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: lower Volumetric Smoke's canvas cap to 65,000 pixels so a portrait tablet holds 60 fps
matinbda5d8d58691
diff --git a/animations/06-3d-advanced/volumetric-smoke/README.md b/animations/06-3d-advanced/volumetric-smoke/README.mdindex b8224f57..acdada20 100644--- a/animations/06-3d-advanced/volumetric-smoke/README.md+++ b/animations/06-3d-advanced/volumetric-smoke/README.md@@ -52,7 +52,7 @@ float smokeDensity(vec3 p, float t) {float src = exp(-r * 3.0) * smoothstep(-0.2, 0.6, p.y) * (1.0 - smoothstep(1.0, 1.8, p.y));if (src < 0.001) return 0.0; // nothing to add here, so skip the noisefloat n = fbm(p * 1.4 + vec3(windDrift, rise, 0.0));- return max(0.0, n - 0.45) * src * density;+ return max(0.0, n - 0.45) * src * density * 2.0;}```@@ -72,7 +72,7 @@ Wherever `src` has faded to almost nothing the function returns before the noise## Production notes- **Precision**: the `sin`-based hash multiplies by 43758.5, which overflows the usable range of a 16-bit `mediump` float and collapses the noise to flat blocks on many mobile GPUs. Request `highp` in the fragment shader (guarded by `GL_FRAGMENT_PRECISION_HIGH`) or swap the hash for an integer-free variant with a smaller multiplier.-- **Mobile cost**: this is fill-rate bound — every fragment runs up to `steps x (fbm + 3 shadow taps)`, so the demo trims it three ways. `smokeDensity` returns before the noise wherever the plume has faded out. The backing store is capped at about 90,000 pixels and the browser scales it up to the stage, which suits soft smoke; it never exceeds 1 CSS pixel per fragment either. On phones (screens 600px wide or less, or 500px tall or less when held sideways) the backing store is also at most 0.75 of the stage and the march at most 48 steps. Honouring a 3x phone DPR would multiply the cost ninefold.+- **Mobile cost**: this is fill-rate bound — every fragment runs up to `steps x (fbm + 3 shadow taps)`, so the demo trims it three ways. `smokeDensity` returns before the noise wherever the plume has faded out. The backing store is capped at about 65,000 pixels and the browser scales it up to the stage, which suits soft smoke; it never exceeds 1 CSS pixel per fragment either. On phones (screens 600px wide or less, or 500px tall or less when held sideways) the backing store is also at most 0.75 of the stage and the march at most 48 steps. Honouring a 3x phone DPR would multiply the cost ninefold.- **Context loss**: a GPU reset, a backgrounded tab on mobile, or a driver hiccup fires `webglcontextlost`. Without a listener the canvas goes permanently black with no error. Preventing the default event and rebuilding shaders and buffers on `webglcontextrestored` is the production path; this demo takes the simpler route of stopping the loop and showing a message.- **Step count vs quality**: each additional march step increases pixel cost linearly. 32 steps is generally sufficient for soft smoke; use 64 only for hero-quality renders. Add blue-noise dithering to random-offset each ray's start, breaking up banding artifacts at low step counts. The offset has to be a fraction of a *full step* to help — jittering by a few thousandths of a unit is invisible.- **Shadow rays**: the 3-step shadow march adds 3× extra density samples per lit pixel. Toggle off on low-end devices. For production, pre-compute a voxelized shadow map and sample it instead.diff --git a/animations/06-3d-advanced/volumetric-smoke/index.html b/animations/06-3d-advanced/volumetric-smoke/index.htmlindex dac51f7a..2b29c732 100644--- a/animations/06-3d-advanced/volumetric-smoke/index.html+++ b/animations/06-3d-advanced/volumetric-smoke/index.html@@ -260,15 +260,15 @@ function init(){// After a lost context nothing draws again until the page is reloaded (as the message says), even if the browser restores the contextconst live=()=>!!gl&&!lost&&!gl.isContextLost();-// Ray marching is fill-rate bound, so the backing store never exceeds one CSS pixel per fragment, and holds about 90,000 pixels+// Ray marching is fill-rate bound, so the backing store never exceeds one CSS pixel per fragment, and holds about 65,000 pixels// at most: the browser scales the canvas up to the stage, which suits smoke this soft. Phones render at most 0.75 of the stage// and take at most 48 steps, so High is 48 there: that is the reduced-quality path this effect needs on mobile.// The visitor's Detail stays as chosen; the limit is applied when drawing, so it follows the screen both ways.function steps(){return Math.min(STEPS,PHONE.matches?48:64);}function layout(force){- const phone=PHONE.matches,s=Math.min(window.devicePixelRatio||1,phone?.75:1,Math.sqrt(90000/Math.max(1,stage.clientWidth*stage.clientHeight)));+ const phone=PHONE.matches,s=Math.min(window.devicePixelRatio||1,phone?.75:1,Math.sqrt(65000/Math.max(1,stage.clientWidth*stage.clientHeight)));const w=Math.max(1,Math.round(stage.clientWidth*s)),h=Math.max(1,Math.round(stage.clientHeight*s));- // Setting the size clears the canvas, so nothing is touched when the stage is the same size and the phone limits are the same+ // Setting the size clears the canvas, so nothing is touched when the canvas would come out the same size and the phone limits are the same// (a phone's address bar showing or hiding also fires resize).if(!force&&w===W&&h===H&&phone===wasPhone)return false;W=cvs.width=w;H=cvs.height=h;wasPhone=phone;diff --git a/docs/superpowers/plans/2026-09-29-3d-content.md b/docs/superpowers/plans/2026-09-29-3d-content.mdindex 36f6322f..80189f9b 100644--- a/docs/superpowers/plans/2026-09-29-3d-content.md+++ b/docs/superpowers/plans/2026-09-29-3d-content.md@@ -1342,9 +1342,9 @@ None: leave out the `details.hb-options` block.- **Reduced motion:** the page's reduced-motion branch goes (see the preamble), with the CSS comment about it.- **Stage font:** no text on the stage; `.msg` uses the site font.- **Stage:** only the canvas. The fps and steps badges and the shader source panel go; `.msg` stays. `hb-dots`: no. Default height.-- **Phone fallback:** more than today's, because today's left the effect at 6 to 7 frames a second on a laptop with integrated graphics and at 20 to 38 on the phone stages, against the 60 CLAUDE.md asks for (Intel UHD chip, GPU rendering in headless Chrome, the CPU slowed four times on the tablet and phones). Two changes carry it:- - **The plume's edge:** `density()` returns 0 at once where the plume's shape is faint, `if(src<1e-3)return 0.;` after the `src` line and before the `fbm` line, so the five noise samples are only taken where there can be smoke. The first picture changes by 4/255 at most in a pixel (about 15/255 at most with Thick smoke).- - **The canvas:** it is capped at about 90,000 pixels. It draws at `Math.min(devicePixelRatio, 0.75 on phones, Math.sqrt(90000/(stage width × stage height)))` of the stage's CSS size and the browser scales it up (the resize guard compares the resulting canvas size, as before). With both changes the stage differs from today's by 0.05 to 0.15/255 on average; the grain is a little coarser.+- **Phone fallback:** more than today's, because today's left the effect at 6 to 7 frames a second on a laptop with integrated graphics and at 20 to 38 on the phone stages, against the 60 CLAUDE.md asks for (Intel UHD chip, GPU rendering in headless Chrome, the CPU slowed four times on the tablet and phones). Two changes carry it, with the phone limits below:+ - **The plume's edge:** `density()` returns 0 at once where the plume's shape is faint, `if(src<1e-3)return 0.;` after the `src` line and before the `fbm` line, so the five noise samples are only taken where there can be smoke. The first picture changes by 4/255 at most in a pixel (12/255 at most with Thick smoke; 15/255 later in the loop).+ - **The canvas:** it is capped at about 65,000 pixels. It draws at `Math.min(devicePixelRatio, 0.75 on phones and 1 elsewhere, Math.sqrt(65000/(w×h)))` of the stage's CSS size, where w×h is the stage's size in CSS pixels, and the browser scales it up (the resize guard compares the resulting canvas size, as before). With both changes the stage differs from today's by 0.05 to 0.15/255 on average; the grain is a little coarser. The cap was 90,000 at first, which drew only 148 to 156 frames in 3 seconds on a portrait tablet (768×1024 at 2×, CPU slowed four times); 65,000 draws 181 there, and its first picture differs from the 90,000 one in 0.02% of its pixels by more than 8/255. Laptops and landscape tablets draw 181 at every cap.- **Phones** are screens 600px wide or less, or 500px tall or less (held sideways). There the canvas is also at most 0.75 of the stage and a ray takes at most 48 steps, so High is 48 (today's).- **Measured:** frames drawn in 3 seconds at Medium (180 is a full 60 fps), before → after: 1366×657 laptop 23 → 180, 1280×800 computer 21 → 181, tablet 25 → 156, phone held upright 114 → 180, phone held sideways 61 → 181; at High: 12 → 122, 11 → 113, 14 → 85, 80 → 159 (48 steps), 44 → 160 (48 steps). Low draws about 180 on every screen.@@ -1400,7 +1400,7 @@ None: leave out the `details.hb-options` block.- **README How it works:** in the `smokeDensity` snippet, `t * speed` becomes `rise`, and the line `if (src < 0.001) return 0.0; // nothing to add here, so skip the noise` goes after the `src` line, before the `fbm` line. These sentences follow the snippet, as two paragraphs: "`rise` grows every frame by the frame's time × the speed, on the page, so changing the speed never makes the smoke jump." and "Wherever `src` has faded to almost nothing the function returns before the noise, so the five noise samples are only taken where there can be smoke. That, together with the smaller canvas described under Mobile cost, keeps the demo smooth on laptops and phones." The rest is unchanged.- **README Production notes:** the Mobile cost bullet is rewritten, the rest is unchanged:- > - **Mobile cost**: this is fill-rate bound — every fragment runs up to `steps x (fbm + 3 shadow taps)`, so the demo trims it three ways. `smokeDensity` returns before the noise wherever the plume has faded out. The backing store is capped at about 90,000 pixels and the browser scales it up to the stage, which suits soft smoke; it never exceeds 1 CSS pixel per fragment either. On phones (screens 600px wide or less, or 500px tall or less when held sideways) the backing store is also at most 0.75 of the stage and the march at most 48 steps. Honouring a 3x phone DPR would multiply the cost ninefold.+ > - **Mobile cost**: this is fill-rate bound — every fragment runs up to `steps x (fbm + 3 shadow taps)`, so the demo trims it three ways. `smokeDensity` returns before the noise wherever the plume has faded out. The backing store is capped at about 65,000 pixels and the browser scales it up to the stage, which suits soft smoke; it never exceeds 1 CSS pixel per fragment either. On phones (screens 600px wide or less, or 500px tall or less when held sideways) the backing store is also at most 0.75 of the stage and the march at most 48 steps. Honouring a 3x phone DPR would multiply the cost ninefold.- **Category line:** `06.16 · 3D & Advanced`- **Pager:** Previous: Cloth / Soft-Body Simulation (`../cloth-simulation/`) · Next: Morphing Blob (`../morphing-blob/`)