HexFloat (Vanilla, WebGPU)

HexFloat (Vanilla, WebGPU) renders a page's live HTML onto a floor of shiny, beveled hexagonal tiles that tilt back in perspective, bob, and rise toward the cursor. It is a framework-free TypeScript module built on vgpu, and the HTML content stays interactive.

component · no preview
This item cannot be built as published, so there is no live preview: install:
See how it was built

Installation

pnpm dlx shadcn@latest add @canvas-ui/hex-float-vanilla-webgpu

Requires @canvas-ui in the registries of your components.json (shadcn adds official directory namespaces automatically).

Usage

usage.tsx
import { useEffect, useRef } from 'react';import { createHexFloat, supportsWebGPU } from '@/components/canvasui/HexFloatWebGPU';export function HexFloatHero() {  const sourceRef = useRef<HTMLCanvasElement>(null);  const contentRef = useRef<HTMLDivElement>(null);  const outputRef = useRef<HTMLCanvasElement>(null);  useEffect(() => {    const source = sourceRef.current;    const content = contentRef.current;    const output = outputRef.current;    if (!source || !content || !output || !supportsWebGPU()) return;    const instance = createHexFloat({ source, content, output }, { size: 160, tilt: 24 });    return () => instance?.destroy();  }, []);  return (    <div style={{ position: 'relative' }}>      <canvas ref={outputRef} aria-hidden='true' style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }} />      <canvas ref={sourceRef} style={{ display: 'block' }}>        <div ref={contentRef}>Your page content</div>      </canvas>    </div>  );}
  • Use it as a hero or landing-page backdrop where the real page content should look like it floats on a dimensional tiled surface.
  • Use it for a showcase CTA area or a premium-feeling section that needs shiny, reactive lighting without extra dependencies.
  • Use it when you want the rendered page to remain selectable, clickable, and hoverable, with pointer input forwarded to the underlying DOM.
  • Avoid it where a static, low-power, or non-WebGPU-only experience is required, since it needs WebGPU and degrades to plain content otherwise.

Examples

Hero backdrop with default tuning

Mounts the effect on a hero section with default options. The content div is the captured subtree, and the output canvas sits behind it as a layer.

hero-backdrop-with-default-tuning.tsx
import { useEffect, useRef } from 'react';import { createHexFloat, supportsWebGPU } from '@/components/canvasui/HexFloatWebGPU';export function Hero() {  const sourceRef = useRef<HTMLCanvasElement>(null);  const contentRef = useRef<HTMLDivElement>(null);  const outputRef = useRef<HTMLCanvasElement>(null);  useEffect(() => {    const source = sourceRef.current;    const content = contentRef.current;    const output = outputRef.current;    if (!source || !content || !output || !supportsWebGPU()) return;    const instance = createHexFloat({ source, content, output });    return () => instance?.destroy();  }, []);  return (    <section style={{ position: 'relative', minHeight: 480 }}>      <canvas ref={outputRef} aria-hidden='true' style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }} />      <canvas ref={sourceRef} style={{ display: 'block' }}>        <div ref={contentRef} style={{ padding: 48 }}>          <h1>Ship faster</h1>          <a href='/signup'>Get started</a>        </div>      </canvas>    </section>  );}

Live tuning with setOptions

Keeps the instance in a ref and pushes option changes at runtime, for example from a debug panel. setOptions only restarts the loop when a value actually changes.

live-tuning-with-setoptions.tsx
import { useEffect, useRef, useState } from 'react';import { createHexFloat, supportsWebGPU, type HexFloatInstance } from '@/components/canvasui/HexFloatWebGPU';export function TunableHexFloat() {  const sourceRef = useRef<HTMLCanvasElement>(null);  const contentRef = useRef<HTMLDivElement>(null);  const outputRef = useRef<HTMLCanvasElement>(null);  const instanceRef = useRef<HexFloatInstance | null>(null);  const [bloom, setBloom] = useState(0.3);  useEffect(() => {    const source = sourceRef.current;    const content = contentRef.current;    const output = outputRef.current;    if (!source || !content || !output || !supportsWebGPU()) return;    instanceRef.current = createHexFloat({ source, content, output }, { bloom: 0.3, grain: 0.4 });    return () => {      instanceRef.current?.destroy();      instanceRef.current = null;    };  }, []);  useEffect(() => {    instanceRef.current?.setOptions({ bloom });  }, [bloom]);  return (    <div style={{ position: 'relative' }}>      <input type='range' min={0} max={1} step={0.05} value={bloom} onChange={(e) => setBloom(Number(e.target.value))} aria-label='Bloom' />      <canvas ref={outputRef} aria-hidden='true' style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }} />      <canvas ref={sourceRef} style={{ display: 'block' }}>        <div ref={contentRef}>Adjust the glow above</div>      </canvas>    </div>  );}

Re-measuring after a layout change

Calls resize() when the container changes size in a way the built-in observers may not catch, such as after a tab switch that changes layout width.

