06

Tunnel

Sixty-four thousand points are wound in rings around a closed 3D path, twisting as they go, and the camera rides the path looking just ahead. A rainbow cycles along the tube and linear fog swallows the far end. A dependency-free WebGL1 port of a three.js scene.

Adapted from Louis Hoebregts (CodePen) · MIT

3D pointsfly-throughfog
Live

Installation

Add it to your project

$
pnpm dlx shadcn@latest add https://funshader.com/r/tunnel.json

Installs 3 files into components/shaders. The tunnel brings its own renderer, so it needs nothing else.

Usage

Mount it behind your content

app/hero.tsx
import { TunnelShader } from "@/components/shaders/tunnel/tunnel-shader";

export function Hero() {
  return (
    <section className="relative isolate min-h-svh overflow-hidden">
      <TunnelShader className="-z-10" />
      {/* your content */}
    </section>
  );
}

The shader fills its nearest positioned ancestor. Give the parent relative isolate and the shader -z-10 to put it behind everything else.

API reference

Props

PropTypeDefaultDescription
speednumber1Flight speed. 1 is the original pace, about 33 s per lap.
radiusnumber4Tube radius in world units.
pointSizenumber0.2Point size in world units; points shrink with distance.
twistnumber5Half-turns the spiral makes around the tube per lap.
hueCyclesnumber4Times the rainbow repeats along the tube.
hueOffsetnumber0Hue offset in degrees.
saturationnumber1HSL saturation, 0–1.
lightnessnumber0.5HSL lightness, 0–1.
fogNearnumber30Distance where fog starts.
fogFarnumber150Distance where fog is total. Also the camera's far plane.
backgroundstring"#000000"Clear and fog colour.
heightnumber100Maximum random height of each path control point.
seednumber7Seed for the path heights.
ringsnumber1600Rings along the tube. Rebuilds the geometry.
pointsPerRingnumber40Points per ring. Rebuilds the geometry.
pausedbooleanfalseFreezes the current frame.
maxDprnumber2Cap on devicePixelRatio.
respectReducedMotionbooleantrueDraws a still frame for prefers-reduced-motion.
classNamestring—Classes for the absolutely-positioned wrapper.

Keep exploring

More shaders