f_apollonian
Status: Planned — not yet speccedLast updated: 2026-07-07
Concept
Apollonian gasket — a circle-packing fractal generated by iterated circle inversion. Closely related to hyperbolic tiling (see ideas/f_poincare.md): specific gaskets (Ford circles) are the circle-packing shadow of a hyperbolic tessellation by the modular group. Not a random pairing — at least one important case is the same underlying group viewed two ways.
Originally attempted ~2026 (a year prior to this writeup) and abandoned — math wasn't framed clearly enough and GenExpr/codebox fluency wasn't there yet. Revisited 2026-07-07 with a year of accumulated jit.gl.pix/GenExpr empirical knowledge (fixed-iteration loops and user-defined functions both since confirmed GPU-safe) and three real Shadertoy reference implementations to check against.
Relationship to f_poincare
Considered as either one shared module or two siblings sharing a Möbius-iteration core — no strong preference yet, "whatever works." Real shared skeleton: take a point, repeatedly apply a transform from a generating set until it lands in a canonical home region, then sample/color from there. Real divergence:
- {p,q} triangle tessellation — space-filling, every point converges to a well-defined fundamental domain in a small bounded number of steps. Every pixel gets a texture sample.
- Apollonian gasket — most of the disk resolves into some circle in the packing, but the gasket boundary itself is a fractal residual set of points that never settle. Needs a real max-iteration param and a decision about what non-converged pixels show (fractal boundary itself, likely via iteration-depth coloring, rather than a texture sample).
If built as two modules, likely candidates for a shared .genexpr helper library (require()-based) rather than duplicated inversion/loop code.
Reference implementations (Shadertoy, 2026-07-07)
Three shaders reviewed. Not portable verbatim (different language/runtime — GLSL fragment shader vs. GenExpr codebox) but the mechanism translates directly.
1. "Colorful Apollonian III" fork chain (FabriceNeyret2 / mla lineage) — N=3 ring-of-circles + central circle, 20-iteration fixed loop, one optional user-driven "final inversion" via an interaction point, colored by iteration depth (cos(depth * 0.5 + ...)). Also demonstrates the whole gasket embedded as a texture on a raymarched 3D torus-of-disks surface — confirms the gasket render can be composited as a 2D layer inside a larger scene, not just full-frame.
2. "Apollonian Gasket" (ebanflo-derived) — N=3 ring + central circle, 100-iteration fixed loop, invert()/checkinverse() split into a reusable pair (probe-and-conditionally-invert). Live iTime-driven rotation of the ring circles' positions. Three keyboard-toggled alternate boundary mappings: half-plane→disk, invert-in-unit-disk, and an inverse Joukovsky transform. Mouse-driven circle inversion applied to the whole field before the gasket loop runs.
3. "Ford circles + final inversion" — simplest of the three. 8-iteration fixed loop, no early exit inside the loop (runs the full 8 every pixel, unconditionally: invert, swap x/y, mod-wrap x). Produces the Ford circles fractal as a byproduct pattern (gray), then applies one final, live-animated circle inversion (center + radius driven by iTime or mouse-drag) to get "any Apollonian gasket" (black) from the fixed Ford construction.
Key findings from this review
Fixed-iteration loops confirmed as the right shape. All three use a for loop with a hard iteration ceiling (8/20/100) — matches GenExpr's "for/while valid but fixed iteration counts only" constraint. Good empirical confirmation this approach is loop-friendly, not just theoretically fine.
Early-exit (break/continue) needs empirical GPU verification before relying on it. The ebanflo-derived shader's checkinverse() uses conditional early exit inside the inner per-circle loop; jit-gen-codebox skill only confirms for/while themselves, not break. UNVERIFIED — check this first in a scratch test. Fallback if it silently misbehaves: carry a settled flag, multiply/mix remaining iterations to no-ops once resolved (same branchless idiom already used elsewhere in f_, e.g. bypass patterns). The Ford-circles shader sidesteps this entirely — no early exit, just always runs all 8 iterations — making it the easiest first scratch-test target.
Animating region size/boundary — better answer than previously assumed. Earlier assumption (this session, before finding these refs) was that resizing individual packed circles breaks Descartes' Circle Theorem tangency constraints, requiring either a parameterized family of valid configurations or accepting seams/overlap as intentional. The Ford-circles shader's actual approach is simpler and cleaner: keep the generating circles fixed and constant, then apply one final circle inversion to the whole settled result, with that final inversion's center/radius live-animated. Because Möbius transforms map circles to circles and preserve tangency by construction, this one extra transform can be animated freely without ever violating the packing math — while still producing large visible changes in relative circle sizes on screen (Möbius maps aren't distance-preserving). Cheap: one extra invert()-equivalent call on the final coordinate, using live params. This directly answers the "animate region size/boundary" question raised this session.
Arbitrary boundary generalization — has real prior art. The ebanflo-derived shader supports swapping the disk boundary for a half-plane via one extra inversion step (z.y += 1.0; z = invert(z, vec3(0,-1,2))-equivalent) — i.e., a line (infinite-radius circle) as a generating boundary is a known, supported degenerate case in this construction, not a hack. Relevant directly to the "arbitrary boundary, not just disk" framing from this session's f_poincare discussion — same underlying idea (swap the generator set/geometry, keep the iteration machine) should extend further than disk/half-plane, though nothing beyond these two cases has been checked.
Texture sampling inside regions — still an open design problem, but a mechanism now exists. None of the three reference shaders sample a source texture per-region; all color purely by iteration depth or draw the circle boundaries as signed-distance lines. However, the ebanflo-derived shader's checkinverse() already identifies which specific circle (center + squared radius) a point last resolved against before settling. That's the missing piece for consistent per-region texture sampling regardless of a region's scale: normalize (pos - circle_center) / sqrt(circle_radius_sq) into a local UV using the last circle a point actually landed in, then sample there. Concrete mechanism, not yet tested.
Composition as a layer, not just full-frame. The torus-of-disks example (ref 1) confirms the gasket computation can drive a texture/UV within a larger composited scene rather than needing to own the whole frame — relevant if this ever needs to sit inside a Vsynth chain alongside other content rather than as a standalone full-screen processor.
Open questions carried forward
- Is
break/early-exit GPU-safe injit.gl.pix's GenExpr path? Not yet tested — first thing to check in scratch. - One module or two (shared with
f_poincare)? No decision — "whatever works," revisit once a scratch mechanism is proven. - Max iteration count as a live param (confirmed desirable — reference shaders show a range from 8 to 100 depending on visual density wanted) — what's a good default/range for this pipeline's performance target? Not measured.
- What do non-converged pixels (the true fractal boundary, at max iteration without settling) show — iteration-depth coloring, a distinct visual treatment, or feed as a mask/mod texture output (same "expose singularity as second outlet" idea already used in
f_droste)? Not decided. - Per-region texture sampling — mechanism identified above, not tested empirically.
- Relationship to
droste_singularity.md— the "fractal boundary that never resolves" here is conceptually close to droste's log-polar singularity zone (both are sampling-rate/convergence isocontours). Worth reading that file again once a scratch mechanism exists, to see if the same masking/exposure tricks apply.
Build sequence
Not yet started. Proposed first step (not yet done): scratch-test the Ford-circles construction (simplest of the three — fixed 8-iteration loop, no early exit) plus one final animatable inversion, and confirm visual match against the reference before touching camera motion, texture sampling, or the f_poincare merge question.
Update 2026-11-07
f_poincare is built; see ideas/f_poincare_lessons.md for what transfers here (a float64 mirror first, the order-dependence of overlapping circles, a branchless settle loop that needs no break, the three-nearest-circles trick, knife-edge tolerance, the unsettled-pixel policy). Paused status unchanged (P-moebius-tiling).