f_particles_spike — can a persistent particle layer, pushed by a vecfield and drawn back as a density, run in a Vsynth chain?
Promoted to a module spec 2026-11-29 (Matt: "Spec the module"): .specify/f_particles/spec.md, plan.md, tasks.md.
Working name f_particles (plain words; the name is Matt's call, gate D1 below).
Status: 🔵 spike plan, decisions D1 to D7 accepted 2026-11-29, tier 1 (NumPy) run 2026-11-29: no stop rule triggered; tier 2: T2.1 and T2.2 run live, GPU path fits the 4 ms budget at 262k particles (about 1.8 ms), T2.3 not run; written 2026-11-29 (Claude, offline, at Matt's go: "Item 5, write the spec"). Nothing run, nothing built. This is item 5 of ideas/cores_next_steps.md, parked as P-cores-particles in .specify/gates.md; Matt reopened it. Format follows ideas/f_peaks_spike.md and ideas/f_defects_spike.md; the cost-budget stop rule follows ideas/f_rd_stepper_spike.md.
The question
Every module so far reads objects OUT of a field (f_cores) or moves a field's own content (f_vf_advect). Can a set of persistent particles live in the chain: a position state that survives from frame to frame, is pushed by an incoming vecfield, and is drawn back into a texture as a density? The motivating case is Chladni sand: particles slide toward the nodal lines of f_chladni and the figure appears as sand collecting there. The bridge note (ideas/field_object_bridge.md, "B. Objects to field") says this "might approximate the figure (inferred, not tried)". This spike is where that gets tried, on a CPU model first.
It is the riskiest of the five f_cores follow-ups because it needs three things this library has not combined: state per object, a scatter, and a cost that scales with the object count.
What already overlaps (checked 2026-11-29 offline; per CLAUDE.md)
- f_ library (
docs/f-reference/module-inventory.md): no module keeps particles.f_vf_advectis the nearest: it carries a TEXTURE backward along a vecfield with a one-frame feedback loop, so injected content spreads and fades. That moves a density, it does not hold N identities, and a bilinear advection smears. Whether it can concentrate sand onto lines as sharply as particles can is inferred: it should not, since the smear is the point of it; the spike's reference comparison tests this.f_causticis the one scatter precedent: a lattice of points displaced ONE step along a field, drawn with additive blending into a float32 capture by a vertex program (package/code/f_caustic_sheets.jxs). It is stateless (the lattice is regenerated each frame), costs about 21 to 23 ms per frame at its fixed setting on an M3 Max, and is driven by points per pixel (blend contention), not the point count (docs/f-reference/f_caustic.md, Notes). Its vertex program reads a texture (texture2D(field, u)), so a vertex-side texture fetch of a position state is the same mechanism (inferred, not tried).f_vf_stampinjects ink and impulse on a press;f_vf_lbmmakes an obstacle flow; neither holds particles.
- Vsynth (
docs/vsynth-reference/module-inventory.md,patterns.md): a search for particle, agent and splat finds only the word "scattered" in a note about file copies. Nothing. - jit.fx (
docs/max-reference/jit_fx.md,jit_fx_vs_ideas.md): nothing for particles or points.tp.delayandcf.radialappear for other ideas. - Jitter itself HAS a particle family (checked 2026-11-29 offline in the installed refpages and help patchers,
/Applications/Max.app/Contents/Resources/C74/docs/refpages/jit-ref/andhelp/jitter/; nothing was run).jit.p.shiva("Generate/eliminate particles": emit rate, life, variance,initvalues),jit.p.vishnu("Apply single force to particles": a world force PER PLANE, plus initial position, speed and direction for newborns) andjit.p.bounds("Limit particles to a region of space":bounds_lo,bounds_hi, a boundary mode,squishbounce). They work on a particle matrix: float32 or float64, 2-D, x by 2 (row 2 holds the previous value of row 1); plane 0 is the particle ID, plane 1 the age/life, planes 2 to 4 x, y, z, planes 5 to 7 velocity (up to 30 free planes) (jit.p.shiva.maxhelp,jit.p.vishnu.maxhelp). These are jit.matrix objects, so CPU (inferred from "matrix" and "jit.op" in the help; not timed).- What they cannot do:
jit.p.vishnuapplies ONE force per plane, a constant "wind", not a force that varies with position. The help says so itself: for "a single attractive force" you do "some math" withjit.opinstead. A vecfield push (force looked up at each particle's own position) is not in the family (inferred from the attribute list and that help text). - What fills the gap in Jitter:
jit.repos("cell positioning on an input matrix using a second matrix as a spatial map") looks like the gather: field matrix in, particle positions as the map, field values at those positions out (inferred from its digest, not tried);jit.opdoes the push;jit.gl.meshorjit.gl.multiple("repeatedly draw an instance of a jit.gl object", fed by matrices) draws from a matrix. Thatjit.gl.meshdraws points: the refpage'sdraw_modelist did not survive (it reads "TEXT_HERE"), butf_caustic's own scene uses it (src/f_caustic/scatter_scene.pyline 112:jit.gl.mesh ... @draw_mode points @shader ... @blend_enable 1 @blend_mode 1 1 @point_size 2, fed a plane gridshape as a matrix: one vertex per lattice point), so a points mesh with additive blending exists in this repo (read from source 2026-11-29; its cost is the 21 to 23 ms figure above). - A GPU-to-CPU readback of the field (
jit.gl.asyncread, already used byf_cores' count) would be needed to hand a vecfield to a CPU particle matrix, one frame late.
- What they cannot do:
- cv.jit (
docs/max-reference/cv_jit.md, 2026-11-29): blob labelling, centroids, point tracking and optical flow objects; nothing that pushes particles by a field. - Temporal state (
docs/max-reference/temporal_synthesis_architecture.md): Pattern 1, a chainedjit.gl.pixfeedback loop, is how every temporal module here keeps a frame; the one-frame settle is a property of closing a loop. A position state in a float32 texture would use it. - Not read: how
f_causticfeeds its lattice (package/code/f_caustic_sheets.jxsandscatter_scene.pywere not opened for this note); thejit.p.*snippets (.maxsnip) and whether Cycling '74 ships any other particle or instancing example (a search ofhelp/andsnippets/by name found only the threejit.p.*); the per-object costs ofjit.repos,jit.opandjit.gl.meshat 100k to 1M cells (never measured here).
The design question, stated so the NumPy tier can test it
State: one float32 texture, N×N texels, one particle per texel, R,G = position in [0,1) (periodic), B,A free (age or a hash seed). Each frame, a pix stage reads the state and the vecfield and writes the new state:
- Gather, not scatter, for the push. The pix stage at texel
isamples the vecfield at the particle's own positionp_iand stepsp_i + dt * F(p_i). That is a gather and is exactly the kind of read a pix stage does well. - Scatter for the drawing. Drawing N points at positions read from the state is the scatter: a vertex program reads the state texture and places a point per particle, with additive blending into a float32 capture (the
f_causticmechanism), then a composite stage normalizes and exposes the density. - Respawn and boundaries. Periodic wrap is free in the position update. A respawn rule (where a particle that is lost or too old comes back) is needed for any field that is not conservative; with a hash of (index, frame) as the new position, a bench stays deterministic if the hash is seeded (a sin hash loses precision at huge arguments;
jit-gen-codeboxskill: the compared quantity needs a tolerance).
Two paths to compare (Jitter's own pieces against a GPU state)
- CPU path (Jitter objects):
jit.p.shivafor spawn and life, a field read back to a matrix (jit.gl.asyncread),jit.reposto sample the field at the particle positions,jit.opto push them,jit.p.boundsor a wrap for the edge,jit.gl.meshto draw. It reuses Cycling '74's code and needs no vertex program, and the count is limited by CPU matrix work and the readback; both unmeasured. - GPU path (library precedent): state texture ping-pong in a pix loop, vertex-side texture fetch and additive scatter as in
f_caustic. No readback, no CPU, and the cost is the scatter's blend contention. - The NumPy tier is path-agnostic (same math). Tier 2 benches whichever the cost estimate favors first, and the spike's job is to say which path, if any, is worth building. Measuring the CPU path means a timing test of
jit.reposplusjit.opplusjit.gl.meshon N points, which needs Max but no new codebox.
What to find out
- Can the sand velocity be built from
f_chladni's existing outlets? Sand slides toward the nodes (wheretotalis 0), down the gradient of|total|. The doc (docs/f-reference/f_chladni.md, Outlets, 1-based there:out1luma,out2gradient oftotalpointing toward antinodes and unit-normalized,out3unsigned magnitude|total|·gain) suggests the direction toward a node is-sign(total) * grad(total)/|grad(total)|, andsign(total)is on no outlet (out1is1 - clamp(sqrt(|total|)·sharpness), which loses the sign). So the existing outlets may be one signal short. Inferred from the outlet table, not tried. This may decide that the module needs a newf_chladnioutlet or its own field read (a design gate, D3). - Does the NumPy particle model converge? On a Chladni
totalfield (the mirror off_chladni, if one exists; not looked for:tests/modules/chladni/was not listed here), do N particles advected by-grad(|total|)collect on the zero set, how fast (frames), and at what density contrast against the nodal-line reference (the zero set oftotal)? - Against the cheap baseline. The same field through a
f_vf_advect-style texture advection (a density, bilinear backward advection): is the particle result sharper, and by how much, at equal frame count? If a texture advection gets most of the way there, the particle machinery is not earning its cost (stop rule 1). - Count against cost, on the CPU model first. Particles per texel of density at 1080p: how many does the figure need before the density is smooth (the
f_causticlesson: noise vs moiré, points per pixel)? A count of N² for N = 256, 512, 1024. - Conservation and clumping. Particles that all reach the line stop moving; a respawn that re-injects them keeps the picture alive. Measure how much density is lost or piles on a single texel, and whether a respawn rate fixes it.
- A second field. Does the same layer do something worth seeing on a field with no nodal lines (a
f_vf_fluidflow: tracers; af_vf_vortexfield: spirals)? Tracers in a flow are the second case in the bridge note ("C. Both ways at once"). - Seeding and determinism. A hashed uniform seed and a hashed respawn, so a bench against the NumPy model is repeatable. What tolerance does the hash need?
- Which path. From the cost rows of tier 2 only: is the CPU Jitter chain (readback,
jit.repos,jit.op, mesh draw) cheaper or dearer than the GPU state plus scatter at the same particle count, and which one reads as sand? Nothing about this is known today; this question cannot be answered offline.
Proposed method (the f_ verification tiers)
- Tier 1, NumPy (offline, no Max, no API calls). Script
tests/records/spike_particles.py, summaries toscratch/experiments/particles_spike/(gitignored). Models: a Chladni field from thef_chladnialgorithm (readdocs/f-reference/f_chladni.mdand its mirror if any), particles, texture advection baseline, density and nodal-line contrast, convergence in frames, N sweep. Answers questions 1 to 7 on the CPU only. - Tier 2, bench (Max foreground, Matt's go, announce first), only if tier 1 passes stop rules 1 to 3. First the cheap half: the position-update pix stage against the NumPy step, bit-level on a fixed hash seed, and its cost (amplified method,
bench-test-authoring9). Then the scatter: one scratch scene in thef_causticstyle, cost per frame at 1080p against particle count. The scatter needs a vertex program underpackage/code/and a Max relaunch to add that folder (perf_caustic.md, Notes). Readjit-gen-codeboxandmaxpat-json-authoringfirst. - Tier 3, live look: Matt's. Does sand collect on the lines as a Chladni plate does, and is it performable (do you drive it live with the figure's modes, and does it keep up)?
Stop rules (the numbers are my picks, not derived)
- If a texture advection is nearly as good, stop. If
f_vf_advect-style density advection reaches about 0.8 of the particle model's nodal-line contrast at the same frame count in tier 1, build the cheaper thing (a Chladni sand mode or a recipe withf_vf_advect), not a particle layer. - If no sand velocity can be made, say so and stop. If the existing outlets cannot give a node-seeking velocity (question 1) and Matt does not want a new outlet on
f_chladni, the Chladni case is closed; keep only the tracer case if it earns its place. - Cost. On either path, the position update plus the draw plus the composite must fit about 4 ms per frame at 1080p for a figure that reads as sand (the budget
f_rd_stepper_spikeused for a solver).f_causticalone is about 21 to 23 ms at its fixed setting, so a scatter at that scale is already past the budget: the particle count and draw cost are the whole spike. If the cheapest count that reads as sand costs more, park the layer and say so in.specify/gates.md. - Determinism. If the position update cannot match the NumPy step bit for bit on a fixed seed (hash tolerance aside), tier 2 stops there: a non-repeatable state cannot be benched.
- A one-field result is not enough to build. If only Chladni converges and the tracer case shows nothing, the module is a Chladni sand effect and should be named and scoped as one (gate D2).
Phase 0 gates (Matt decides; Claude's lean in each)
- D1 Name. Lean
f_particlesas a working name;f_sandif it becomes Chladni-only. Matt picks before any build. - D2 Scope. One module that can do Chladni sand and tracers in any vecfield, or a Chladni-only effect. Lean the general one (a vecfield in, a density out), unless stop rule 5 fires.
- D3 The sand velocity. Use the existing
f_chladnioutlets if question 1 says they suffice; otherwise a new outlet onf_chladni(a signed node-seeking field), or the particle layer readstotalitself. Lean: a newf_chladnioutlet only after tier 1 says the sign is missing. Matt decides, since it changes a shipped module. - D4 Particle count. Lean a fixed N×N state with N a build-time constant (256 or 512 first), no live count dial (a count dial is a restart and a state resize, which Vsynth bpatchers handle poorly).
- D5 Path and draw. Lean to measure both before choosing: the GPU state with the
f_causticscatter (it exists and is measured) and the CPU Jitter chain (jit.p.shiva,jit.repos,jit.op,jit.gl.mesh; extant objects, nothing measured). A gather-only draw (each pixel searches nearby particles) has no precedent here. - D6 Tiers. Lean tier 1 now; tier 2 only if stop rules 1 to 3 pass; tier 3 is Matt's.
- D7 Stop rules. Lean as written; Matt may move the 0.8 and 4 ms picks.
Result, NumPy tier (run 2026-11-29; Claude, offline, NumPy, no Max, no bench, no API calls)
What ran. tests/records/spike_particles.py (uv run --no-project --with numpy python3 tests/records/spike_particles.py, 121 s; output and summary.json in scratch/experiments/particles_spike/, gitignored; the run text was in the session scratchpad). Field: the f_chladni mirror's mode-A total T at 256x256 (tests/modules/chladni/chladni_mirror.py, modal_A), notes 40, 60 and 80, dish radius 1, no reflection. Particles seeded uniformly in the annulus 0.06 < r < 0.38 (rim mask and the center singularity left out), 262,144 of them unless stated, step 0.4 texel per frame, periodic positions, bilinear field reads. "On the line" = within 1.5 texels of the sign changes of T; the area share of that band is 6 to 8% (the uniform start). Nothing here is a Max or GPU measurement.
Q1 and Q2: the sand velocity and convergence (share of particles on the line, frame 100 / 200 / 400)
| Velocity | note 40 | note 60 | note 80 |
|---|---|---|---|
| TRUE (descend ` | T | `) | 0.96 / 1.00 / 1.00 |
SIGNED_OUT (out2 direction times the true sign of T) | same as TRUE | 0.91 / 1.00 / 1.00 | same as TRUE |
SIGNLESS (out2 direction, no sign) | 0.09 / 0.33 / 0.42 | 0.08 / 0.35 / 0.94 | 0.03 / 0.14 / 0.47 |
OUT3GRAD (the layer takes a gradient of out3 = `clamp( | T | ·gain)`, gain 1) | same as TRUE |
- Convergence works: with a node-seeking velocity, 96 to 100% of the particles reach the lines by frame 100 to 200 at all three notes.
out2alone does not do it. Its direction needs the sign ofT, which no outlet carries (out1loses it through the square root,out3is|T|). Without the sign the sand is slow and unreliable (3 to 9% at frame 100).- The existing outlets can still do it, by a gradient taken from
out3: the layer reads three taps ofout3(a gather) and descends it. That matched the true velocity at notes 40 and 80 and reached 0.88 at note 60 (cause not examined). It needsgainlow enough thatout3does not clamp; at a highgainthe clamp would flatten it away from the lines (inferred, not run). So a newf_chladnioutlet is not needed to start; one that carries the sign would be cleaner (0.98 to 1.00).
Q3: the texture baseline (stop rule 1)
I advected a density-like texture by semi-Lagrangian backward sampling, as an f_vf_advect-style loop does. The result is not a clean comparison: the texture's mass collapsed to 0, 8 or 3,925 of 29,000 (the TRUE velocity at notes 40, 60, 80) and grew to 51,364 once, so "share near the line" is not meaningful. Cause, inferred: backward sampling of a texture that is zero outside the annulus pulls zeros inward, and a gathered scalar is not conserved. The cleaner statement is analytic (inferred): advecting a UNIFORM texture value by any field leaves it uniform, so a gather-based advection cannot make sand collect; the particles accumulate because they carry mass. A mass-conserving texture transport (scatter) was not run; it would be the same transport as the particles without identities.
Q4: count (note 60, TRUE velocity, frame 400)
| Particles | on the line | per band texel | Poisson noise 1/sqrt(n) | most in one texel |
|---|---|---|---|---|
| 65,536 | 0.98 | 31 | 0.18 | 2,394 |
| 262,144 | 0.98 | 126 | 0.09 | 9,831 |
| 1,048,576 | 0.98 | 502 | 0.045 | 38,330 |
The convergence does not depend on the count; only the smoothness of the drawn density does. Whether 0.09 reads as smooth sand is a tier 3 question. The pile-up is extreme: thousands of particles per texel on the lines, so an additive float32 capture saturates and the composite needs a tone curve (as f_caustic's exposure does).
Q5: respawn (note 60, 262,144 particles, frame 400)
| Respawn per frame | on the line | most in one texel |
|---|---|---|
| 0 | 0.98 | 9,831 |
| 1% | 0.67 | 3,574 |
| 5% | 0.28 | 549 |
Respawn keeps the picture alive and costs sharpness: 1% of the particles re-injected per frame holds about two thirds on the line, 5% about a quarter. So a respawn control is a liveliness-against-sharpness dial; a plate whose mode changes needs no respawn because the sand moves anyway (inferred).
Q6: a second field (the tracer case)
A steady divergence-free cellular flow (peak 1.2 texels per frame) carrying 16-texel stripes: the stripe contrast (standard deviation of the 0/1 label) stays at 0.495, 0.488, 0.480, 0.472 for the particles at frames 0, 25, 100, 200, and falls 0.500, 0.433, 0.323, 0.239 for the same stripes carried as a texture. So the tracers keep structure that a texture advection smears. That is the case for a particle layer beyond Chladni sand.
Q7: determinism
A float32 fract(sin(i·12.9898)·43758.5453) against float64 over 262,144 indices: 99.8% differ by more than 1e-3 (maximum 0.5). The shader's float32 hash will not reproduce a NumPy float64 reference. Consequence: seed from an UPLOADED seed texture (or compare against a float32 mirror with a stated tolerance), not an in-shader hash, so a bench can be repeatable. A GPU sin may also differ from NumPy's float32 sin (the jit-gen-codebox skill records this for huge-argument hashes; not tried here).
Q8: which path
Not answerable offline. Needs Max timings of the CPU Jitter chain and of the GPU state plus scatter at one count.
Where the stop rules stand
- Texture advection nearly as good (about 0.8 of the particle contrast): NOT triggered. The measured baseline was invalid (mass collapse), but the analytic argument (a gathered scalar is not conserved; a uniform fill stays uniform) and the tracer stripes (0.24 against 0.47 at frame 200) both favor the particles. A conservative texture transport was not tested.
- No sand velocity from the existing outlets: NOT triggered. A gradient of
out3reaches 0.88 to 1.00;out2alone does not. A sign-carryingf_chladnioutlet would reach 0.98 to 1.00 (D3, Matt's call). - Cost: not measured (tier 2 only).
- Determinism: a constraint, not a stop. Seed from a texture; the in-shader hash is not matchable to NumPy.
- One field only: NOT triggered. The tracer case shows an advantage too.
Recommendation (inferred, Matt decides): proceed to tier 2, starting with the cost question, because everything the NumPy tier can answer is answered favorably and the stop rule that decides the module is rule 3 (ms per frame), which only Max can measure. Suggested first tier 2 run: the position-update stage (a pix pass over an N×N state texture, bit-checked against NumPy on a texture seed), then the CPU Jitter chain timing at 65k and 262k points; the scatter (a vertex program, f_caustic-style) last, because it is the expensive and riskiest part.
Tier 2 plan (written 2026-11-29, Claude, offline; nothing run; every run needs Matt's go)
Goal: answer stop rule 3 (ms per frame at 1080p against about 4 ms) for each path, and prove the pieces match the NumPy model. Order: cheapest and most informative first; stop as soon as a stop rule decides.
Precedents read for this plan: src/f_caustic/scatter_scene.py (a standalone scene generated by a script: a points jit.gl.mesh on a plane-gridshape matrix, additive blend into a jit.gl.node float32 capture, one control entry), package/code/f_caustic_sheets.jxs (the vertex program reads tex1 at the lattice point u, offsets it, writes the position), tests/modules/caustic/bench_caustic_sheets.py (its scatter parity and frame-cost tests; the header says it needs tests/bench/bench_module.maxpat open and Vsynth performance patches closed), tests/lib/benchclient.py (run_pass, run_temporal with an initial state and one feedback texture, measure). Not read in detail: caustic_runner.py, scatter_mirror.py and scatter_truth.py (the scatter parity method and its tolerance), and how the bench times a scene's frame cost; read them first in T2.2.
What the scatter reuse means (inferred, not tried): f_caustic's vertex program reads a field at the lattice point u and moves the point. A particle vertex program reads the POSITION STATE at u (the particle's index) and places the point there, so the scene, the capture and the composite are f_caustic's with a different .jxs.
T2.0 Preconditions
- Matt's go for each run below (CLAUDE.md; announce, Max foreground,
-q, no polling). State the run count, the job count and a rough time before each; the bench steals focus. - Read first:
jit-gen-codebox(especiallysample()at jumpy coordinates),bench-test-authoring(pin every Param in every job; chain single-step temporal jobs; 8 chain slots; amplified cost),maxpat-json-authoringif a scene is generated. - A seed texture, not an in-shader hash (Q7): the initial positions come from an uploaded float32 texture made by the NumPy script (deterministic).
T2.1 The position-update stage (a pix pass; the cheap half)
- Files:
tests/records/codebox_particles_spike.gen(scratch, not a module),tests/records/particles_mirror.py(float32 one-step mirror),tests/records/bench_particles_spike.py; register intests/lib/benchdeps.py. - Stage: inputs = the state texture (R, G = position in [0,1), periodic) and the node-seeking velocity field; output = the new state. The field must be read by four
nearest()taps blended by hand, notsample(): the position is exactly the kind of jumpy, data-dependent coordinate wheresample()reads nearest and would quantize the push to texel steps (jit-gen-codeboxrule 9; inferred to matter here, not measured). - Velocity input, per the NumPy result: either the layer's own central difference of
out3(three taps; Matt's D3 may add a sign outlet later), or a precomputed velocity texture for the first bench so the mirror isolates the update from the field. - Rows: (1) one step equals the float32 mirror within about 1e-6 of a texel (tolerance to be set by the mechanism, not copied); (2) 50 chained single-step jobs against 50 mirror steps, with the drift recorded; (3) wrap at the border; (4) a zero field leaves the state exactly unchanged; (5) cost per frame at N = 256, 512, 1024 (65k, 262k, 1M particles) by the amplified repeat-loop method (the update body in a
repsloop, coordinates shifted per repeat), reported as a slope, not an upper bound. - Pass: parity rows within tolerance; cost recorded. Expected small (a handful of taps per texel on an N×N pass; inferred, which is why it goes first and why a surprise would matter).
T2.1 result (Max bench, run 2026-11-29; Claude, on Matt's go, Max foreground; tests/logs/20261129-172625-bench.log, commit c09231a)
7 of 8 rows passed; the failing row is a too-strict tolerance, not a wrong pass. Read from the log:
- Compiles and draws (the scratch codebox
tests/records/codebox_particles_spike.gen). - One step against the float32 mirror: max circular position error 5.96e-8 (one float32 ulp; tolerance 1e-6). 50 chained steps (state fed back into inlet 2): 5.96e-8, 1.19e-7, 4.17e-7 at steps 1, 10, 50 (tolerance 2e-5): the drift is small and grows slowly.
- Border wrap against the analytic value 1.3e-8; zero field leaves the state exactly unchanged (0); constant velocity against the analytic v/fw: 5.96e-8 (x), 2.9e-8 (y). So the nearest-tap push is exact; no texel quantization (the four hand-blended taps work).
- Amplified at reps 1 against the shipped codebox: max difference 5.96e-8, one float32 ulp, so the strict-zero check failed. I widened its tolerance to 1.2e-7 AFTER seeing this (comment in the bench); the changed row has not been re-run. The loop and the straight-line code differ by one ulp (cause not isolated; the compiler's arithmetic ordering is the likeliest, inferred). It does not affect the cost slopes.
- Cost of the update pass, by the amplified method (ms per pass at 1 rep, from the slope against reps; every point GPU bound; scales linearly with reps and with the particle count): 65,536 particles (256x256) 0.0110 ms; 262,144 (512x512) 0.0421 ms; 1,048,576 (1024x1024) 0.1575 ms.
- This also confirms the bench feeds the same two inputs to every chained slot (cost scales cleanly with reps and N; before this it was an unconfirmed assumption).
What it means for stop rule 3 (about 4 ms at 1080p): the position update is negligible, 0.04 ms at 262k and 0.16 ms at a million particles. The whole budget question is now the scatter (T2.2). Caveat, inferred: the amplified repeats shift the taps by 0 to 2 texels, so cache reuse may make the slope slightly low; in use the particles on converged lines read near-coherent field texels, which should also cache well, but that was not measured.
T2.2 The scatter (detailed plan written 2026-11-29, Claude, offline; nothing run)
Read for this plan (2026-11-29): package/code/f_caustic_sheets.jxs (whole shader), src/f_caustic/scatter_scene.py (scene(), standalone(), the Graph helper), tests/modules/caustic/caustic_runner.py (run, period_ms, refresh_file_db) and the test names and tolerances of tests/modules/caustic/bench_caustic_sheets.py (scale 0 identity 1e-3, energy 1e-3, N points on one pixel 1e-3, truth agreement, orientation, FRAME_BUDGET_MULT 1.4). Not read: scatter_mirror.py's ref_scatter body, modulebench.make_wrapper, scatter_truth.py.
Three facts that shape the plan
- This is a different harness from T2.1. The scatter lives in a Jitter GL scene (a
jit.gl.nodecapture, a pointsjit.gl.mesh), which the codebox bench cannot host. Thef_causticscatter bench uses the MODULE bench: Max withtests/bench/bench_module.maxpatopen (notbench.maxpat) and every Vsynth performance patch closed (header ofbench_caustic_sheets.py,caustic_runner.py). - That bench cannot see a cost below its own pacing.
caustic_runner.period_msmeasures the frame period against a 60 fps cap (CAP_MS= 16.7 ms) and its docstring says a value at or under the cap "only means within the frame budget". Our budget is about 4 ms, far below the cap, so the f_caustic way of timing would show "fits" for anything. The amplified method is needed here too: draw the same point set K times per frame (K meshes, enabled by a control tokenk, withweightdivided by K so total energy is unchanged) and take the SLOPE of the frame period against K, using only K large enough that the frame is over the cap. - The scatter differs from
f_caustic's in one place only (inferred): its vertex program reads a field at the lattice pointuand displaces it; ours reads the particle STATE at the particle's index and places the point there. The capture, blend, tent fragment program and composite are the same.
Files (all new, scratch; nothing touches f_caustic)
package/code/f_particles_points.jxs: a vertex program withtex0= the state (R, G = position in [0,1)), paramsweight,res,n. A planejit.gl.gridshapeof dim n x n has vertices atu = i/(n-1), not at texel centers, so the shader recovers the index (ui = floor(u*(n-1) + 0.5)) and reads the state at the exact texel center(ui + 0.5)/n; reading a texel center through linear filtering returns that texel exactly (the interpolation weight is 0) (inferred, not tried). Position goes torespixels, snapped to the nearest pixel corner, with the unsnapped position passed on for the fragment's tent weights: exactlyf_caustic's lines, noscaleoredge(positions are already periodic). New.jxsin the existingpackage/code/folder is found aftercaustic_runner.refresh_file_db()without a relaunch (its docstring: only a NEW folder needs one).tests/records/particles_scene.py: generatestests/bench/particles_points_standalone.maxpatby script (derived, never hand-typed), importingGraphfromsrc/f_caustic/scatter_scene.pyor copying its small pattern: onejit.gl.slab @type float32 @rectangle 0adapter for the state (asf_caustic's texture adapters), one gridshape matrix, K meshes (K up to 16)@draw_mode points @blend_enable 1 @blend_mode 1 1 @point_size 2on thejit.gl.nodefloat32 capture, a control entryroute weight r n k.tests/records/particles_splat_mirror.py: a float32 NumPy splat of a position list into an r x r capture with tent weights from the unsnapped position (the same math the fragment program does; thescatter_mirror.ref_scattermethod without the field).tests/records/bench_particles_scatter.py: the module-bench rows below; registered intests/lib/benchdeps.py.- Seed states from the NumPy tier: a deterministic generator (import
spike_particles.py'sfield,velocity_fields,run_particles) writes float32 N x N state textures for note 60: UNIFORM (frame 0), CONVERGED at frame 100 and at frame 400, at N = 256 and 512 (65,536 and 262,144 particles), and N = 1024 for one row.
Rows (module bench; each job pins every parameter, bench-test-authoring 2)
- Loads and draws: the shader compiles, the capture is non-zero.
- Orientation probe: one particle at (0.25, 0.75) lands in which capture pixel; decides the flips the mirror needs, as
f_caustic's orientation test did (its comment: inputs reach the GPU as matrices; up_flip and out_flip found in its spike S0b). - Energy: capture sum = N x weight within 1e-3 (the
f_causticprecedent), at N = 64, 256 and 512 (also proves every index is drawn exactly once). - N particles on one pixel: total and share outside a 4 x 4 block within 1e-3 (the
f_causticprecedent); this is the pile-up extreme. - Splat parity: the capture against
particles_splat_mirroron the UNIFORM and CONVERGED states; tolerance from the mechanism (additive blend order in float32), starting from thef_caustic1e-3 and recording the error; the first run decides if it is tight. - Tier 1 at the draw level: the share of the capture's mass within 1.5 texels of the nodal lines on the converged state against the NumPy value (0.98 at frame 400): ties the NumPy convergence to what the GPU draws.
- Cost by copies (the amplified method): for each of UNIFORM, CONVERGED-100, CONVERGED-400 at N = 256 and 512 (and N = 1024 on uniform), frame period at K = 4, 8, 16 (and 32 if needed) via
period_ms-style two-job slope, a capture of 1024 x 1024 (asf_caustic's) and one row at 2048 x 2048 for the 1080p case; cost per scatter = slope of period against K over the points above the 16.7 ms cap; a K = 0 floor row shows the pacing. Report ms per scatter, per particle count and per distribution, so vertex work and blend contention separate (f_caustic.md: contention dominates; the converged state piles thousands of particles per pixel, which is the worst case). - The composite (tone curve): the pile-up means a tonemap is needed (tier 1); its cost as a small pix pass by the T2.1 amplified method, in the codebox bench, at the end.
Pass or stop: the answer is a table, per N and distribution, of ms per scatter against the 4 ms budget, together with T2.1's update (0.04 ms at 262k) and the composite. Stop rule 3 decides: if the scatter alone is over about 4 ms at the smallest N that reads as sand (tier 1: N = 65,536 gave Poisson noise 0.18, 262,144 gave 0.09), the GPU path is parked and T2.3's CPU chain becomes the only candidate. A guess from f_caustic's numbers, inferred, not measured: 262k points is about 16 times fewer than its 4.2M points at 21 to 23 ms, so about 1.4 ms if cost were linear in points, higher if the converged pile-up dominates.
Run size and preconditions (estimates, not timed). About 8 short parity jobs plus about 16 to 24 period_ms measurements (two jobs each, tens of frames at 10 to 25 ms plus a lattice build per job), so roughly 6 to 12 minutes. Needs bench_module.maxpat open, Vsynth performance patches closed, Max foreground, Matt's go. The bench steals focus, so he must step away.
Risks: vertex texture fetch of a float32 state through jit.gl.slab (the f_caustic scene does the same for its field; unproven for a state texture); the plane gridshape's vertex positions (handled by the index recovery, checked by the energy row); one 1M-vertex lattice is about 48 MB at 12 float32 planes per f_caustic.md (inferred scale from its 200 MB for 4.2M points), fine; the K-copy scene must not change the capture's total (weight divided by K, checked by the energy row at K = 4).
Decisions this plan adds (Matt; Claude's lean in each)
- D11 Generate the scene by script (like
f_caustic), undertests/bench/, not hand-typed. Lean yes. - D12 Capture size. Lean 1024 x 1024 for the main rows (what
f_causticuses) and one 2048 x 2048 row for a 1080p-class capture. - D13 Distributions. Lean all three (uniform and the converged states at frames 100 and 400), since the pile-up drives cost.
- D14 Open
bench_module.maxpat. This run needs the module bench instead ofbench.maxpat; Matt opens it.
T2.2 result (module bench, run 2026-11-29; Claude, on Matt's go, bench_module.maxpat open, Max foreground; tests/logs/20261129-173908-bench.log, commit 7c03661)
7 of 7 tests passed. Correctness is clean; cost is resolved for the converged (worst) cases and only bounded for the uniform ones.
Correctness (all within tolerance, errors far below the 1e-3 borrowed from f_caustic)
- The shader loads and draws; the capture is 1024x1024 with sum 65,536 for 65,536 particles. Orientation: the matrix is flipped vertically against the framebuffer, and a particle at (0.25, 0.75) lands one pixel from the predicted place.
- Energy: |capture sum minus N| / N is 2e-10 at K = 1 and 1.1e-10 at K = 4 (weight divided by K): every index is drawn once and the copies conserve energy. N on one pixel: exact (peak pixel 1024, share outside the 4x4 block 0).
- Parity with the NumPy splat mirror: mean relative error 8e-9 (65k uniform), 2e-8 (262k uniform), 4e-6 (65k converged) and 1.9e-5 (262k converged); the converged errors come from additive blend order in float32 where the peak pixel holds 1,095 to 4,498 particles (inferred from the size and where it appears, not isolated).
- Tier 1 at the draw level: 0.975 of the capture's mass lies within 1.5 texels of the nodal lines against 0.980 from the NumPy positions (difference 0.005). The GPU scatter draws what the NumPy model predicted.
Cost per scatter, by copies (ms per scatter = the frame period at the largest K over K when that period is above the 16.7 ms pacing, i.e. GPU bound, a slight overestimate; an upper bound only when the period stayed at the cap; capture 1024 unless stated). The module bench's pacing hides everything below 16.7 ms, so only one point per row rose above the cap and no slope could be fitted.
| Particles | uniform start | converged, 100 steps | converged, 400 steps |
|---|---|---|---|
| 65,536 | at most 0.26 (period 16.4 at K = 64, not GPU bound) | 0.29 (18.8 ms at K = 64, barely above the cap) | 0.42 (26.9 ms at K = 64) |
| 262,144 | at most 1.03 (16.4 at K = 16) | 1.32 (21.1 at K = 16) | 1.71 (27.3 at K = 16) |
| 1,048,576 | at most 4.19 (16.8 at K = 4) | not run | not run |
| 262,144, capture 2048 | at most 1.03 (16.4 at K = 16) |
- The pile-up does cost: at 262k particles the converged state costs at least 1.3 to 1.7 times the uniform bound, as
f_caustic.mdsays (blend contention). The worst case is the one resolved, which is the useful way round. - Roughly linear in count at fixed distribution: 0.42 ms at 65k and 1.71 ms at 262k for converged-400 (4.1 times the cost for 4 times the particles).
- Capture size: 2048 gave the same upper bound as 1024 at 262k uniform (not resolved, so no claim beyond "no sign it is dearer").
- Against
f_caustic: about 5 ms per million points at the uniform bound agrees with its 21 to 23 ms for 4.2 million points. - Not measured: 1M particles when converged (the state generator only made the uniform 1M start; the 1M converged cost is probably several ms (inferred from the converged to uniform ratio at 262k)), the composite (tone curve) pass, and the whole loop (update, scatter, composite) as one scene.
T2.3 The CPU Jitter chain (the comparison)
- Contents: a
jit.matrixof particles (N x 1, float32, planes for x, y),jit.reposto gather the field at the particle positions (field = a 256² matrix, standing in for the asyncread readback),jit.opto push and wrap, optionallyjit.p.shivaandjit.p.boundsfor spawn and limits, andjit.gl.meshto draw. - Open question (needs Matt): the bench harness times GPU pix chains by frame rate. It has no way to time a CPU matrix chain that I know of (not checked in
benchclient.pybeyondmeasure). Options: a scratch patch generated by script (asscatter_scene.py --standalonedoes) with acpuclockortimeraround the CPU part, read by Matt in the Max console or a number box; or extend the bench job type. Matt's call on which; the first is cheaper and keeps the harness unchanged. - Rows: ms per frame of the CPU part at N = 65k and 262k, the readback of a 256² vecfield per frame (asyncread, already exercised by
f_cores), and the mesh draw cost at the same counts. - Pass: a number per row; the comparison with T2.1 plus T2.2 is the whole answer to question 8.
T2.4 Decision record
- A table in this note: per path, ms per frame at 1080p for 65k and 262k particles, against the 4 ms budget, and what each reads like (tier 3). Then Matt decides: build the GPU layer, build the CPU layer, a Chladni-only effect from the cheaper one, or park (
P-cores-particles).
Budget and ordering
Rough run sizes (inferred, not timed): T2.1 about 12 bench jobs for parity plus about 10 measure jobs for the amplified costs, a few minutes; T2.2 about 10 jobs plus a long scene load, several minutes; T2.3 manual in Max. Each is a separate go. T2.1 is worth doing first even if T2.2 is likely to fail: it is cheap, it settles the nearest-tap push and the seed-texture design, and it is reusable by either path.
Decisions this plan adds (Matt; Claude's lean in each)
- D8 Start with T2.1. Lean yes (cheap, informative, reusable).
- D9 How to time the CPU chain (T2.3). Lean a script-generated standalone scratch patch with a timer, not a change to the bench harness.
- D10 First field for the bench. Lean the note-60 Chladni field (the tier 1 worst case for the
out3gradient) with a precomputed velocity texture for T2.1 so the mirror isolates the update from the field read.
Decisions
Matt, 2026-11-29 (chat: "Accept all"): D1 to D7 as leaned. Working name f_particles (f_sand if Chladni-only); one general module; a new f_chladni outlet only after tier 1 confirms the sign is missing; fixed N×N state; measure both the GPU scatter and the CPU Jitter chain before choosing a path; tier 1 NumPy next, tier 2 only if stop rules 1 to 3 pass; stop-rule numbers as written.
Gate
P-cores-particles in .specify/gates.md is the parent row: reopened by Matt 2026-11-29 ("Item 5, write the spec"). After tier 1 the row either becomes a module spec (a new gates row for D1 to D3) or closes on stop rule 1, 2 or 3.
Related
cores_next_steps.md, field_object_bridge.md, f_peaks_spike.md, f_rd_stepper_spike.md, docs/f-reference/f_caustic.md, f_vf_advect.md, f_chladni.md, docs/max-reference/temporal_synthesis_architecture.md.