176 web animation techniques, each a live demo with plain settings and a ready-made prompt for your AI assistant. No dependencies, no build step.
HTML ai-promptsanimationcss-animationsfrontendgithub-pagesjavascriptmicrointeractionsmotion-designno-dependenciesreferencescroll-animationui-animationweb-animationweb-developmentwebgl
fix: cap Ray Marching's canvas at 300,000 pixels so it holds 60 fps on 1.5x and 2x screens and tablets
matin082bb783852e
diff --git a/animations/06-3d-advanced/ray-marching-sdf/README.md b/animations/06-3d-advanced/ray-marching-sdf/README.mdindex 685dd500..c779e6fa 100644--- a/animations/06-3d-advanced/ray-marching-sdf/README.md+++ b/animations/06-3d-advanced/ray-marching-sdf/README.md@@ -18,8 +18,8 @@ float rayMarch(vec3 ro, vec3 rd) { // ray origin, ray directionfor (int i = 0; i < MAX_STEPS; i++) {float d = scene(ro + rd * t); // distance to nearest surfaceif (d < 0.001) return t; // hit- t += d; // safe to advance by d- if (t > 20.0) break; // escaped scene+ t += d * 0.9; // step a little short: blended and carved shapes are not exact distances+ if (t > 22.0) break; // escaped scene}return -1.0; // no hit}@@ -75,7 +75,7 @@ vec3 getNormal(vec3 p) {## Production notes- **Shadertoy convention**: uniforms are `iTime`, `iResolution`, `iMouse`. Porting Shadertoy code to WebGL requires renaming these to your own uniform names and adding the WebGL boilerplate (vertex shader + quad).-- **Performance scales with pixel count, not scene complexity**: adding 10 more SDF operations costs very little — adding a 4K display multiplies cost by 4×. Run at half resolution and upscale for complex shaders on mobile.+- **Performance scales with pixels and with the work per step**: every step of every ray evaluates the whole scene formula, so each extra shape or operation adds to every step, and a 4K display costs 4× what 1080p does. The demo caps its canvas at about 300,000 pixels and lets the browser scale it up; on phones it also draws at 0.7 of the stage and takes two thirds of the steps.- **Soft shadows and AO**: both require additional rays per fragment (shadow ray, AO samples). Soft shadows are expensive — 20 shadow-march steps per lit pixel doubles the total march work. Toggle off on low-end devices.- **`mediump` precision**: complex distance functions with large-scale repetition can lose precision at `mediump`. Use `highp float` for SDF scenes with repetition patterns or fine geometry.- **Three.js alternative**: Three.js with `ShaderMaterial` passes the same uniforms to the same fragment shader — the GLSL is identical, only the WebGL boilerplate changes.diff --git a/animations/06-3d-advanced/ray-marching-sdf/index.html b/animations/06-3d-advanced/ray-marching-sdf/index.htmlindex 517e260e..dff9b48c 100644--- a/animations/06-3d-advanced/ray-marching-sdf/index.html+++ b/animations/06-3d-advanced/ray-marching-sdf/index.html@@ -243,9 +243,10 @@ const PHONE=matchMedia('(max-width:600px),(max-height:500px)');function steps(){return STEPS[PHONE.matches?1:0][DETAIL];}let MAX_STEPS=steps();-// Cost is one full ray march per *pixel*, so the backing store is what sets the-// bill. Phones render below CSS resolution and desktops cap DPR at 1.5.-function qScale(){const dpr=window.devicePixelRatio||1;return PHONE.matches?Math.min(dpr,0.7):Math.min(dpr,1.5);}+// Cost is one full ray march per *pixel*, so the backing store is what sets the bill. Phones render below CSS resolution, computers+// cap the pixel ratio at 1.5, and the canvas holds about 300,000 pixels at most (the browser scales it up), which keeps 60 fps on+// integrated graphics on 1.5x and 2x screens, big desktop stages and tablets.+function qScale(){const dpr=window.devicePixelRatio||1;return Math.min(PHONE.matches?Math.min(dpr,0.7):Math.min(dpr,1.5),Math.sqrt(300000/Math.max(1,stage.clientWidth*stage.clientHeight)));}function fail(msg,detail){cvs.hidden=true;fallback.style.display='flex';diff --git a/docs/superpowers/plans/2026-09-29-3d-content.md b/docs/superpowers/plans/2026-09-29-3d-content.mdindex 6ce9feae..36f6322f 100644--- a/docs/superpowers/plans/2026-09-29-3d-content.md+++ b/docs/superpowers/plans/2026-09-29-3d-content.md@@ -1051,7 +1051,8 @@ None: leave out the `details.hb-options` block.- **Reduced motion:** the page's reduced-motion branch goes (see the preamble).- **Stage font:** no text on the stage; `.fallback` uses the site font.- **Stage:** only the canvas. The fps and scene badges and the shader source panel go; `.fallback` stays. `hb-dots`: no. Default height.-- **Phone fallback:** today's stays: on screens 600px wide or less the canvas draws at 0.7 of the stage's CSS size (up to 1.5 times on computers), and Detail takes two thirds of the steps there (16 · 32 · 64 in place of 24 · 48 · 96; today phones start at 32).+- **Phone fallback:** today's stays: on phones (screens 600px wide or less, or 500px tall or less) the canvas draws at 0.7 of the stage's CSS size (up to 1.5 times on computers), and Detail takes two thirds of the steps there (16 · 32 · 64 in place of 24 · 48 · 96; today phones start at 32).+- **Pixel cap:** on every screen the canvas also holds about 300,000 pixels at most, and the browser scales it up: the scale is the smaller of the ratio above and `Math.sqrt(300000/(w×h))` for a stage of w×h CSS pixels. The cost is one ray march per backing pixel, so without the cap the 60 fps rule failed on integrated graphics. Measured on an Intel UHD chip, frames drawn in 3 seconds (180 is 60 fps), each run checked against a stage-sized control page that read 181–182: 1280×720 at 1.5× 96 frames before the cap and 180 after; 1440×900 at 2× 86 → 180; 1920×1080 at 1× 167 → 181; a 768×1024 tablet at 2× with the CPU slowed four times 120 → 181; the 1366×657 laptop 180 → 179, which is no change, because its canvas was already under the cap.**Main settings**