IrisBackgroundsMotorway
Motorway
Night Road widened into a full six-lane highway — symmetric white-gold-to-amber lanes with five dashed dividers, converging on one real vanishing point.
Motorway
A variation on `night-road` that trades its four-or-so streaks for a genuine wide highway: six full lanes of light trail ride the same kind of real perspective projection toward a vanishing point inside the frame, five dashed dividers running between them rather than one. The colour widens with the road — cool white-gold in the two centre lanes, warming outward to full amber at the outer pair — the way a broad sodium-lit carriageway reads wider than it is deep, rather than one narrow bundle.
The pointer keeps `night-road`'s contract exactly: x steers the vanishing point, y throttles every lane's flicker and dash travel the nearer it sits to the bottom edge, and the cursor drops the same warm headlight bloom.
Install
No installation needed — self-contained, paste-in code.
Usage
Drop it straight into a page.
import { MotorwayField } from "./MotorwayField";
export default function Example() {
return (
// Fills its nearest positioned ancestor (it renders itself `absolute
// inset-0`) — give it a sized, relatively positioned box.
<div className="relative isolate h-[32rem] w-full overflow-hidden rounded-2xl">
<MotorwayField />
</div>
);
}Component
The real source, exactly as it ships — multiple files, kept together.
"use client";
import { useEffect, useRef } from "react";
import { mountShaderSurface } from "@/lib/shader-surface";
/**
* A live WebGL variation on `RoadField`'s night-road family that trades the
* family's usual four-or-so streaks for a genuine wide highway: six full
* lanes of light trail, symmetric across the bundle, converging on the same
* kind of real perspective projection toward a vanishing point inside the
* frame. Five dashed dividers ride between the six lanes rather than
* `RoadField`'s single one, and the colour itself widens with the road — cool
* white-gold in the two centre lanes, warming to full amber at the outer
* edges, the way a broad sodium-lit carriageway actually reads wider than it
* is deep.
*
* The lane count is a fixed loop of six rather than a prop: this is one
* specific, wider piece in the family (`night-road` is the narrow one,
* `rainline` the wet one, this the six-lane one), not a parametric "road
* generator" — same reasoning `RoadField` and `ContraflowField` already
* apply to their own fixed lane counts.
*
* Pointer contract carried over from `RoadField` unchanged — steering and
* throttle, not a new gesture:
* - steering — the pointer's x pans the vanishing point.
* - throttle — the pointer's y speeds every lane's flicker and dash travel
* the nearer it sits to the bottom edge.
* The same warm headlight bloom rides the cursor.
*
* One of the reusable background fields, a sibling of `RoadField`,
* `ContraflowField` and `RainlineField` in the same trail family. Drop it
* into any `position: relative`/`isolate` parent — it fills the box. Built
* on `lib/shader-surface.ts`, so every degradation path is already handled:
* no WebGL, a blocked or lost context, a hidden tab, or
* `prefers-reduced-motion` all leave the CSS `.iris-motorwayfield__floor`
* underneath visible (a still composed frame in the same palette, never a
* blank box).
*
* Fixed palette, not the token ramp — same reasoning as `RoadField`: the
* near-white flare core and the cool/warm widening live nowhere in the
* accent ramp, so the CSS floor carries the colour rather than a live token
* read.
*
* Reading guard: when `guardSelector` resolves to an element, the field
* measures that block every frame and clamps its own luminance under a
* ceiling inside that region (hue and saturation untouched), so copy laid
* over the field holds WCAG AA with no overlay layer. `null` (the default)
* turns the guard off — for decorative use where nothing sits on top.
*/
/* Palette, sRGB 0–1. Uniforms, not tokens — see the note above. */
const PALETTE: Record<string, [number, number, number]> = {
u_black: [0.013, 0.013, 0.015], // the near-black asphalt between the lanes
u_haze: [0.22, 0.12, 0.06], // the warm haze pooling under the bundle near the camera
u_white: [0.92, 0.88, 0.78], // the cool white-gold of the two centre lanes
u_gold: [0.98, 0.72, 0.32], // the mid-bundle colour
u_amber: [0.99, 0.46, 0.14], // the hotter outer-lane colour
u_flare: [1.0, 0.97, 0.9], // the near-white core riding every lane
u_line: [0.83, 0.8, 0.72], // the dashed lane dividers
};
const FRAG = `
uniform vec2 u_res;
uniform float u_time;
uniform float u_scale;
uniform vec3 u_pointer; /* x, y (0 bottom .. 1 top), presence 0..1 */
uniform vec3 u_black;
uniform vec3 u_haze;
uniform vec3 u_white;
uniform vec3 u_gold;
uniform vec3 u_amber;
uniform vec3 u_flare;
uniform vec3 u_line;
/* Reading region for the contrast guard: xy = centre (uv, y up),
zw = half-extent. Measured from the live copy block every frame.
u_guard is 0 when the guard is off. */
uniform vec4 u_readA;
uniform float u_guard;
const float HORIZON = 0.72; /* uv.y of the vanishing point */
const float VP_X = 0.0; /* the point's x offset from centre, P-space */
const float ROAD_W = 0.86; /* road half-width at the camera — wider than RoadField's, six lanes */
const float MIN_BW = 0.004; /* width floor so the bundle never divides by zero */
float trail(float dx, float sigma, float wz, float seed, float spd, out float core) {
float s2 = sigma * sigma + 1e-7;
float body = exp(-dx * dx / s2);
core = exp(-dx * dx / (s2 * 0.085));
float flicker = 0.77 + 0.23 * sin(wz * 0.5 - u_time * spd + seed * 6.4);
return body * flicker;
}
void main() {
vec2 res = u_res / u_scale;
vec2 uv = gl_FragCoord.xy / u_scale / res; /* 0..1, y up */
float aspect = res.x / res.y;
vec2 P = (uv - 0.5) * vec2(aspect, 1.0);
/* steering: the pointer's x pans the vanishing point. throttle: the
pointer's y doubles as an accelerator — nearer the bottom edge (closer
to the camera) reads as pressing it down. Same contract as RoadField. */
float steer = (u_pointer.x - 0.5) * u_pointer.z * 0.5;
float speed = 1.0 + u_pointer.z * (1.0 - u_pointer.y) * 2.4;
float vpX = VP_X + steer;
float d = uv.y / HORIZON;
float invZ = pow(clamp(1.0 - d, 0.0, 1.0), 1.35);
float aboveHorizon = 1.0 - smoothstep(0.9, 1.02, d);
float wz = (1.0 - invZ) / max(invZ, 0.02);
float roadCenterX = vpX * (1.0 - invZ);
float bw = max(ROAD_W * invZ, MIN_BW);
vec3 col = u_black;
/* a warm haze pooling under the whole bundle near the camera — nothing
here is pure black, the discipline the rest of the family keeps */
float haze = smoothstep(0.55, 0.0, d) * exp(-abs(P.x - roadCenterX) * 0.7);
col += u_haze * haze * 0.12;
/* six lanes, symmetric across the bundle's half-width — offsets of
-2.5..2.5 in steps of 1, scaled to the bundle so they converge to the
same point together. Colour widens outward: white-gold at the two
centre lanes, full amber by the outer pair. */
float coreSum = 0.0;
for (int i = 0; i < 6; i++) {
float k = (float(i) - 2.5) / 3.0; /* -0.833 .. 0.833 */
float laneX = roadCenterX + k * bw;
float seed = float(i) * 1.9 + 1.1;
float spd = (0.82 + 0.05 * float(i)) * speed;
float core;
float e = trail(P.x - laneX, bw * 0.075, wz, seed, spd, core);
float t = abs(k) / 0.833; /* 0 centre .. 1 edge */
vec3 laneColor = mix(u_white, mix(u_gold, u_amber, smoothstep(0.4, 1.0, t)), smoothstep(0.0, 0.55, t));
col += laneColor * e * 1.55 * aboveHorizon;
coreSum += core;
}
col += u_flare * coreSum * aboveHorizon * 0.6;
/* five dashed dividers riding between the six lanes, spaced and animated
in world depth so they compress toward the horizon exactly the way the
lanes converge */
for (int j = 0; j < 5; j++) {
float k = (float(j) - 2.0) / 3.0; /* -0.667 .. 0.667 */
float lineX = roadCenterX + k * bw;
float dashSigma = bw * 0.018 + 0.001;
float dxD = P.x - lineX;
float lineBody = exp(-dxD * dxD / (dashSigma * dashSigma + 1e-7));
float dp = fract(wz * 0.55 - u_time * 0.9 * speed + float(j) * 0.2);
float dashOn = clamp(smoothstep(0.0, 0.05, dp) - smoothstep(0.55, 0.6, dp), 0.0, 1.0);
col += u_line * lineBody * dashOn * aboveHorizon * 0.9;
}
/* the touch: a warm headlight bloom with a near-white core, the same
"your touch joined the light" move RoadField makes */
vec2 ptr = (u_pointer.xy - 0.5) * vec2(aspect, 1.0);
vec2 toPtr = P - ptr;
float dPtr = dot(toPtr, toPtr);
col += u_amber * u_pointer.z * exp(-dPtr * 9.0) * 0.5;
col += u_flare * u_pointer.z * exp(-dPtr * 40.0) * 0.4;
col = max(col, 0.0);
/* ---- the reading guard (see TileField for the full rationale) ---- */
vec2 rd = abs(uv - u_readA.xy) / max(u_readA.zw, vec2(0.02));
float m = mix(max(rd.x, rd.y), length(rd), 0.4);
float band = 1.0 - smoothstep(0.72, 2.1, m);
col = mix(col, holdUnder(col, 0.09), band * u_guard);
col += (bayer8(gl_FragCoord.xy) - 0.5) * (2.2 / 255.0);
gl_FragColor = vec4(col, 1.0);
}
`;
export interface MotorwayFieldProps {
className?: string;
/**
* CSS selector for the block the reading guard should keep readable,
* resolved against `document`. `null` (the default) turns the guard off.
*/
guardSelector?: string | null;
}
export function MotorwayField({ className, guardSelector = null }: MotorwayFieldProps) {
const canvasRef = useRef<HTMLCanvasElement>(null);
useEffect(() => {
const canvas = canvasRef.current;
if (!canvas) return;
const guardOn = guardSelector != null;
/* The block the reading guard protects. Looked up once, lazily. */
let guardEl: Element | null | undefined;
const readGuardEl = () => {
if (guardEl === undefined) {
guardEl = guardOn
? document.querySelector(guardSelector as string)
: null;
}
return guardEl;
};
return mountShaderSurface(canvas, {
fragment: FRAG,
uniforms: [...Object.keys(PALETTE), "u_readA", "u_guard"],
onInit: (gl, u) => {
for (const name of Object.keys(PALETTE)) {
if (u[name]) gl.uniform3fv(u[name], PALETTE[name]);
}
if (u.u_readA) gl.uniform4f(u.u_readA, 0.5, 0.5, 0.44, 0.32);
if (u.u_guard) gl.uniform1f(u.u_guard, guardOn ? 1 : 0);
},
onFrame: (gl, u, s) => {
if (!guardOn || !u.u_readA) return;
let cx = 0.5, cy = 0.5, hw = 0.44, hh = 0.32;
const el = readGuardEl();
const { rect } = s;
if (el && rect.width > 0 && rect.height > 0) {
const r = el.getBoundingClientRect();
const padX = rect.width * 0.09;
const padY = rect.height * 0.11;
cx = (r.left + r.width / 2 - rect.left) / rect.width;
cy = 1 - (r.top + r.height / 2 - rect.top) / rect.height;
hw = (r.width / 2 + padX) / rect.width;
hh = (r.height / 2 + padY) / rect.height;
}
gl.uniform4f(u.u_readA, cx, cy, hw, hh);
},
onPainted: () => canvas.setAttribute("data-shader", "on"),
/* No onIdle — same contract as RoadField / RainlineField: once
painted, the last frame stays on screen while the surface is parked
off-view, so scrolling away and back does not crossfade to the
static floor. A lost context still clears it below. */
onLost: () => canvas.removeAttribute("data-shader"),
maxPixels: 2_200_000,
dprCap: 1.5,
});
}, [guardSelector]);
return (
<div
className={`absolute inset-0 overflow-hidden${className ? ` ${className}` : ""}`}
aria-hidden="true"
>
<div className="absolute inset-0 [background:radial-gradient(_46%_50%_at_50%_72%,oklch(0.94_0.03_85)_0%,transparent_12%_),radial-gradient(_58%_68%_at_50%_72%,oklch(0.85_0.09_75)_0%,transparent_32%_),radial-gradient(_80%_92%_at_50%_72%,oklch(0.62_0.16_55)_0%,transparent_58%_),radial-gradient(_105%_105%_at_50%_72%,oklch(0.18_0.05_40)_0%,transparent_78%_),oklch(0.032_0.008_60)] after:content-[''] after:absolute after:inset-0 after:[background:repeating-linear-gradient(_90deg,transparent_0_3.2%,oklch(0.1_0.02_60_/_0.55)_3.2%_4.6%_)] after:[-webkit-mask-image:radial-gradient(_72%_90%_at_50%_72%,transparent_0_10%,#000_40%,transparent_80%_)] after:[mask-image:radial-gradient(_72%_90%_at_50%_72%,transparent_0_10%,#000_40%,transparent_80%_)]" />
<canvas ref={canvasRef} className="absolute inset-0 w-full h-full opacity-0 transition-opacity duration-[--duration-slow] ease-[--ease-standard] data-[shader=on]:opacity-100" />
</div>
);
}Custom work
Need one that isn't in the catalogue?
Describe what you're after and I'll reply by email — no promise on turnaround yet, this is a new channel, not a service with a set price or queue.
Fardin Omor Afnan
Reads and answers every request himself