← f_ notebook · docs/f-reference/f_cores.md

f_cores ​

Name: f_cores, called f_defects until 2026-11-29 (Matt). Physics, and the f_cgl and f_nematic docs, call these points defects; here they are cores, the center of each swirl.

Type: Processor. One texture in (a signed 2-vector field); six outlets: two pictures (marks, signed marks: textures, stateless) and four messages (count: float, went up: bang, went down: bang, rate: float). Eight jit.gl.pix stages, a jit.gl.asyncread and a js. Status: The marks were built 2026-11-28 to 2026-11-29. The count outlets (2 to 5) were merged in on 2026-11-29 (Matt: "merge it"; first built as a separate f_cores_count, since retired). Later the same day (Matt: count and rate floats, pulses bangs) the count outlets became messages read back from the GPU. The GPU sum chain was benched on the GPU before the merge (below); the readback, the js and the outlets were tested offline (the js under node against the mirror), the three benches were re-run live on the merged module 2026-11-29 (Claude, Matt's go: marks 7/7, count 5/5, contract 2/2), and Matt saw the count and the bangs move, with debounce working (live, chat, 2026-11-29); Scale default 64 kept (Matt, live, 2026-11-29); not yet measured: the render-size cost of the count chain**. Marks: Tier 1 mirror 16/16, codebox bench 7/7, module contract bench 2/2 (logs below). Live looks passed (Matt, chat, 2026-11-28 and 2026-11-29: marks sit on the f_cgl cores and come in pairs; out0 into f_vf_stamp "yes"; a derived vecfield "interesting"; "panel checks out"; on f_nematic Plus marks travel farther than Minus marks). No dial, range or default was changed after the looks. Menu category provisional (G-menu).

Reference written 2026-11-29 from src/f_cores/ (definition and three codeboxes), .specify/stable/f_cores/{spec,plan,tasks}.md (decisions D1 to D9, ADR-1 to ADR-6), ideas/f_defects_spike.md and the module's tests.


What it does ​

In plain terms: a pattern that swirls has points it swirls around, and the module puts a dot on each. Examples:

  • A spiral core (f_cgl): the pattern is made of spiral waves, and the core is the center of each spiral, where all the colors meet, like the eye of a whirlpool. In the Phase view it is the point at the middle of each color pinwheel.
  • A nematic defect (f_nematic): the module draws oriented streaks, like combed hair or wood grain. Where the streaks cannot all line up, there are points they bend around. They look like the loops and triangles in a fingerprint: the loop kind (a +1/2 defect, the "comet") is the one that moves; the triangle kind (−1/2) has streaks fanning out three ways and mostly stays put.
  • A zero of a vecfield (any f_vf_* output): a vecfield is an arrow at every pixel, like wind or a current. A zero is a point where the arrow vanishes: the middle of a whirlpool, a spot water flows out of or into, or a saddle where the flow splits.

You do not need to recognize the shapes: the module finds the points, and Plus and Minus say which way each one turns (counterclockwise or clockwise). They always come in pairs.

Technically, it finds the defects of a field and draws them. A defect is a point where a signed 2-vector field has no direction: a spiral core in an f_cgl field, a +1/2 comet or −1/2 three-armed defect in an f_nematic director field, or any zero of a vecfield (a source, sink, center or saddle). Each defect carries a charge, plus or minus, and defects are born and die in plus-and-minus pairs, so the two counts are always equal on a wrapping frame.

  • Inlet 0 is the field: a texture whose R and G are a signed 2-vector, 0.5 + 0.5 * (x, y), zero = 0.5. That is the encoding of f_cgl outlet 1 (A as a vecfield), f_nematic outlet 1 (the packed tensor, whose R, G is already the angle-doubled director) and every f_vecfield. It must be at the render size, which the f_ solver outlets are. Control messages arrive here too.
  • Outlet 0, marks: white soft discs on black (luma), both charges unless Charge says otherwise. Shaped to feed f_vf_stamp as its stamp texture, which is what the looks tried.
  • Outlet 1, signed marks: R = plus marks, G = minus marks, B = 0, A = 1. Not a vecfield.

The module keeps nothing: no feedback, no frame memory, no identity of a defect from one frame to the next. Persistence is downstream (f_vf_advect, f_vf_fluid, f_vf_stamp).

Why a reader and not a threshold: thresholding |A| (or |q|, the order) finds the amplitude dips, and they are not the defects in a busy field. In the NumPy spike, about 1 blob in 5 on f_cgl defect turbulence and about 1 in 4 on active f_nematic carried no defect, and cores merged into shared blobs when dense (ideas/f_defects_spike.md).

The count (outlets 2 to 5). The same detector also feeds a counter, and its results leave as messages, so they can drive a parameter directly or, through an LFO's phase, become a texture: count (a float) is how many cores the field has, divided by Scale; went up and went down (bangs) fire when the count rose or fell since the last frame; rate (a float) is how much the count changed since the last frame, unsmoothed (smooth it downstream). It counts plus and minus together, exactly, at any frame size.


Signal Flow ​

Inlet 0: the field plus control messages. Outlet 0: marks. Outlet 1: signed marks. Outlet 2: count (float, count / Scale). Outlet 3: went up (bang). Outlet 4: went down (bang). Outlet 5: rate (float, rate / Scale). The picture stages run at the render size (render_dim: dim reads 1 in a live pix, so the stages read width and height Params that Vsynth drives).

field -> detect -> hdist -> shade -> outlet 0 (marks), outlet 1 (signed marks)
               detect -> s1 -> s2 -> s3 -> s4 -> pack -> jit.gl.asyncread -> js cores_count.js -> outlets 2 to 5
StageReadsWrites
detectthe fieldR = 1 where the 2 x 2 loop winds +1, G = 1 where it winds −1 (one texel per defect)
hdistthe marksper texel, the smallest horizontal distance to a plus mark and to a minus mark in its row, within the radius (radius + 1 if none)
shadehdistthe exact Euclidean distance (the minimum over the rows within the radius of the root of dx squared plus dy squared), the soft disc, the charge filter, both outlets, bypass
s1 to s4the previous stage (s1: the detector)one codebox, four times: the sum of an 8 by 8 block per output texel, reads past the edge 0; 1920 x 1080 goes to 240 x 135, 30 x 17, 4 x 3, 1 x 1
packs4the count in every color plane of a 1x1 texture (the readback reads plane 1, in either matrix order)
jit.gl.asyncreadpackthe 1x1 texture as a matrix cell, one frame late (interleaved mode)
cores_count.jsthe celloutlet 2: count / Scale; outlets 3 and 4: bangs; outlet 5: rate / Scale; messages full_scale, debounce, param bypass_gate, reset

A small patch of Max objects turns Vsynth's render-size broadcast into each sum stage's size. The js takes the time between frames from the clock. The GPU chain and the readback always run, whether or not the outlets are patched.


Parameters ​

NameTypeRangeDefaultDescription
size (Size)float0 to 31Mark radius as a percent of the frame height. 0 marks single texels. The spread loops are capped at 16 texels each side, so on a tall frame the dial stops growing the marks (about 1.5 percent at 1080p).
soft (Soft)float0 to 10.5Edge softness: the share of the radius used as a smooth falloff. 0 is a hard disc. A numbox.
charge (Charge)menuBoth / Plus / MinusBothWhich defects to mark. Plus is a counterclockwise winding of the field: a +1/2 defect on f_nematic, the self-propelled one.
debounce (Debounce)float dial0 to 10000Minimum time between went-up bangs, and between went-down bangs, in milliseconds. 0 bangs on every change. A change dropped by the debounce is not queued. The count and rate outlets are not debounced.
full_scale (Scale)float numbox1 to 100064The count that reads as 1 on the count and rate outlets. Not clamped: more cores read above 1.
bypasstoggle0/10Every outlet goes to the neutral, black with alpha 1 (not a passthrough of the input). Through bypass_gate in shade (outlets 0 and 1); the float outlets send 0 with no bangs (the js hears the same toggle); the other stages keep running. The native bypass 1 message has no effect.

Internal, never set by hand: width, height (the render size, driven by Vsynth), and in_w, in_h, out_w, out_h on each sum stage.


Algorithm ​

The winding. Around each 2 x 2 loop of texels (this texel, the next column, the next row and column, the next row; wrapping at the edges) the module counts signed crossings of the positive real axis by the vector (x, y). An edge from a to b counts +1 for a counterclockwise crossing (y goes from at most 0 to above 0 with a positive cross product) and −1 for a clockwise one; the sum is the loop's winding. There is no atan2 (f_cgl spec D12 bans it in a codebox). Ties on y = 0 are half-open: any consistent tie rule gives the same result away from exact zero vectors, and dropping ties loses a crossing (the mutation check).

Sign. The loop order is counterclockwise in array coordinates, the order of nematic_mirror.winding(), so a plus mark is the mirror's +1/2 defect. The simulation, not the screen, fixes this: tier 1 requires plus to equal winding() > 0 on every plaquette of a nematic run, and in the mirror the Plus marks move about 2.5 times as fast as the Minus marks (7 to 8 cells per time unit against about 3 at Active 2, tests/records/spike_defects_swim.py), as +1/2 defects do. Matt confirmed live that Plus marks travel farther. The spike's scratch codebox walked the opposite order and its signs were swapped.

The spread. size is a percent of the frame height, size_texels = min(size / 100 * height, 16), radius = ceil of that. hdist and shade are a two-pass separable distance, exact inside the radius, so each mark becomes a round disc: 1 inside size * (1 - soft), 0 at and beyond size, a smoothstep between.

The count. On the GPU, s_n(ox, oy) is the sum over i, j in 0 to 7 of s_(n-1)(8 ox + i, 8 oy + j), reads past the edge 0: a sum, never an average, so the total is an exact integer at any frame size (float32 sums of whole numbers are exact to 2^24). In the js, with cnt the integer from the readback and prev the last frame's, d = cnt - prev: up if d > 0.5, down if d < -0.5, no bangs on the first frame after load or a reset. The rate outlet is abs(d), unsmoothed (0 on the first frame). Debounce: a bang is dropped if the same kind fired less than debounce ms ago, by Date.now(); up and down have separate timers. Count and rate are divided by full_scale. Messages leave in the order rate, down, up, count.


Notes and limits ​

  • The input must be at the render size. The stages follow the render size; a smaller vecfield is read at the wrong pitch and its marks are wrong. Watch this with a vecfield from a module that does not follow the render size.

  • Exact zero vectors have no defined winding. A plaquette that contains one, and an edge between two adjacent y = 0 texels of opposite x sign (which passes through the origin), can show a lone mark. A uniform, neutral or vs_black field has no marks (tested). A field that is mostly exact zeros with a few nonzero texels has undefined marks.

  • Non-finite components map to 0 and make no mark in a uniform field (tested).

  • Dense fields at render size. The loop at render size reads a bilinearly upsampled field. On f_cgl the counts matched the solver grid exactly; on dense f_nematic (scale 192) they showed up to 3 percent extra plus-and-minus pairs (cause not examined).The marks outlets mark what the loop finds; the count outlets (2 to 5) report how many.

  • The cap. Past 16 texels each side the discs stop growing (tested on the GPU at radius 16 and with size asking for more).

  • Not built: a per-area defect density, tracking of defect identity, a raw-tensor input decode, an analytic-source (Kinem) check.

  • Index of a vecfield's zeros: sources, sinks and centers should wind +1 and saddles −1 (inferred; the live look on a derived vecfield said "interesting" and did not check this).

  • Count: net change only. A birth and a death on the same frame cancel, so neither bang fires. In dense defect turbulence the count changed on about 65% of steps by about 2, so the bangs are frequent. Per-core births and deaths, and tracking, are not done (they need the previous frame's marks).

  • Count: late. jit.gl.asyncread delays the matrix by a frame (its interleaved mode), so every count message lags the field by about a frame. A readback also costs a little time every frame.

  • Count: asyncread is untested here. The reference note docs/max-reference/jit_gl_asyncread_architecture.md says it was never run in this environment and records a Max 9.1.4 bug thread; if the count outlets stay silent, check the Max Global Context preference first. f_util_profile already ships an asyncread.

  • Count: a resize does not reset the state. The first frame after load fires no bang; a frame-size change can cause at most one stray bang. Send reset to clear it.

  • Count: 4096 cap. Frames larger than 4096 on a side need a fifth sum stage and are not supported.

  • Count scale. The raw count is unbounded. Scale picks what reads as 1; nothing clamps it. Rate is scaled by Scale too (the absolute change in the count since the last frame, divided by Scale; unsmoothed, because Smooth was removed on 2026-11-29: Matt smooths it downstream).

  • The count chain always runs. Detect, four sum stages, pack and the readback run every frame whether or not outlets 2 to 5 are patched; the amplified cost bench (tests/modules/cores/bench_cores_count_cost_amp.py, tests/logs/20261129-162732-bench.log, Claude on Matt's go, 2026-11-29) resolves the GPU stages (detect plus s1 to s4; not the pack stage, the readback or the js) at about 0.25 ms per frame at 1920x1080 (detect 0.105, s1 0.122, s2 0.015, s3 and s4 about 0.002 each) and about 0.04 ms at 256x256. Each repeat reads neighboring texels, so caching may make the slope a little low (inferred, not checked). The readback and js cost is not measured.

  • Why not jit.fx.an.mean. It averages pairs of texels per stage and is inexact when a stage has an odd size (1080 and 1920 both reach one). Read in its source, not run (docs/max-reference/jit_fx_vs_ideas.md).

  • Why merged, not a separate module. First built as f_cores_count (gate D2, a separate module with a pinned copy of the detector). Merged on Matt's call: one detector, one module to learn, no duplicate detector pass. The cost is a rebuild of a stable module and the always-on stages. Decision record: .specify/stable/f_cores/count/.


Verification ​

  • Tier 1: tests/modules/cores/test_cores.py, 16/16 (tests/logs/20261128-230009-offline.log): a vortex pair at known plaquettes, conjugation flips signs, phase rotation and periodic roll change nothing, net charge zero, uniform and neutral fields, a wrapped-phase-sum reference on a short f_cgl run, f_nematic's winding() on a short nematic run (the sign), the distance against brute force (worst error under 1e-9), the disc against the lattice-point count, the cap, and five mutations each caught.
  • Tier 2: tests/modules/cores/bench_cores.py, 7/7 (tests/logs/20261128-232107-bench.log): GPU against mirror for each stage (detect and hdist exact; shade within 9e-8), a non-square frame, the sign at known plaquettes, size, soft and charge at non-default values, the cap, end to end, bypass. The first run was 3/6 on a compile error (a function after a Param), fixed. Module contract bench 2/2 (tests/logs/20261128-232500-bench.log). Both re-run after the rename to f_cores on 2026-11-29: stage bench 7/7 (tests/logs/20261129-002459-bench.log), contract bench 2/2 (tests/logs/20261129-002505-bench.log).
  • Cost (bench_cores_cost.py, tests/logs/20261128-232114-bench.log; ms per pass; a record, not a gate; most rows are upper bounds at the bench's per-frame floor): 256 x 256 about 0.25 to 0.46 per stage, all upper bounds; 1920 x 1080 at size 1% about 0.73 per stage, upper bounds; at the cap (radius 16) at 1080p: hdist 1.035 and shade 1.096, resolved, detect still an upper bound at 0.734, so the whole chain is at most about 2.9 ms per frame there. For orientation f_cgl is 3.47 ms and f_ks 2.39 ms.
  • Count, tier 1: tests/modules/cores/test_cores_count.py, 13 tests before the merge (tests/logs/20261129-122529-offline.log; the detector-copy pin was dropped at the merge, and the stage-id check now names the merged ids): the block sum equals the plain sum exactly at nine sizes including 255 x 129, 1001 x 563 and 1 x 7; the count equals the detector's marks and the float64 reference on 12 saved spike states; the counter pulses and closed-form rate; a model of an.mean that is inexact at 1080 x 1920 (inferred); a mutation check.
  • Count, tier 2 (run on the separate module, same sum codeboxes; the pack stage and the js are new since): tests/modules/cores/bench_cores_count.py 7/7 (tests/logs/20261129-132833-bench.log): all codeboxes compile, every sum stage and the four-stage ladder equal the mirror exactly at five sizes, detector to count end to end is exact (22054, 187642, 132), the old GPU counter matched a scripted sequence (rate within 2e-8); that logic now lives in cores_count.js, tested under node against the same mirror (test_cores_count.py, 14 tests, tests/logs/20261129-134636-offline.log: count and rate floats within 1e-12, bang for bang, bypass, first frame, reset). Cost bench_cores_count_cost.py (tests/logs/20261129-132902-bench.log), upper bounds: 1920 x 1080 detect 0.745 plus sum stages 0.34 to 0.45 each, about 2.37 ms per frame; 256 x 256 about 1.06.
  • After the merge: drift 1 of 1, preflight Part 1 run; the marks bench, the count bench (its count-stage rows were replaced by a pack-stage row) and the contract bench (now limited to the two texture outlets, TEXTURE_OUTLETS) were re-run live on the merged patcher 2026-11-29 (marks 7/7, count 5/5, contract 2/2 after debounce and full_scale were listed as known, since they target the js, not a pix; commit fe979d9).
  • Live (Matt): see Status. The helpfile was looked at and approved by Matt, live, 2026-11-29.

f_lfo and f_util_profile (other control-texture sources), vs_op2, vs_comparator and vs_vca (modules that process a 1x1 control texture). f_cgl (outlet 1 is the natural input; its spec D11 parked a defect-marks outlet, which this module answers), f_nematic (outlet 1), f_vf_stamp (out0 as the stamp), f_vf_advect, f_vf_fluid. ideas/field_object_bridge.md (why: fields and the objects inside them), ideas/f_defects_spike.md (the evidence).


References ​

The charge of a defect is the winding number of the field around it, and the index of a zero of a vector field; the +1/2 and -1/2 defects of a line field (a nematic director) are the standard half-integer charges. These are textbook facts, not looked up for this module.

  • The detector (signed crossings of the positive real axis around each 2 x 2 loop, no atan2): derived in development, no outside source. Checked against a wrapped-phase-sum winding on f_cgl states and against f_nematic's own winding(), in NumPy and on the GPU (ideas/f_defects_spike.md, tests/modules/cores/).
  • The spread (a two-pass separable exact Euclidean distance): a standard construction, written here from scratch; checked against a brute-force distance.
  • Sign convention: plus = the mirror's +1/2 defect of f_nematic, checked by motion (the plus marks move about 2.5 times as fast as the minus marks in the mirror, and Matt saw the plus marks travel farther live).
  • The count's block-sum reduction: a standard parallel reduction, written here from scratch; checked against the plain sum at odd sizes.