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: make Volumetric Smoke light enough for laptops and phones
matin9a5a750d7e14
diff --git a/animations/06-3d-advanced/volumetric-smoke/README.md b/animations/06-3d-advanced/volumetric-smoke/README.mdindex 07385b00..b8224f57 100644--- a/animations/06-3d-advanced/volumetric-smoke/README.md+++ b/animations/06-3d-advanced/volumetric-smoke/README.md@@ -50,6 +50,7 @@ float smokeDensity(vec3 p, float t) {float r = length(p.xz);// smoothstep needs edge0 < edge1, so the upper falloff is inverted rather than reversedfloat 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;}@@ -57,6 +58,8 @@ float smokeDensity(vec3 p, float t) {`rise` grows every frame by the frame's time × the speed, on the page, so changing the speed never makes the smoke jump.+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.+## Key parameters| Parameter | Default | Effect ||-----------|---------|--------|@@ -69,7 +72,7 @@ float smokeDensity(vec3 p, float t) {## 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 `steps x (fbm + 3 shadow taps)`. Honouring a 3x phone DPR would multiply the cost ninefold, so the demo caps the backing store at 0.75 CSS pixels and the march at 48 steps below 600px, and never exceeds 1 CSS pixel on desktop.+- **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.- **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 04745275..dac51f7a 100644--- a/animations/06-3d-advanced/volumetric-smoke/index.html+++ b/animations/06-3d-advanced/volumetric-smoke/index.html@@ -185,6 +185,8 @@ float density(vec3 p,float t){vec3 q=p+vec3(windX,0.,0.);// Cone source shape: narrower at topfloat r=length(p.xz);float src=exp(-r*3.)*smoothstep(-.2,0.6,p.y)*(1.-smoothstep(1.0,1.8,p.y));+ // Nothing to add where the plume has faded out, so the five noise samples are only taken where there can be smoke+ if(src<1e-3)return 0.;float n=fbm(q*1.4+vec3(0.,uRise*.4,0.));return max(0.,n-.45)*src*uDens*2.;}@@ -258,12 +260,13 @@ 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. Phones render below that-// (0.75) and take at most 48 steps, so High is 48 there: that pair is the reduced-quality path this effect needs on mobile.+// Ray marching is fill-rate bound, so the backing store never exceeds one CSS pixel per fragment, and holds about 90,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);+ const phone=PHONE.matches,s=Math.min(window.devicePixelRatio||1,phone?.75:1,Math.sqrt(90000/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// (a phone's address bar showing or hiding also fires resize).diff --git a/docs/superpowers/plans/2026-09-29-3d-content.md b/docs/superpowers/plans/2026-09-29-3d-content.mdindex 12194bc5..e2f13557 100644--- a/docs/superpowers/plans/2026-09-29-3d-content.md+++ b/docs/superpowers/plans/2026-09-29-3d-content.md@@ -92,7 +92,7 @@ What stays: the still picture (every loop draws a full frame at load and is pausCLAUDE.md asks for 60 fps on a mid-range phone, and a reduced-quality fallback on phones for heavy effects. Each section has a **Phone fallback** line: what the demo already does, or the smallest change that keeps it smooth. "On phones" means a screen 600px wide or less, which is how these demos already decide (`innerWidth<=600` or `matchMedia('(max-width:600px)')`).-The WebGL pages already draw fewer pixels on phones (a lower pixel ratio, and fewer ray steps on the two ray-marching pages), and GPGPU Particle System starts with fewer particles; those stay. Their cost is on the graphics chip, which a headless measurement cannot stand in for.+The WebGL pages already draw fewer pixels on phones (a lower pixel ratio, and fewer ray steps on the two ray-marching pages), and GPGPU Particle System starts with fewer particles; those stay, except that Volumetric Smoke needed more (its section has the numbers, measured with GPU rendering on an Intel UHD chip). Their cost is on the graphics chip, which a headless measurement in software cannot stand in for.The canvas and SVG pages were measured in a scratch run: headless Chrome at 375×812 with pixel ratio 2, the CPU slowed four times (roughly a mid-range phone), the old demos with their stage set to a phone stage (351×300 in the first runs, 343×300, the shared phone stage, in the later Canvas Particle Effect runs), recording how long each animation-frame callback runs and how many frames were drawn in 3 seconds (180 is a full 60 fps). The browser draws the canvas in software there, so frame counts are pessimistic, but they show where the work is.@@ -1331,7 +1331,11 @@ 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:** today's stays: on screens 600px wide or less the canvas draws at 0.75 of the stage's CSS size (at most 1 on computers) and a ray takes at most 48 steps, so High is 48 there.+- **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.+ - **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.**Main settings**@@ -1382,8 +1386,10 @@ None: leave out the `details.hb-options` block.- [Ray Marching / SDF Scene](../ray-marching-sdf/) — rays that stop at surfaces instead of adding up smoke- [Noise-Based Motion](../noise-based-motion/) — the same kind of noise, on a flat canvas- [Fluid / Liquid Simulation](../fluid-simulation/) — a soft, liquid look drawn by a shader-- **README How it works:** in the `smokeDensity` snippet, `t * speed` becomes `rise`, and this sentence follows the snippet: "`rise` grows every frame by the frame's time × the speed, on the page, so changing the speed never makes the smoke jump." The rest is unchanged.-- **README Production notes:** unchanged+- **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.- **Category line:** `06.16 · 3D & Advanced`- **Pager:** Previous: Cloth / Soft-Body Simulation (`../cloth-simulation/`) · Next: Morphing Blob (`../morphing-blob/`)