re-measuring-after-a-layout-change.tsx
import { useEffect, useRef } from 'react';import { createHexFloat, supportsWebGPU, type HexFloatInstance } from '@/components/canvasui/HexFloatWebGPU';export function TabPanelHexFloat({ activeTab }: { activeTab: string }) {  const sourceRef = useRef<HTMLCanvasElement>(null);  const contentRef = useRef<HTMLDivElement>(null);  const outputRef = useRef<HTMLCanvasElement>(null);  const instanceRef = useRef<HexFloatInstance | null>(null);  useEffect(() => {    const source = sourceRef.current;    const content = contentRef.current;    const output = outputRef.current;    if (!source || !content || !output || !supportsWebGPU()) return;    instanceRef.current = createHexFloat({ source, content, output }, { size: 140, tilt: 18 });    return () => {      instanceRef.current?.destroy();      instanceRef.current = null;    };  }, []);  useEffect(() => {    instanceRef.current?.resize();  }, [activeTab]);  return (    <div style={{ position: 'relative' }}>      <canvas ref={outputRef} aria-hidden='true' style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }} />      <canvas ref={sourceRef} style={{ display: 'block' }}>        <div ref={contentRef}>Active tab: {activeTab}</div>      </canvas>    </div>  );}

API reference

PropTypeDefaultDescription
sizenumber160Width of each hex tile in CSS pixels.
gapnumber0Seam between tiles in CSS pixels.
bevelnumber1.5Width of the shiny beveled rim in CSS pixels.
tiltnumber24Backward lean of the page in degrees, clamped to -30 to 30. Positive tilts the top away.
perspectivenumber0.5Camera closeness from 0 to 1. Higher exaggerates the perspective of the tilt.
floatnumber0How far tiles bob up and down (0 to 1). 0 keeps them still.
speednumber1Speed of the floating motion. 1 is normal speed.
shinenumber0.5Intensity of specular glints on rims and tile faces (0 to 2).
liftnumber0.1How strongly tiles rise along the edges of the fluid reading window (0 to 1).
radiusnumber1200Size of the fluid splats the cursor injects, in CSS pixels. Sets the reading window's scale.
flownumber0How strongly cursor movement pushes the fluid around (0 to 3).
swirlnumber0Vorticity of the fluid (0 to 15). Higher makes the trail curl into eddies.
trailnumber0How long the fluid trail lingers before healing (0 to 1).
iridescencenumber1Strength of the iridescent hue shift on highlights (0 to 2). 0 keeps highlights neutral.
bloomnumber0Bloom glow around bright highlights (0 to 1). 0 skips the pass entirely.
grainnumber0.8Animated film grain over the final image (0 to 1). 0 skips the pass entirely.
gapColor[number, number, number] | "auto""auto"Seam color as [r, g, b] in the 0-1 range, or "auto" to derive a dark seam from the page background.

Accessibility

  • The effect is purely visual; the real HTML content is captured from the DOM, so text, links, and buttons keep their semantics and remain focusable.
  • Mark the output canvas as aria-hidden='true' so assistive technology reads only the page content.
  • Respects prefers-reduced-motion: the loop stops animating, pointer-driven fluid and hover-driven motion are disabled, and static content is still shown.
  • Pointer clicks, hover cursors, and text selection are remapped from the tilted surface to the captured DOM, so keyboard focus and click targets still work.
  • If WebGPU or the experimental HTML-in-canvas API is unavailable, createHexFloat returns null or falls back to drawing the content without the effect, so the page stays readable.
  • Keep the content's contrast sufficient, since tile shading, grain, and bloom can reduce the apparent contrast of text.
  • Pause is automatic when the canvas leaves the viewport, which reduces background CPU and GPU work.

Docs written by anthropic:claude-haiku-5-5 from the registry source.

Use with Coding Agent

Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.

prompt.md
Use the "HexFloat (Vanilla, WebGPU)" component (canvas-ui/hex-float-vanilla-webgpu) from its shadcn registry.1. Install it with: npx shadcn@latest add @canvas-ui/hex-float-vanilla-webgpu2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.4. Available props: size, gap, bevel, tilt, perspective, float, speed, shine, lift, radius, flow, swirl, trail, iridescence, bloom, grain, gapColor.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { useEffect, useRef } from 'react';import { createHexFloat, supportsWebGPU } from '@/components/canvasui/HexFloatWebGPU';export function HexFloatHero() {  const sourceRef = useRef<HTMLCanvasElement>(null);  const contentRef = useRef<HTMLDivElement>(null);  const outputRef = useRef<HTMLCanvasElement>(null);  useEffect(() => {    const source = sourceRef.current;    const content = contentRef.current;    const output = outputRef.current;    if (!source || !content || !output || !supportsWebGPU()) return;    const instance = createHexFloat({ source, content, output }, { size: 160, tilt: 24 });    return () => instance?.destroy();  }, []);  return (    <div style={{ position: 'relative' }}>      <canvas ref={outputRef} aria-hidden='true' style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }} />      <canvas ref={sourceRef} style={{ display: 'block' }}>        <div ref={contentRef}>Your page content</div>      </canvas>    </div>  );}```

Files & dependencies

  • components/canvasui/HexFloatWebGPU.ts→ components/canvasui/HexFloatWebGPU.ts
dependenciesvgpu@^0.3.1
devDependencies@webgpu/types

Looks similar, elsewhere

There is no screenshot of this item to compare yet.