f_caustic
Type: Processor (f_vecfield consumer) Status: Working. One path: a GPU forward scatter ("sheets"). The module originally had a second mode (a backward-gather "soft" path) and a detail quality ladder; both were removed 2026-10-10 -- Matt found no reason to run anything but the heaviest detail step, so the choice and the ladder were both dead weight. See History below and the decision note in .specify/f_caustic_scatter/tasks.md.
What it does
An optical caustic processor. Takes a light-source image and a vecfield (the refracting medium) and redistributes the source's brightness according to the field: a lattice of points ("glass samples") is displaced through the field and each deposits a small bilinear splat of the source's color, additively, into a float32 capture. Splat density is illuminance, so the overlapping translucent folded sheets that give the module its name appear at larger scale. Two outlets: the composite (source + caustic, additive) and the isolated caustic layer.
Structurally requires a coherent vecfield -- patching a non-field texture into the vecfield inlet will produce output but not meaningful caustic structure. The vecfield inlet has no vs_inState fallback: unconnected = silent passthrough on the composite outlet and black on the caustic-layer outlet, not a misleading default caustic.
Compatible with any f_vf_ producer -- pairs naturally with f_vf_vortex (sink topology produces a bright ring at the convergence zone) and f_vf_fieldmap (noise-derived caustic bands along ridge lines). Matt pairs it with f_vf_prism downstream (caustic -> prism) for chromatic dispersion -- see Parameters, expo/history below for why that replaced a built-in color control rather than the module growing one.
Signal Flow
The module has two inlets and two outlets, both going through the one pix stage.
inlet 0 (texture + control) → routepass → route <params> → live.dials / menu → prepend param <name> → caustic
└ vs_inState ─┬→ caustic (light source, in1)
└→ scene source slab (jit.gl.slab, float32)
inlet 1 (f_vecfield, texture) — no vs_inState ─┬→ caustic (field, in3)
└→ scene field slab (jit.gl.slab, float32)
the scene (a jit.gl.node capture @type float32 holding a points jit.gl.mesh drawn with
package/code/f_caustic_sheets.jxs) → caustic in2 = the float32 illuminance capture
caustic (codebox_sheets.gen) out1 → outlet 0 (composite)
caustic (codebox_sheets.gen) out2 → outlet 1 (isolated caustic layer)causticis the chain's only (and so primary) pix stage. Bypass is aParam bypass_gatedeclared directly incodebox_sheets.gen, mixing both outlets to the source last ("every outlet mixes to its passthrough").- The scene is raw boxes generated by
src/f_caustic/scatter_scene.pyintosrc/f_caustic/raw_ui.json; regenerate it withpython3 src/f_caustic/scatter_scene.pybefore a build. It is always enabled and its lattice is built once, at patcher load, by a fixed message (there is no live rebuild any more).
Parameters
| Param | Range | Default | Description |
|---|---|---|---|
mix_pct | 0–100% | 0.0 | Wet/dry crossfade toward the fully-composited (source+caustic) state — composited = mix(source_pass, composite, mix_pct). Rendered as live.numbox; the internal Param is named mix_pct to avoid colliding with the codebox's mix() operator. |
gain | 0–2.0 | 0.5 | Caustic brightness. The codebox applies an internal constant (k_sheets = 2.0 in codebox_sheets.gen) calibrated so the default 0.5 reads about like the original look-patch prototype. |
scale | 0–1.0 | 0.3 | The propagation distance of the scatter, in UV per unit field; sheets fold over as it grows. pix_wire: False in definition.py — the dial feeds the raw scene's control entry (scatter_scene.py), not a Param on codebox_sheets.gen. |
expo | 0.3–1.5 | 0.7 | Tone-curve exponent for the caustic layer's exposure curve, (v / (1 + v)) ^ expo — lower compresses highlights harder, higher keeps more contrast. Was a fixed internal constant (the look-patch default) until 2026-10-10, now exposed. |
edge | Off / Wrap / Mirror / Clamp | Off | Where a ray that lands outside the frame goes. Off: it is clipped away with its light (the original behavior; a one-way field starves the opposite side). Wrap: it re-enters on the opposite side (fract), so nothing is lost and no band is starved; the natural choice for a periodic field such as f_vf_fluid's. Mirror: it reflects at the border (doubles the density near it). Clamp: it piles onto the border pixels, clamped half a pixel inside so the whole splat stays in the frame. Like scale, a shader uniform on the scene's control entry (pix_wire: False), tapped at the menu's outlet. Added 2026-10-17. |
bypass | 0/1 | 0 | Passthrough on both outlets (both give the source) — implemented as a Param (bypass_gate) in codebox_sheets.gen itself, not the native @bypass. |
Prefix: caustic — Object name: #0_caustic_sheets (instance-scoped; no fixed name any more — that convention belonged to the old soft stage, kept only so it stayed bit-identical across the sheets-mode rollout).
Algorithm
// vertex program (package/code/f_caustic_sheets.jxs, GLSL 1.20), one lattice point per glass sample u:
F = (texture2D(field, u).xy - 0.5) * 2; F.y *= -1 // the flip is baked: upload and capture each flip vertically
x = u + scale * F // where the ray lands
x = edge_remap(x, edge) // 0 off (unchanged: outside rays are clipped), 1 fract(x), 2 1 - |1 - mod(x, 2)|, 3 clamp(x, 0.5/res, 1 - 0.5/res)
col = texture2D(source, u) * weight // one bilinear source read; weight = (capture / n)^2
position snapped to the nearest pixel corner, drawn with point_size 2
// fragment: a bilinear (tent) weight from the UNsnapped position; additive blending into the float32 capture
// composite (codebox_sheets.gen): the capture is upscaled bilinearly to the source's size
exposed = (v / (1 + v)) ^ expo with v = capture * gain * 2.0, zeroed when the field inlet reads as unconnected
wet = mix(source, clamp(source + exposed, 0, 1), mix_pct / 100)
composite = mix(wet, source, bypass_gate); layer = mix(clamp(exposed, 0, 1), source, bypass_gate)A size-2 point on a pixel corner covers exactly the four pixel centers the tent can reach, so the result is bit-identical to a size-3 point at about half the fragments. A regular lattice is used: jitter trades moiré for grain and lowers every quality score. At 1 point per capture pixel a regular lattice shows a faint cross-hatch moiré; the module's fixed setting (2 points per pixel at 1024², i.e. 4 per capture pixel counting both axes — see FIXED_DETAIL in scatter_scene.py) is clean.
Notes
- Where the scene lives: the shader is
package/code/f_caustic_sheets.jxs(Vsynth keeps its own in its packagecode/folder). Max adds a new package folder to its search path only at launch, so after the first checkout containingpackage/code/, relaunch Max once. (Users who install the package get the folder from the start.) - Latency: the scatter is exactly one frame behind an upstream pix chain (measured in the spike, 8 of 8 captures). That is accepted.
- Memory: the lattice is 48 bytes per vertex (the matrix is 12 planes of float32): about 200 MB, fixed. This cost is now unconditional — before 2026-10-10 it only existed once the module was switched into sheets mode; with soft mode gone, every
f_causticinstance carries it. - Cost is driven by points per pixel (blend contention), not by the point count; vertex work is about 1 ms per million points or less. On an M3 Max the fixed setting alone measures about 21-23 ms per frame, roughly 1.3x the 16.7 ms 60 fps budget (the tier-2 tests use a widened FRAME_BUDGET_MULT for it); timings from the spike varied up to 2x between runs, and no M1 number exists. There is no lighter setting to fall back to any more — the old
detailladder's "step it down if a machine struggles" escape hatch went with the menu. - Two instances: every stage is
#0-scoped now (the old fixed-name soft stage is gone). Twof_causticinstances in one patch are not yet checked live. - Unconnected inputs: an unconnected vecfield inlet reads a constant (0, 0, 0, 1) (black with alpha 1), which would decode to a strong field. The composite stage treats a field that is exactly 0 in R and G at four fixed points as absent, so the module stays silent.
- Tests: stale as of this doc's rewrite —
tests/modules/caustic/bench_caustic_sheets.py's soft-identity check andtests/baselines/f_caustic_soft.npztest a branch that no longer exists, andtests/modules/caustic/test_scatter_scene.pystill references ids (SOFT,SEL_COMP,SEL_LAYER,MENU_MODE,MENU_DETAIL) that aren't in the build any more. Not yet reworked — see.specify/f_caustic_scatter/tasks.md's 2026-10-10 entry.
References
Derived in development. No code, formulation or constant was taken from another implementation.
- Sheets mode (forward scatter of a lattice of glass samples through the field, with splat density read as illuminance; a corner-snapped bilinear splat; a fixed-capture quality step): an original construction, developed and measured in the 2026-10-06 and 2026-10-07 spikes (
tests/records/spike_scatter.py,ideas/optics_map.md). Measured against photon-counting ground truth at 3.5 times the first-fold distance: r above 0.99 (0.9997 at the fixeddetailstep) (spec:.specify/f_caustic_scatter/spec.md; evidence:ideas/optics_map.md). The photon-counting ground truth used to test it (tests/modules/caustic/scatter_truth.py) is the plain idea of histogramming where rays land. - Background only (not a source): the forward-scatter-and-count approach is the idea behind photon mapping. Not consulted for the implementation.
- Jensen, H. W. (1996). "Global Illumination Using Photon Maps." Rendering Techniques '96 (Eurographics Workshop on Rendering).
- In-house precedent for the scatter's mechanism: Vsynth's own
vs_xyz_disp/vtfk.jxsdraw points with a vertex-stage texture fetch into ajit.gl.node, the same structure the sheets scene follows; the shader code itself is original.
History
- 2026-10-17:
edgemenu added (Off / Wrap / Mirror / Clamp, default Off = unchanged behavior). Why: with a one-way field (e.g. tensorf_tf_axisflowintof_vf_fluid) a largerscalesent the light out of the frame, losing it on one side and starving the other. The remap is in the vertex shader (package/code/f_caustic_sheets.jxs, uniformedge), driven through the scene's control entry likescale(newedgetoken,prepend param edge; raw layer regenerated,MENU_EDGE = obj-32inscatter_scene.py, guarded by a test). Clamp insets half a pixel: on the border itself half of the tent falls off-frame and it would still lose light. Mirror test:tests/modules/caustic/scatter_mirror.pyedge_remap+ 3 tests (10/10), scene test 5/5; bench 14/14 on 2026-10-17 includingtest_T040_*(edge 1/2/3 match the mirror to 3e-6..1e-5; Off 1.06e-3, the same as the edge-less mirror: a border snapping-vs-clipping gap that predates edge mode); checked live by Matt 2026-10-17 (Edge menu position, Wrap in the tensor chain). A splat straddling the frame edge in Wrap/Mirror still loses its off-frame half (about 0.3% in the tests). - 2026-10-10: soft mode (the 8-tap backward-gather,
codebox_v2.gen, plus the earlier supersededcodebox_v1.gen), themodeanddetailmenus, and the two select stages (codebox_select_comp.gen,codebox_select_layer.gen) all removed — sheets-only now, fixed at the old step-5 detail.softnessandcolor_shift(soft-only) removed with it; Matt is rebuilding that look as af_caustic→f_vf_prismchain instead.expo(the tone-curve exponent) exposed as a new param in the same pass. Full record:.specify/f_caustic_scatter/tasks.md. - 2026-10-07/08: sheets mode built and shipped alongside soft mode as a second, selectable branch. Live-tested by Matt 2026-10-08: read clearly better than soft.
gain/scaleboth gotrange_tiersmenus. - 2026-07-11:
definition.pyhad pointed at a stray earlier single-inlet draft (codebox_v3.gen, since deleted) that never readin2. - 2026-07-12 gain/mix rollout:
strengthrenamedmix_pct(range capped to true 0–100%,live.numbox) andintensityrenamedgain, matching the library-wide convention. @type float32overrides the processor default ofchar— accumulation benefits from float32 headroom.- Divergence sign convention (soft mode, historical): f_vf_vortex sink topology (positive convergence) produced negative divergence at the fixed point, which produced bright bands. No longer applicable with soft mode gone, kept here as a pointer for anyone reading old history.
- See
docs/f-reference/f_vecfield_type.mdfor the f_vecfield type contract.