Skip to content

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.

fix: settle the GPGPU particles before a still picture, ignore pressing the chosen Color, and never leave a shader error blank

matin988e8c75c707
diff --git a/animations/06-3d-advanced/gpgpu-particle-system/README.md b/animations/06-3d-advanced/gpgpu-particle-system/README.md
index 06de6f85..f4e0cab5 100644
--- a/animations/06-3d-advanced/gpgpu-particle-system/README.md
+++ b/animations/06-3d-advanced/gpgpu-particle-system/README.md
@@ -97,7 +97,7 @@ void main() {
- **Wrap only survives a divergence-free field**: this demo's flow field pushes particles away from the x-axis, so it has a net outward drift. An earlier version wrapped at ±1.2 while only ±1.0 is visible; particles drifted into that invisible ring faster than they came back and the canvas faded to black after about ten seconds. Tightening the wrap to ±1.0 only moved the symptom — a divergent field teleports the escapee straight back to the edge it just left, so the particles crust along the top and bottom instead. Respawning escapees at a random point near the middle is the fix, and it is what keeps the population steady here. Nothing throws in either failure, and the first second looks correct in all three versions, so this class of bug is only visible if you leave the demo running.
- **Point size is in device pixels**: the canvas backing store is sized `clientWidth * devicePixelRatio` (capped at 2 here) and `gl.viewport` uses those same numbers. `gl_PointSize` is measured in device pixels too, so it has to be multiplied by the same ratio or the points shrink on a retina screen.
- **Context loss**: a GPU reset, a tab restore, or too many live WebGL contexts will fire `webglcontextlost`. Without a listener that calls `preventDefault()`, the context never comes back and the demo stays black forever. On `webglcontextrestored` every program, buffer, texture and framebuffer has to be recreated — GPU objects do not survive the loss.
-- **Mobile budget**: 65k additively blended points cover a phone screen several times over and are both slow and visually mushy. This demo drops to a 128x128 texture (16k particles) under 600px; a production system should scale the texture size to the pixel count it actually has to fill.
+- **Mobile budget**: 65k additively blended points cover a phone screen several times over and are both slow and visually mushy. This demo drops to a 128x128 texture (16k particles) on phones (screens 600px wide or less, or 500px tall or less); a production system should scale the texture size to the pixel count it actually has to fill.
- **Memory**: 256×256 × 4 channels × 4 bytes (float32) = 1MB per texture. Two textures = 2MB — trivial. At 512×512 (262k particles): 4MB × 2 = 8MB.
## See also
diff --git a/animations/06-3d-advanced/gpgpu-particle-system/index.html b/animations/06-3d-advanced/gpgpu-particle-system/index.html
index b9507837..e1f6d193 100644
--- a/animations/06-3d-advanced/gpgpu-particle-system/index.html
+++ b/animations/06-3d-advanced/gpgpu-particle-system/index.html
@@ -236,8 +236,8 @@ document.querySelectorAll('#count-seg button').forEach(b=>{
b.classList.toggle('on',on);b.setAttribute('aria-pressed',String(on));
});
-function mk(t,s){const x=gl.createShader(t);gl.shaderSource(x,s);gl.compileShader(x);if(!gl.getShaderParameter(x,gl.COMPILE_STATUS)){shaderErr=gl.getShaderInfoLog(x);console.error(shaderErr);}return x;}
-function mkProg(vs,fs){const p=gl.createProgram();gl.attachShader(p,mk(gl.VERTEX_SHADER,vs));gl.attachShader(p,mk(gl.FRAGMENT_SHADER,fs));gl.linkProgram(p);if(!gl.getProgramParameter(p,gl.LINK_STATUS)){shaderErr=gl.getProgramInfoLog(p);console.error(shaderErr);}return p;}
+function mk(t,s){const x=gl.createShader(t);gl.shaderSource(x,s);gl.compileShader(x);if(!gl.getShaderParameter(x,gl.COMPILE_STATUS)){shaderErr=gl.getShaderInfoLog(x)||'the shader did not compile';console.error(shaderErr);}return x;}
+function mkProg(vs,fs){const p=gl.createProgram();gl.attachShader(p,mk(gl.VERTEX_SHADER,vs));gl.attachShader(p,mk(gl.FRAGMENT_SHADER,fs));gl.linkProgram(p);if(!gl.getProgramParameter(p,gl.LINK_STATUS)){shaderErr=gl.getProgramInfoLog(p)||'the shaders did not link';console.error(shaderErr);}return p;}
function initTex(n){
const data=new Float32Array(n*n*4);
@@ -311,7 +311,7 @@ function render(ts){
}
// ── Physics pass (render to texture) ──
-function physics(t){
+function physics(t,step){
gl.useProgram(physicsProg);
gl.bindFramebuffer(gl.FRAMEBUFFER,fbo1);
gl.viewport(0,0,TEX_N,TEX_N);
@@ -322,13 +322,15 @@ function physics(t){
gl.uniform1i(gl.getUniformLocation(physicsProg,'uPos'),0);
gl.uniform1f(gl.getUniformLocation(physicsProg,'uT'),t);
gl.uniform1f(gl.getUniformLocation(physicsProg,'uSpd'),SPD);
- gl.uniform1f(gl.getUniformLocation(physicsProg,'uStep'),slowTog.checked?1/3:1);
+ gl.uniform1f(gl.getUniformLocation(physicsProg,'uStep'),step===undefined?(slowTog.checked?1/3:1):step);
gl.uniform1i(gl.getUniformLocation(physicsProg,'uBehavior'),BEHAVIOR);
gl.drawArrays(gl.TRIANGLE_STRIP,0,4);
// Swap textures
[tex0,tex1]=[tex1,tex0];[fbo0,fbo1]=[fbo1,fbo0];
}
+// 120 silent steps (two seconds of flow at the full step), so a picture shown still already shows the flow, not the starting cloud
+function settle(){for(let i=0;i<120;i++){simT+=1/60;physics(simT,1);}}
// ── Render pass (draw points). A picture drawn on its own starts from a cleared canvas ("fresh"): with Trails on, a
// normal frame only lays a thin fade over the last one, which would leave the old picture showing under a new setting. ──
@@ -370,7 +372,7 @@ document.addEventListener('hb:pause',e=>{
if(init()){
resize();
- physics(simT);paint(simT,true); // the first picture, so a loop that is paused on arrival never shows an empty stage
+ settle();paint(simT,true); // the first picture, so a loop that is paused on arrival never shows an empty stage
start();
window.addEventListener('resize',()=>{if(resize()&&gl)paint(simT,true);});
cvs.addEventListener('webglcontextlost',e=>{
@@ -400,10 +402,10 @@ choices('count-seg',d=>{
const n=+d.n;
if(n===TEX_N)return; // choosing what is already chosen must not scatter the particles again
TEX_N=n;
- if(gl){initTex(TEX_N);repaint();}
+ if(gl){initTex(TEX_N);if(paused)settle();repaint();}
});
choices('speed-seg',d=>{SPD=+d.spd;});
-choices('color-seg',d=>{COLOR_MODE=+d.mode;repaint();});
+choices('color-seg',d=>{if(+d.mode===COLOR_MODE)return;COLOR_MODE=+d.mode;repaint();});
document.getElementById('trail-tog').addEventListener('change',e=>{TRAILS=e.target.checked;repaint();});
</script>
</body>
diff --git a/docs/superpowers/plans/2026-09-29-3d-content.md b/docs/superpowers/plans/2026-09-29-3d-content.md
index 80189f9b..8629c784 100644
--- a/docs/superpowers/plans/2026-09-29-3d-content.md
+++ b/docs/superpowers/plans/2026-09-29-3d-content.md
@@ -1119,27 +1119,27 @@ None: leave out the `details.hb-options` block.
- **Sequence:** the WebGL 2 loop as in the preamble (`render(ts)`, 12ms gate).
- `drawFrame(t)` splits into `physics(t)` (the physics pass and the texture swap) and `paint(t)` (the drawing pass). Each drawn frame runs both.
- The page keeps its own clock, `simT` (each frame's time, at most 50ms, and nothing on the first frame after a start), in place of `(ts-startT)/1000`.
- - **The first picture:** `physics()` and `paint()` run once at load (today's `resize()` draws only while paused).
- - **While paused,** a setting or a resize calls `paint()` only. Today's `refresh()` also ran a physics step, which moved the particles a little while paused.
+ - **The first picture:** `settle()` and then `paint()` run once at load (today's `resize()` draws only while paused). `settle()` is 120 silent physics steps at the full step, whatever Slow motion says (`physics(t,step)` takes the step as a second argument and sets `uStep` to it; called without one it uses 1, or 1/3 in slow motion, as before). That is two seconds of flow, so a picture shown still (paused on arrival, or under reduced motion) already shows the flow, not the starting square cloud. It costs about 23 ms on a laptop and 11 ms on a phone with the CPU slowed four times.
+ - **While paused,** a setting or a resize calls `paint()` only. Today's `refresh()` also ran a physics step, which moved the particles a little while paused. A change of Number of particles builds the new cloud and settles it first, so the picture shows the flow and not the starting cloud. Pressing the Number of particles or the Color that is already chosen does nothing (Color would otherwise draw the picture again and erase the streaks Trails leaves).
- **Slow motion:** the physics shader gets `uniform float uStep` (1, or 1/3 while Slow motion is on), from the next frame. Every change of velocity is multiplied by `uStep` (the four behaviours' pushes, and the vortex's and orbit's inward pulls), the damping becomes `pow(.985,uStep)`, and the move becomes `x+=vx*uStep; y+=vy*uStep`. So every particle moves a third as far each frame while its speed and the shapes the particles form stay the same. The clock adds a third of each frame's time.
- **Reduced motion:** the page's reduced-motion branch goes (see the preamble).
-- **Stage font:** no text on the stage. The WebGL 2 message uses the site font and reads "This demo needs WebGL 2, which this browser does not offer. Try a recent Chrome, Firefox or Safari.", set with `textContent` (was "WebGL2 required for GPGPU texture ping-pong." with a `<br>`).
+- **Stage font:** no text on the stage. The WebGL 2 message uses the site font and reads "This demo needs WebGL 2, which this browser does not offer. Try a recent Chrome, Firefox or Safari.", set with `textContent` (was "WebGL2 required for GPGPU texture ping-pong." with a `<br>`). A shader that fails to build reads "Shader failed to build: " and the browser's log; when the browser gives no log the page says "the shader did not compile" (or "the shaders did not link"), so the message is never left blank, as on Ray Marching / SDF Scene and Volumetric Smoke.
- **Stage:** only the canvas. The fps, count and behaviour badges go; `.no-wgl2` stays. `hb-dots`: no. Default height.
-- **Phone fallback:** today's stays: on screens 600px wide or less the page starts with 16,000 particles (today's `SMALL` default). At load it gives 16,000 the `on` class and `aria-pressed="true"` (and takes them from 65,000) itself, before the shared script reads the settings. The visitor can still pick more.
+- **Phone fallback:** today's stays: on phones (screens 600px wide or less, or 500px tall or less) the page starts with 16,000 particles (today's `SMALL` default). At load it gives 16,000 the `on` class and `aria-pressed="true"` (and takes them from 65,000) itself, before the shared script reads the settings. The visitor can still pick more.
**Main settings**
| Setting | Control | Choices or range (value shown) | Default | Hint | Sets in the demo |
|---|---|---|---|---|---|
| Movement | Choice buttons | Flow · Swirl · Attract · Orbit | Flow | The rule every particle follows. | `BEHAVIOR`: 0 / 1 / 2 / 3 |
-| Number of particles | Choice buttons | 16,000 · 65,000 · 100,000 | 65,000 (16,000 on phones) | Phones start with 16,000; more can be slow there. | `TEX_N`: 128 / 256 / 320, then `initTex(TEX_N)` |
+| Number of particles | Choice buttons | 16,000 · 65,000 · 100,000 | 65,000 (16,000 on phones) | Phones start with 16,000; more can be slow there. | `TEX_N`: 128 / 256 / 320, then `initTex(TEX_N)` (and, while paused, `settle()` before the picture is drawn again) |
| Speed | Choice buttons | Slow · Normal · Fast | Normal | How hard the rule pushes the particles. | `SPD`: 0.35 / 0.6 / 1 |
**More options**
| Setting | Control | Choices or range (value shown) | Default | Hint | Sets in the demo |
|---|---|---|---|---|---|
-| Color | Choice buttons | One color · By speed · Shifting | One color | One color, by speed, or slowly shifting colors. | `COLOR_MODE`: 0 / 1 / 2 |
+| Color | Choice buttons | One color · By speed · Shifting | One color | One color, by speed, or slowly shifting colors. | `COLOR_MODE`: 0 / 1 / 2, then the picture is drawn again while paused; pressing the color already chosen does nothing, because drawing it again would erase the streaks Trails leaves |
| Trails | Switch | on / off | off | Each particle leaves a fading streak. | `TRAILS` true / false |
- **Removed:**