Interstellar space
The slowly turning galaxy behind Starlight's sign-in, sign-up and checkout: one WebGL shader of twinkling, flaring stars drifting through depth.
Build a React 19 + TypeScript component called InterstellarSpace: a slowly turning, drifting galaxy of twinkling stars drawn by one WebGL fragment shader. Constraints - One .tsx file, "use client", imports from react only, plain WebGL (webgl2, falling back to webgl), no libraries. CSS in a template string rendered as <style href="ui-interstellar-space" precedence="ui">, classes prefixed "gx-". - The root fills its parent (position relative, width/height 100%, overflow hidden, isolation isolate) and paints a background prop, default #0a0812. Create the canvas inside the effect and append it (a fresh one per mount, since cleanup loses its context). Size it with a ResizeObserver to the root's offsetWidth × offsetHeight at one pixel per CSS pixel, no devicePixelRatio. - Context: alpha true, premultipliedAlpha false, depth false, antialias false. Blending off: the shader's colour and alpha are written straight and the page composites them over the background. Clear to transparent (opaque black when transparent is false). Props and defaults - focal [0.5, 0.5], rotation [1, 0] (cos, sin), starSpeed 0.5, density 0.6, hueShift 220, speed 0.5, autoDrift 1, glowIntensity 0.15, saturation 0.3, twinkleIntensity 0.4, rotationSpeed 0.05, repulsionStrength 2, autoCenterRepulsion 0, transparent true, disableAnimation false, pointer "off" | "drift" | "repel" (default "off"). Props must apply after mount without rebuilding the context: keep them in a ref read every frame. Geometry - One triangle covering the screen: positions (−1,−1), (3,−1), (−1,3), uv (0,0), (2,0), (0,2). Shader - uv = (vUv × resolution − focal × resolution) / resolution.y. - Pointer: with autoCenterRepulsion > 0, uv += normalize(uv) × autoCenterRepulsion / (|uv| + 0.1) × 0.05. Else "repel": the same away from the pointer, using repulsionStrength and × the pointer's active factor. Else uv += (mouse − 0.5) × 0.1 × active factor. - Rotate uv by time × rotationSpeed, then by the rotation prop. Drift: uv.x += (sin(t·0.07)·0.3 + sin(t·0.13)·0.15 + sin(t·0.031)·0.1) × autoDrift, uv.y += (cos(t·0.09)·0.25 + cos(t·0.17)·0.12 + sin(t·0.023)·0.1) × autoDrift. - Four layers, i = 0, 0.25, 0.5, 0.75: depth = fract(i + layerTime), scale = mix(20 × density, 0.5 × density, depth), fade = depth × smoothstep(1, 0.9, depth); add StarLayer(uv × scale + i × 453.32) × fade. - StarLayer: for the cell and its 8 neighbours, seed = Hash21(cell) (p = fract(p × (123.34, 456.21)); p += dot(p, p + 45.32); fract(p.x × p.y)). size = fract(seed × 345.32). Flare = smoothstep(0.9, 1, size) × tri(starTime / (3 × seed + 1)), tri(x) = |fract(x) × 2 − 1|. - Colour: red = smoothstep(0.2, 1, Hash21(cell + 1)) + 0.2, blue the same with + 3, green = min(red, blue) × seed. Convert to hue = atan(g − r, b − r) / 2π + 0.5, add hueShift / 360; saturation = distance from its luma (0.299, 0.587, 0.114) × the saturation prop; value = max channel; back through hsv2rgb. - Wobble: offset the star by (tris(seed × 34 + speedTime / 10), tris(seed × 38 + speedTime / 30)) − 0.5, tris(x) = 1 − smoothstep(0, 1, |2 fract(x) − 1|). - Star(p, flare): d = |p|; m = 0.05 × glow / d; plus smoothstep(0, 1, 1 − |p.x × p.y × 1000|) × flare × glow; rotate p by 45° and add the same rays × 0.3; × smoothstep(1, 0.2, d). - Twinkle: trisn(speedTime + seed × 2π) × 0.5 + 1 (trisn = 2 tris − 1), mixed from 1 by twinkleIntensity. Add star × twinkle × size × colour. - Transparent: alpha = min(smoothstep(0, 0.3, length(col)), 1), output (col, alpha). Otherwise (col, 1). Clock - Integrate per frame (dt capped at 0.1 s): time += dt, starTime += dt × starSpeed / 10, speedTime += dt × speed, layerTime += dt × starSpeed / 10 × speed. Integrating rather than multiplying keeps the field from jumping when speed changes. disableAnimation freezes all four. - Pointer position is 0–1 across the root with y up, from pointermove; pointerleave and pointercancel drop the target active factor to 0, as does pointer "off". Ease position and factor toward their targets by 0.05 per 60fps frame (1 − 0.95^(dt × 60)). Be a good guest - Pause with an IntersectionObserver off screen and on visibilitychange. prefers-reduced-motion: draw one still frame, and redraw it when props change. Canvas aria-hidden. On unmount stop the loop, remove listeners, delete the buffers, shaders and program, lose the context and remove the canvas.
"use client";
/**
* InterstellarSpace — the drifting galaxy behind Starlight's sign-in.
*
* From Starlight (joinstarlight.com), where it fills the screen behind sign-in, sign-up, onboarding, checkout
* and the welcome page, every one with the settings used as the defaults here. Starlight's copy is React Bits'
* Galaxy (reactbits.dev, MIT) with an `autoDrift` added; this file ports it from the ogl library to plain
* WebGL so it needs nothing but React.
*
* How it works
* - One fragment shader on a full-screen triangle. Space is cut into a grid; each cell holds one star at a
* hashed size, colour and wobble, drawn as a 1/d glow plus four diffraction rays (and four fainter ones at
* 45°) on the biggest. Four layers at different scales slide through depth and cross-fade, which reads as
* flying slowly forward.
* - Colours come from the hash, then are rotated by `hueShift` and scaled by `saturation`. Starlight's 220° and
* 0.3 give the faint blue, rose and gold that sit on its #0a0812 sky.
* - The whole field turns slowly (`rotationSpeed`) and pans on a sum of slow sines (`autoDrift`), so it never
* visibly loops. Stars twinkle on a triangle wave and the biggest flare up now and then.
* - With `transparent` (the default, as on the site) the canvas is see-through where there are no stars and the
* root's `background` shows through. Alpha is stored straight, not premultiplied, as ogl did.
* - The canvas renders at one pixel per CSS pixel, as on the site, even on retina screens. It keeps the glow
* soft and the shader cheap.
* - `pointer` adds the original's mouse modes: "drift" leans the field toward the pointer, "repel" pushes
* stars away from it. Starlight runs it with neither ("off").
* - Speed and star-speed changes are integrated over time rather than multiplied by the clock. At a steady
* speed it's the same picture, but a slider no longer makes the field jump.
* - The loop pauses off screen and in hidden tabs. With reduced motion it draws one still frame.
*
* Usage
* <div style={{ height: 520 }}>
* <InterstellarSpace />
* </div>
* <InterstellarSpace hueShift={140} density={1} glowIntensity={0.3} pointer="repel" />
*
* Requirements: React 19 (for the hoisted <style>) and a browser with WebGL. No other dependencies. Without
* WebGL it shows the plain background.
*/
import { useEffect, useRef } from "react";
type Pointer = "off" | "drift" | "repel";
type InterstellarSpaceProps = {
/** Where the centre of the field sits, as a fraction of the frame (x, y from the bottom left). */
focal?: [number, number];
/** A fixed rotation of the field, as [cos, sin]. */
rotation?: [number, number];
/** How fast the layers fly through depth, and how often the big stars flare. */
starSpeed?: number;
/** Stars per area. Higher is more, smaller stars. */
density?: number;
/** Rotates every star's hue, in degrees. */
hueShift?: number;
/** Freezes the clock (the pointer still works). */
disableAnimation?: boolean;
/** Scales twinkle, wobble and flight through depth. */
speed?: number;
/** "drift" leans toward the pointer, "repel" pushes stars away from it, "off" ignores it. */
pointer?: Pointer;
/** How far the field wanders on its own. 0 holds it still. */
autoDrift?: number;
/** Glow and ray strength. */
glowIntensity?: number;
/** 0 is white stars, 1 full colour. */
saturation?: number;
/** How deep the twinkle goes, 0–1. */
twinkleIntensity?: number;
/** How fast the field turns, in radians per second. */
rotationSpeed?: number;
/** How hard "repel" pushes. */
repulsionStrength?: number;
/** Pushes stars out from the centre, as a fixed lens. Overrides `pointer`. */
autoCenterRepulsion?: number;
/** See-through between stars, showing `background`. Otherwise the field is drawn on black. */
transparent?: boolean;
/** The sky behind the stars. */
background?: string;
};
const vertexShader = `
attribute vec2 uv;
attribute vec2 position;
varying vec2 vUv;
void main() {
vUv = uv;
gl_Position = vec4(position, 0, 1);
}
`;
// React Bits' Galaxy shader with Starlight's autoDrift, as on the site. The only change: the clock-times-speed
// products (uTime * uSpeed and uStarSpeed * uSpeed) arrive pre-integrated as uSpeedTime and uLayerTime.
const fragmentShader = `
precision highp float;
uniform float uTime;
uniform vec3 uResolution;
uniform vec2 uFocal;
uniform vec2 uRotation;
uniform float uStarSpeed;
uniform float uDensity;
uniform float uHueShift;
uniform float uSpeedTime;
uniform float uLayerTime;
uniform vec2 uMouse;
uniform float uGlowIntensity;
uniform float uSaturation;
uniform bool uMouseRepulsion;
uniform float uTwinkleIntensity;
uniform float uRotationSpeed;
uniform float uRepulsionStrength;
uniform float uMouseActiveFactor;
uniform float uAutoCenterRepulsion;
uniform bool uTransparent;
uniform float uAutoDrift;
varying vec2 vUv;
#define NUM_LAYER 4.0
#define STAR_COLOR_CUTOFF 0.2
#define MAT45 mat2(0.7071, -0.7071, 0.7071, 0.7071)
#define PERIOD 3.0
float Hash21(vec2 p) {
p = fract(p * vec2(123.34, 456.21));
p += dot(p, p + 45.32);
return fract(p.x * p.y);
}
float tri(float x) {
return abs(fract(x) * 2.0 - 1.0);
}
float tris(float x) {
float t = fract(x);
return 1.0 - smoothstep(0.0, 1.0, abs(2.0 * t - 1.0));
}
float trisn(float x) {
float t = fract(x);
return 2.0 * (1.0 - smoothstep(0.0, 1.0, abs(2.0 * t - 1.0))) - 1.0;
}
vec3 hsv2rgb(vec3 c) {
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
float Star(vec2 uv, float flare) {
float d = length(uv);
float m = (0.05 * uGlowIntensity) / d;
float rays = smoothstep(0.0, 1.0, 1.0 - abs(uv.x * uv.y * 1000.0));
m += rays * flare * uGlowIntensity;
uv *= MAT45;
rays = smoothstep(0.0, 1.0, 1.0 - abs(uv.x * uv.y * 1000.0));
m += rays * 0.3 * flare * uGlowIntensity;
m *= smoothstep(1.0, 0.2, d);
return m;
}
vec3 StarLayer(vec2 uv) {
vec3 col = vec3(0.0);
vec2 gv = fract(uv) - 0.5;
vec2 id = floor(uv);
for (int y = -1; y <= 1; y++) {
for (int x = -1; x <= 1; x++) {
vec2 offset = vec2(float(x), float(y));
vec2 si = id + vec2(float(x), float(y));
float seed = Hash21(si);
float size = fract(seed * 345.32);
float glossLocal = tri(uStarSpeed / (PERIOD * seed + 1.0));
float flareSize = smoothstep(0.9, 1.0, size) * glossLocal;
float red = smoothstep(STAR_COLOR_CUTOFF, 1.0, Hash21(si + 1.0)) + STAR_COLOR_CUTOFF;
float blu = smoothstep(STAR_COLOR_CUTOFF, 1.0, Hash21(si + 3.0)) + STAR_COLOR_CUTOFF;
float grn = min(red, blu) * seed;
vec3 base = vec3(red, grn, blu);
float hue = atan(base.g - base.r, base.b - base.r) / (2.0 * 3.14159) + 0.5;
hue = fract(hue + uHueShift / 360.0);
float sat = length(base - vec3(dot(base, vec3(0.299, 0.587, 0.114)))) * uSaturation;
float val = max(max(base.r, base.g), base.b);
base = hsv2rgb(vec3(hue, sat, val));
vec2 pad = vec2(tris(seed * 34.0 + uSpeedTime / 10.0), tris(seed * 38.0 + uSpeedTime / 30.0)) - 0.5;
float star = Star(gv - offset - pad, flareSize);
vec3 color = base;
float twinkle = trisn(uSpeedTime + seed * 6.2831) * 0.5 + 1.0;
twinkle = mix(1.0, twinkle, uTwinkleIntensity);
star *= twinkle;
col += star * size * color;
}
}
return col;
}
void main() {
vec2 focalPx = uFocal * uResolution.xy;
vec2 uv = (vUv * uResolution.xy - focalPx) / uResolution.y;
vec2 mouseNorm = uMouse - vec2(0.5);
if (uAutoCenterRepulsion > 0.0) {
vec2 centerUV = vec2(0.0, 0.0);
float centerDist = length(uv - centerUV);
vec2 repulsion = normalize(uv - centerUV) * (uAutoCenterRepulsion / (centerDist + 0.1));
uv += repulsion * 0.05;
} else if (uMouseRepulsion) {
vec2 mousePosUV = (uMouse * uResolution.xy - focalPx) / uResolution.y;
float mouseDist = length(uv - mousePosUV);
vec2 repulsion = normalize(uv - mousePosUV) * (uRepulsionStrength / (mouseDist + 0.1));
uv += repulsion * 0.05 * uMouseActiveFactor;
} else {
vec2 mouseOffset = mouseNorm * 0.1 * uMouseActiveFactor;
uv += mouseOffset;
}
float autoRotAngle = uTime * uRotationSpeed;
mat2 autoRot = mat2(cos(autoRotAngle), -sin(autoRotAngle), sin(autoRotAngle), cos(autoRotAngle));
uv = autoRot * uv;
uv = mat2(uRotation.x, -uRotation.y, uRotation.y, uRotation.x) * uv;
if (uAutoDrift > 0.0) {
float t = uTime;
uv.x += (sin(t * 0.07) * 0.3 + sin(t * 0.13) * 0.15 + sin(t * 0.031) * 0.1) * uAutoDrift;
uv.y += (cos(t * 0.09) * 0.25 + cos(t * 0.17) * 0.12 + sin(t * 0.023) * 0.1) * uAutoDrift;
}
vec3 col = vec3(0.0);
for (float i = 0.0; i < 1.0; i += 1.0 / NUM_LAYER) {
float depth = fract(i + uLayerTime);
float scale = mix(20.0 * uDensity, 0.5 * uDensity, depth);
float fade = depth * smoothstep(1.0, 0.9, depth);
col += StarLayer(uv * scale + i * 453.32) * fade;
}
if (uTransparent) {
float alpha = length(col);
alpha = smoothstep(0.0, 0.3, alpha);
alpha = min(alpha, 1.0);
gl_FragColor = vec4(col, alpha);
} else {
gl_FragColor = vec4(col, 1.0);
}
}
`;
const css = `
.gx-root {
position: relative;
width: 100%;
height: 100%;
overflow: hidden;
isolation: isolate;
}
.gx-canvas {
position: absolute;
inset: 0;
display: block;
width: 100%;
height: 100%;
}
`;
/** Per-frame easing of the pointer, as at 60fps. */
const POINTER_EASE = 0.05;
/** The longest step the clock takes in one frame, so a stalled tab doesn't lurch the field. */
const MAX_DT = 0.1;
function compile(gl: WebGLRenderingContext, type: number, source: string) {
const shader = gl.createShader(type);
if (!shader) return null;
gl.shaderSource(shader, source);
gl.compileShader(shader);
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
console.warn("InterstellarSpace:", gl.getShaderInfoLog(shader));
gl.deleteShader(shader);
return null;
}
return shader;
}
export default function InterstellarSpace({
focal = [0.5, 0.5],
rotation = [1.0, 0.0],
starSpeed = 0.5,
density = 0.6,
hueShift = 220,
disableAnimation = false,
speed = 0.5,
pointer = "off",
autoDrift = 1,
glowIntensity = 0.15,
saturation = 0.3,
twinkleIntensity = 0.4,
rotationSpeed = 0.05,
repulsionStrength = 2,
autoCenterRepulsion = 0,
transparent = true,
background = "#0a0812",
}: InterstellarSpaceProps) {
const rootRef = useRef<HTMLDivElement>(null);
// Read by the render loop every frame, so a changed prop shows without rebuilding the GL context.
const props = {
focal,
rotation,
starSpeed,
density,
hueShift,
disableAnimation,
speed,
pointer,
autoDrift,
glowIntensity,
saturation,
twinkleIntensity,
rotationSpeed,
repulsionStrength,
autoCenterRepulsion,
transparent,
};
const propsRef = useRef(props);
propsRef.current = props;
// Redraws once when the loop isn't running (reduced motion, off screen) so a changed prop still shows.
const redrawRef = useRef<() => void>(() => {});
useEffect(() => {
const root = rootRef.current;
if (!root) return;
// A fresh canvas per mount: the cleanup loses its context, and a lost context can't be got back from the
// same element (Strict Mode mounts twice).
const canvas = document.createElement("canvas");
canvas.className = "gx-canvas";
canvas.setAttribute("aria-hidden", "true");
const attrs: WebGLContextAttributes = { alpha: true, premultipliedAlpha: false, depth: false, antialias: false };
const gl = (canvas.getContext("webgl2", attrs) ?? canvas.getContext("webgl", attrs)) as WebGLRenderingContext | null;
if (!gl) return;
const vs = compile(gl, gl.VERTEX_SHADER, vertexShader);
const fs = compile(gl, gl.FRAGMENT_SHADER, fragmentShader);
const program = gl.createProgram();
if (!vs || !fs || !program) return;
gl.attachShader(program, vs);
gl.attachShader(program, fs);
gl.linkProgram(program);
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
console.warn("InterstellarSpace:", gl.getProgramInfoLog(program));
return;
}
gl.useProgram(program);
root.appendChild(canvas);
// One triangle that covers the screen, uv 0–1 across the visible part.
const attribute = (name: string, data: number[]) => {
const buffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(data), gl.STATIC_DRAW);
const loc = gl.getAttribLocation(program, name);
gl.enableVertexAttribArray(loc);
gl.vertexAttribPointer(loc, 2, gl.FLOAT, false, 0, 0);
return buffer;
};
const buffers = [attribute("position", [-1, -1, 3, -1, -1, 3]), attribute("uv", [0, 0, 2, 0, 0, 2])];
const names = [
"uTime", "uResolution", "uFocal", "uRotation", "uStarSpeed", "uDensity", "uHueShift", "uSpeedTime",
"uLayerTime", "uMouse", "uGlowIntensity", "uSaturation", "uMouseRepulsion", "uTwinkleIntensity",
"uRotationSpeed", "uRepulsionStrength", "uMouseActiveFactor", "uAutoCenterRepulsion", "uTransparent", "uAutoDrift",
] as const;
const u = Object.fromEntries(names.map((n) => [n, gl.getUniformLocation(program, n)])) as Record<
(typeof names)[number],
WebGLUniformLocation | null
>;
// Straight writes, no blending: the canvas keeps the shader's colour and alpha as they are, and the page
// composites them over the root's background (ogl disabled blending for this program too).
gl.disable(gl.BLEND);
// The clock and its integrals. At steady settings: time = t, starTime = t * starSpeed / 10,
// speedTime = t * speed, layerTime = starTime * speed, as the original computed them.
const clock = { time: 0, starTime: 0, speedTime: 0, layerTime: 0 };
const mouse = { x: 0.5, y: 0.5, tx: 0.5, ty: 0.5, active: 0, targetActive: 0 };
const draw = () => {
const p = propsRef.current;
gl.viewport(0, 0, canvas.width, canvas.height);
gl.uniform1f(u.uTime, clock.time);
gl.uniform3f(u.uResolution, canvas.width, canvas.height, canvas.width / Math.max(1, canvas.height));
gl.uniform2f(u.uFocal, p.focal[0], p.focal[1]);
gl.uniform2f(u.uRotation, p.rotation[0], p.rotation[1]);
gl.uniform1f(u.uStarSpeed, clock.starTime);
gl.uniform1f(u.uDensity, p.density);
gl.uniform1f(u.uHueShift, p.hueShift);
gl.uniform1f(u.uSpeedTime, clock.speedTime);
gl.uniform1f(u.uLayerTime, clock.layerTime);
gl.uniform2f(u.uMouse, mouse.x, mouse.y);
gl.uniform1f(u.uGlowIntensity, p.glowIntensity);
gl.uniform1f(u.uSaturation, p.saturation);
gl.uniform1i(u.uMouseRepulsion, p.pointer === "repel" ? 1 : 0);
gl.uniform1f(u.uTwinkleIntensity, p.twinkleIntensity);
gl.uniform1f(u.uRotationSpeed, p.rotationSpeed);
gl.uniform1f(u.uRepulsionStrength, p.repulsionStrength);
gl.uniform1f(u.uMouseActiveFactor, mouse.active);
gl.uniform1f(u.uAutoCenterRepulsion, p.autoCenterRepulsion);
gl.uniform1i(u.uTransparent, p.transparent ? 1 : 0);
gl.uniform1f(u.uAutoDrift, p.autoDrift);
gl.clearColor(0, 0, 0, p.transparent ? 0 : 1);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.drawArrays(gl.TRIANGLES, 0, 3);
};
// ── Loop ──────────────────────────────────────────────────────────────────────────────────────
const motion = window.matchMedia("(prefers-reduced-motion: reduce)");
let still = motion.matches;
let visible = true;
let raf = 0;
let last = 0;
const frame = (now: number) => {
raf = requestAnimationFrame(frame);
const dt = last ? Math.min((now - last) / 1000, MAX_DT) : 0;
last = now;
const p = propsRef.current;
if (p.pointer === "off") mouse.targetActive = 0;
if (!p.disableAnimation) {
clock.time += dt;
clock.starTime += (dt * p.starSpeed) / 10;
clock.speedTime += dt * p.speed;
clock.layerTime += ((dt * p.starSpeed) / 10) * p.speed;
}
const k = 1 - Math.pow(1 - POINTER_EASE, dt * 60);
mouse.x += (mouse.tx - mouse.x) * k;
mouse.y += (mouse.ty - mouse.y) * k;
mouse.active += (mouse.targetActive - mouse.active) * k;
draw();
};
const start = () => {
if (raf || still || !visible || document.hidden) return;
last = 0;
raf = requestAnimationFrame(frame);
};
const stop = () => {
cancelAnimationFrame(raf);
raf = 0;
};
redrawRef.current = () => {
if (!raf) draw();
};
// One pixel per CSS pixel, as on the site.
const resize = () => {
const w = Math.max(1, root.offsetWidth);
const h = Math.max(1, root.offsetHeight);
if (canvas.width !== w || canvas.height !== h) {
canvas.width = w;
canvas.height = h;
}
draw();
};
resize();
const ro = new ResizeObserver(resize);
ro.observe(root);
const io = new IntersectionObserver(([entry]) => {
visible = entry.isIntersecting;
if (visible) start();
else stop();
});
io.observe(root);
const onVisibility = () => (document.hidden ? stop() : start());
document.addEventListener("visibilitychange", onVisibility);
const onMotion = () => {
still = motion.matches;
if (still) {
stop();
draw();
} else start();
};
motion.addEventListener("change", onMotion);
// Pointer: positions are 0–1 across the root, y up, as the shader expects.
const onMove = (e: PointerEvent) => {
if (propsRef.current.pointer === "off") return;
const rect = root.getBoundingClientRect();
mouse.tx = (e.clientX - rect.left) / rect.width;
mouse.ty = 1 - (e.clientY - rect.top) / rect.height;
mouse.targetActive = 1;
};
const onLeave = () => {
mouse.targetActive = 0;
};
root.addEventListener("pointermove", onMove);
root.addEventListener("pointerleave", onLeave);
root.addEventListener("pointercancel", onLeave);
start();
return () => {
stop();
redrawRef.current = () => {};
ro.disconnect();
io.disconnect();
document.removeEventListener("visibilitychange", onVisibility);
motion.removeEventListener("change", onMotion);
root.removeEventListener("pointermove", onMove);
root.removeEventListener("pointerleave", onLeave);
root.removeEventListener("pointercancel", onLeave);
buffers.forEach((b) => gl.deleteBuffer(b));
gl.deleteProgram(program);
gl.deleteShader(vs);
gl.deleteShader(fs);
gl.getExtension("WEBGL_lose_context")?.loseContext();
canvas.remove();
};
}, []);
// A prop changed while the loop is asleep: show it anyway.
useEffect(() => {
redrawRef.current();
});
return (
<div ref={rootRef} className="gx-root" style={{ background }}>
<style href="ui-interstellar-space" precedence="ui">
{css}
</style>
</div>
);
}






