Adventureland Registry

WebGL Background

An interactive WebGL2 background that fills its parent container with pixelated shapes and click-triggered ripple animations.

WebGLBackground renders a Three.js WebGL2 canvas that sizes itself to its nearest relative ancestor via absolute inset-0. A fullscreen quad is shaded by a custom GLSL fragment shader supporting four pixel shapes (square, circle, triangle, diamond), a configurable ink colour, interactive click-ripple effects, and mouse-tracking. When interactive is false the canvas ignores pointer events entirely.

SSR note: This component is "use client" and requires a WebGL2 context. Import it with next/dynamic and { ssr: false } when used in server or static contexts. It silently bails out when WebGL2 is unavailable.

Installation

npx shadcn@latest add @adv/webgl-background

Usage

import dynamic from 'next/dynamic';

const WebGLBackground = dynamic(
  () => import('@/components/WebGLBackground').then((m) => m.WebGLBackground),
  { ssr: false },
);

// Wrap in a relative container — the canvas fills it completely
<div className="relative h-screen w-full bg-black">
  <WebGLBackground shape="circle" ink="#ffffff" pixelSize={4} interactive />
  <div className="relative z-10">Your page content</div>
</div>

Example

Click to create ripples

Props

PropTypeDefaultDescription
shape"square" | "circle" | "triangle" | "diamond""square"Shape drawn at each pixel grid cell.
pixelSizenumber4Size of each pixel cell in logical pixels. Larger values = coarser grain.
inkstring"#FFFFFF"CSS colour string for the shape fill.
interactivebooleantrueWhen true, click events create ripple animations; the canvas receives pointer events.
shapeScalenumber1.0Uniform scale factor applied to the rendered shape within each cell.
classNamestringundefinedAdditional CSS classes merged with absolute inset-0 on the host div.

On this page