Bloom Passage
Bloom Passage
Bloom Passage - Thin-Petal Volumetric Flower Cavern
Note: Most of the code in this post was written by AI.
The prose was written by a human, but most of the formulas and code were written by AI.
bloom-passage is a WebGL2 volumetric ray-marching scene: the camera travels through a winding cavern, and elliptical buds that grow inward from the walls and ceiling open as it comes near.
The petals are not thick SDF solids or CPU-built meshes. They are very thin density layers wrapped around curved midsurfaces, and each ray integrates their emission, absorption and transmittance together with the density of the surrounding rock.
The current implementation rests on a few design constraints.
Bloom state is driven solely by camera distance, not by time-based random values.
Petal attachment points are fixed, and petals split open from the free end.
Petals are sheet densities 8.8–10.2 mm thick rather than elliptical cross-section tubes.
Ray-cast flower petals close the outer end of the midline with an elliptical cap while preserving tip width, so the free end does not come to a sharp point.
The white tissue is nearly opaque due to a high absorption coefficient, but retains only a faint transmission at the edges.
A single stem endpoint owns the stem, sepal, floret center, and petal frame all at once.
The stems of all flowers are aligned to the local normal pointing from the cavern's outer wall toward its center.
The final color is obtained via Beer-Lambert front-to-back integration rather than a surface hit.
1. Curved Cavern and Radial-Axial Repetition
The cavern centerline is the sum of two frequencies in the travel coordinate z.
C(z) = (
0.82sin(0.18z) + 0.24sin(0.47z + 1.30),
0.55cos(0.15z + 0.40) + 0.20sin(0.39z − 0.70)
)The cross-section radius adds a slow breathing component to the angular relief of the rock wall.
R(z,θ) = 2.28 + 0.16sin(0.21z+0.50) + 0.07sin(0.53z−0.80)
+ 0.13sin(3θ+0.31z) + 0.065sin(7θ−0.47z)
+ 0.035sin(11θ+0.29z)The axial direction repeats over L_z=2.65, and the cross-section repeats across N=6 sectors. A hash rotates each axial cell, and each flower's axial position and angle get jittered again within a small range.
k_z = floor((p_z + L_z/2)/L_z)
Δθ = 2π/N
k_θ = floor((θ − φ(k_z) + Δθ/2)/Δθ)
θ_a = φ(k_z) + k_θΔθ + jitter(hash(k_z,k_θ))A flower's base point is C(z_a)+R(z_a,θ_a)(cosθ_a,sinθ_a). The outward normal n_o, the circumferential tangent t, the inward normal n_i and the axis a give the flower its local frame.
n_o = (cosθ_a, sinθ_a, 0)
t = (−sinθ_a, cosθ_a, 0)
n_i = −n_o
a = (0,0,1)
q = (dot(p−b,t), dot(p−b,n_i), dot(p−b,a))So every flower faces into the cavern without rotating and duplicating one model onto the floor, side walls and ceiling. Use only the inward wall normal as the stem axis, and the thin corollas on the 3 o'clock and 9 o'clock walls line up exactly edge-on to a forward-moving camera. Instead of a billboard that swings to face the screen, each cell carries a fixed upstream tilt ℓ_z, which keeps the flower's physical orientation while avoiding the projection singularity.
ℓ_z = −mix(0.24,0.30,hash(k_z,k_θ))
s = normalize(ℓ_t t + h_stem n_i + ℓ_z a)In a curved cavern, the gap between C(p_z) and the ring reference C(z_ring) can push a flower's bounding sphere past its nominal angular cell. Evaluate one cell only and the flower ID flips right there, cutting the corolla flat. The implementation evaluates just the nearest angular neighbors, together, inside a boundary strip, and looks at each axial neighbor once. Anchor jitter, stem tilt, wind and the flower head's bounding sphere are kept to a sum below L_z/2, so each axial ring has exactly one owner.
θ_local = θ − φ(k_z) − k_θΔθ
d_boundary = |p_xy−C(z_ring)| sin(Δθ/2−|θ_local|)
d_boundary < 0.76 이면
ρ_flower = max(ρ_kθ, ρ_kθ±1), D_flower = min(D_kθ, D_kθ±1)
|z_jitter| + |lean_z| + |wind_z| + r_head < L_z/2Both sides of an angular boundary evaluate the same two candidates in opposite order. Density max, distance min and material-weighted averages are all commutative, so the result is continuous across sector planes. Axial rings look at one candidate only.
Personal note: in practice, when browsing ShaderToy, experienced shader programmers use ray marching frequently. This work represents a first step in that application, using Signed Distance Functions (SDFs) defined procedurally inside the shader along with domain repetition techniques.
2. Bloom State Determined Solely by Distance
The distance d between the flower center c and the camera r_o maps to a bloom amount O.
P(d) = clamp((d_far − |c − r_o|)/(d_far − d_near), 0, 1)
P_η = clamp(P + 4ηP(1−P), 0, 1), η ∈ [−0.09,0.09]
O(d) = P_η²(3 − 2P_η)When d ≥ d_far, O=0; when d ≤ d_near, O=1. Time drives only the stem wind and a slight petal flutter, so even a flower that comes extremely close to the camera keeps its open state instead of turning back into a bud.
3. Opening from the Free Tip of an Elliptical Bud
The petal's length coordinate is u∈[0,1]: u=0 at the base attached to the stem, u=1 at the free tip. The actual cubic Bézier control points for a closed and an open petal are below.
P₀ = (r_b, y_b)
P₁_closed = (r_b + 0.76b, y_b + 0.31h)
P₂_closed = (r_b + b, y_b + 0.72h)
P₃_closed = (r_b, y_b + h)
P₁_open = (r_b + 0.24R, y_b + 0.78A)
P₂_open = (r_b + 0.67R, y_b + 0.62A − 0.18G)
P₃_open = (r_b + R, y_b − G)h is bud height, b is bud inflation, R is open length, A is crown height and G is the per-petal gravitational droop. Each petal keeps a single midplane. Control points P₁, P₂, P₃ sit at the base, shoulder and free tip, and one cubic Bézier skeleton is kept all the way through. With g(x)=x²(3−2x), all three control points start moving at O=0, but the free tip leads and the shoulder and base follow.
r = g(O)
r_tip = r
r_shoulder = r(0.58 + 0.42O)
r_hinge = r(0.28 + 0.72O)
P₁ = mix(P₁_closed, P₁_open, r_hinge)
P₂ = mix(P₂_closed, P₂_open, r_shoulder)
P₃ = mix(P₃_closed, P₃_open, r_tip)
c(u,O) = (1−u)³P₀ + 3(1−u)²uP₁ + 3(1−u)u²P₂ + u³P₃A petal therefore carries either a closed curve segment or an open one, never both at once. Every release function is zero at the start in both value and first slope, so only the free tip moves at first, and the early edge pop where the shoulder used to kink is gone as well. The self-fold that made double coronas regenerate mid-bloom in the earlier implementation is blocked by construction. The base distance range has also widened from 2.2→7.5 m to 1.6→10.8 m, so at the default speed a bloom now takes about 8.8 seconds instead of roughly 5.
A hash gives each flower one of 28, 30, 32, 34 coronas. Overall length, width, droop, floret size and bloom phase vary from cell to cell, and each petal's small individual deviations in length and width grow continuously from zero with g(O). The closed corolla therefore stays smooth, and no shape switches on at a threshold bloom value.
4. Thin Petal Density Field
Petals are handled as one continuous curve rather than chopped into straight ribbon segments. For a sample q_xy, the closest parameter u on the current-bloom midline c(u,O) is found. With r=c(u,O)−q_xy, the objective function is F(u)=|r|²/2.
F′(u) = dot(r,c′)
F″(u) = dot(c′,c′) + dot(r,c″)
δ_k = clamp(F′/safe(F″), −0.16, 0.16)
u_{k+1}= clamp(u_k − δ_k, 0, 1)
n = dot(q_xy − c(u,O), normalize(−c′_y,c′_x))The derivative comes from the analytic first and second derivatives of the cubic Bézier, not from finite differences.
c′(u) = 3(1−u)²(P₁−P₀) + 6(1−u)u(P₂−P₁) + 3u²(P₃−P₂)
c″(u) = 6(1−u)(P₂−2P₁+P₀) + 6u(P₃−2P₂+P₁)A bud curve folds once radially and then straightens into a monotone curve as it opens. An initial guess back-solved from height or radius alone can therefore converge on the wrong branch in the middle of a bloom. The implementation picks the global minimum basin from nine candidates on [0,1], then applies four Newton corrections with the full Newton denominator.
u_0 = argmin_{j∈{0,…,8}} |c(j/8,O)−q_xy|²
u ← Newton(F′,F″), 4 iterationsThe argmin over discrete candidates does not change the distance value; it only picks Newton's basin. Distance and density are then computed at the corrected curve point, which closes the path where a wrong branch used to blow up into long white fragments mid-bloom. The tangent residual stays out of the marching path and is not used as a conservative sphere-tracing distance. Ray florets are narrow near the floret center and widen in the middle. Rather than forcing the width to zero at u=1, M_end keeps the off-midline distance after the nearest point clamps to the endpoint, which rounds the tip into an elliptical cap.
b(u) = smootherstep(clamp(u/0.13,0,1))
g(u) = mix(0.50,1,smootherstep(clamp((u−0.06)/0.44,0,1)))
t(u) = 1 − 0.12 smootherstep(clamp((u−0.70)/0.30,0,1))
w_max(O) = mix(0.023,0.0355,O) · scale_width
w(u,O) = w_max(O) · b(u) · g(u) · t(u)Angular repetition evaluates the current petal i together with its boundary neighbors i±1 inside its sector, instead of clipping the current petal alone. The neighbors are switched on continuously by a gate χ that is 0 at the sector center and 1 at the edge.
χ = smootherstep(clamp((|φ_local|−0.14Δθ)/(0.36Δθ),0,1))
ρ_corona = max(ρ_i, χρ_{i±1})The upshot is that even when a petal is wider than half the sector, no radial straight line clips it; adjacent petals overlap a little instead, just as they do on a real flower.
Multiplying the mid-surface Gaussian density by an edge mask gives the thin sheet.
ρ_p(q) = exp(−2.20(n/τ)²) · M_side(|q_z|/w) · M_end · M_nearest
τ ∈ [0.0088, 0.0102]The color shift from green bud tissue to white ray petals is not driven by one O value for the whole corolla; it belongs to a separate field that travels from the free tip down to the base. That pigment field starts at u=1, propagates toward u=0, and is stored alongside the density field.
O_start(u) = mix(0.48,0.34,u)
W(u,O) = smootherstep(clamp((O−O_start(u))/0.34,0,1))
ρ_white = ρ_p · WA corolla still folded into a cup therefore stays green bud tissue. White begins at the free tip only after the petal blade has actually separated, then works down toward the base.
The cell ID for angular repetition has to be normalized by the corona count. atan wraps between +π and −π at the same direction, so hashing the raw integer makes the two sides of the same flower, or of the same petal, come out as different objects.
i_flower = mod(floor((θ−φ+Δθ/2)/Δθ), N_flower)
i_petal = mod(floor((ψ+δψ/2)/δψ), N_petal)Without that normalization, a flower straddling the branch cut was evaluated as two independent halves: the center got clipped, or a white semicircular shard appeared.
An open petal lifts its edges in proportion to the square of the lateral coordinate. This cupping bends the mid-surface itself instead of thickening the cross-section. The central midrib ρ_v, the parallel micro-ridges ρ_r and the marginal tissue ρ_e are computed from u and the normalized lateral coordinate. These are procedural surface coordinates that ride on the petal rather than external textures, so they stay fixed to the petal through the bloom.
M_nearest discards only those samples whose tangential residual from the Newton result is unusually large. The value stays a safety valve on visible density and has nothing to do with how far a ray may skip across empty space.
5. Single Coordinate Owner for Rock Anchors and Flower Heads
In the local frame whose origin is the wall anchor b and whose +Y=n_i, the stem endpoint is a single point.
h = (lean_t, stemHeight, lean_a)
D_stem(q) = sdCapsule(q, 0, h, r)
c_flower = b + h_x t + h_y n_i + h_z aThe flower head's local +Y axis aligns with normalize(h).
q_head = (
dot(p−h, x̂),
dot(p−h, ŷ),
dot(p−h, ẑ)
)Because the stem capsule and the flower head share the same rock anchor and frame, the sepals and petals stay attached to the stem — on a wall or a ceiling, with wind or without.
6. Floor Rock and Moss Surface Field
The floor is part of the cavern cross-section, not a 2D layer pasted at the bottom of the screen. A floor mask comes from how far the radial vector r_xy points downward, and moss and fine moisture veins are laid out with low-frequency noise over the wall coordinates (x,z).
M_floor = smootherstep(clamp((−r_y/|r|−0.24)/0.56,0,1))
ρ_moss = ρ_wall M_floor smoothstep(0.46,0.72,N_moss)
ρ_vein = ρ_wall M_floor (1−|2N_f−1|)^11 smoothstep(0.50,0.76,N_moss)Low pebbles are elliptic footprints whose position, aspect ratio and height are hashed per (x/0.58, z/0.76) cell. The pebble height h_s∈[0.030,0.095] pushes wallGap inward by that much, so the pebbles take part in the silhouette and occlusion of the real volume. Moss and veins tint the same wall density, so they stay on the wall.
7. Emission–Absorption Volumetric Ray Marching
Each sample's extinction coefficient is a weighted sum of the petal, vein, stem, floret-center and sepal densities.
σ_t = ρ_p(112 + 14ρ_r + 4ρ_e) + 58ρ_s + 72ρ_c + 54ρ_k + 44ρ_wBeer-Lambert transmittance and scattered light are updated front to back at each sample interval Δs.
T_step = exp(−σ_t Δs)
α = 1 − T_step
L_{k+1} = L_k + T_k · S_k · α
T_{k+1} = T_k · T_stepS_k is the source term: material color, the density derivative along the sun direction, and a forward/backward scattering approximation. The base extinction coefficient for petals went from 38 to 112. White tissue therefore looks nearly opaque head-on, and only the Gaussian tail of the sheet and the thin edges keep some T for backlit transmission.
8. Adaptive Sample Spacing and Bounds
Empty space is skipped with a conservative distance d_macro to the stem capsule, the flower head bounding sphere, the petal plane and the cavern wall. The flower head sphere is used as an acceleration distance only from outside. Negative values inside it do not correspond to material, so once a ray has entered, the petal, core and sepal distance fields take over. A pixel is a cone rather than a line, so a step narrower than the cone is wasted marching through something the ray cannot resolve.
D_head⁺ = max(D_head,0)
Exterior: d_macro = min(D_stem,D_head⁺)
Inside the detailed model: d_macro = min(D_stem,D_core,D_calyx,D_petal)w_px = (2 / (H · 1.78)) · s Pixel cone width
Δs = clamp(max(0.60 d_macro, w_px), 0.007, 1.60)
σ_t > 0.025이면 Δs = clamp(0.35 / σ_t, 0.007, Δs)Sampling stops at 128 iterations, terminates early at T<0.012, and ends at 20 m. The cave rock wall is part of the same emission-absorption integral, so occlusion behind flowers is solved in the same marching loop without a separate 2D layer. The internal render resolution follows the measured FPS, somewhere between 34% and 100% of the screen size.
d_macro is a proximity estimate, not a Signed Distance Function. The petal sheet value comes from the nearest point on the Bézier found by Newton's method, the floret center and sepals from ellipsoid approximations, and the wall from the radial gap. Sphere tracing the full d_macro step therefore gives up any guarantee of staying outside the surface. That is why the coefficient drops from 0.85 to 0.60, and why spacing inside material is set by optical depth rather than a fixed lower bound. Both values came from measurement; see "The problem of steps skipping over petals" below.
9. Camera
The camera follows the same C(z) as the GLSL cavern and looks 3.35 units ahead. Instead of a fixed world-up vector it builds a local frame from the direction of travel and the curvature, then adds two low-frequency rolls so the heading shifts as if the cavern were really being walked.
r_o = path(z)
r_t = path(z+3.35)
f = normalize(r_t−r_o)
s = normalize(f × y_world)
u_0 = normalize(s × f)
roll(z) = 0.23sin(0.17z) + 0.09sin(0.43z+1.20)
u = u_0 cos(roll) + s sin(roll)Drag input moves only the look-ahead target along the local s,u directions. Flowers the camera has passed drop out of the forward ray range on their own, so scene state is complete with the forward range alone.
Formula → Code
Formula/Concept | Implementation Location | Role |
|---|---|---|
|
| Curved cavern centerline and rock wall boundary |
Axis-angle repetition cell |
| Wall and ceiling flower anchor selection |
upstream stem lean |
| Preventing edge-on projection collapse of the 3 o'clock and 9 o'clock sidewall corollas |
|
| Preventing the entire flower from being clipped at sector planes; the axial ring is single-owned as a placement invariant |
varied cubic |
| Slow distance-based blooming and per-cell phase offset |
continuous staged Bézier |
| Persistent skeleton where all segments depart simultaneously and the free end leads |
ray-cast flower petal |
| Narrow base, wide blade, and arc-shaped free end |
global basin + analytic Newton |
| Nearest-point computation that does not diverge onto a spurious curve branch even for a folded bud |
neighbor-gated petal union |
| overlapping ray-cast flower petals without sector clipping |
|
| thin sheet density with tangential residual boundary |
|
| central midrib, parallel fibers, and marginal tissue |
|
| white pigment transition progressing from the free tip toward the base |
angular corona repetition |
| a single-layer corolla of 28–34 petals per flower |
canonical angular IDs |
| Preventing flowers and petals from splitting in half at the |
Rock-face local frame and |
| Wall normal alignment and flower head tip position |
|
| Ground moss, moisture veins, and low pebbles attached to the cavern wall |
|
| Beer-Lambert transmittance |
|
| Front-to-back scattering integral |
adaptive |
| Empty-space acceleration and thin-petal preservation |
look-ahead + roll camera |
| Curved-cavern travel direction and gaze alignment |
- Formula/Concept
C(z),R(z,θ)- Implementation Location
shaders/flower-model.glsl- Role
Curved cavern centerline and rock wall boundary
- Formula/Concept
Axis-angle repetition cell
- Implementation Location
shaders/flower-model.glsl- Role
Wall and ceiling flower anchor selection
- Formula/Concept
upstream stem lean
ℓ_z- Implementation Location
shaders/flower-model.glsl- Role
Preventing edge-on projection collapse of the 3 o'clock and 9 o'clock sidewall corollas
- Formula/Concept
d_boundary, angular adjacent-cell union- Implementation Location
shaders/flower-model.glsl- Role
Preventing the entire flower from being clipped at sector planes; the axial ring is single-owned as a placement invariant
- Formula/Concept
varied cubic
O(d)- Implementation Location
shaders/flower-model.glsl- Role
Slow distance-based blooming and per-cell phase offset
- Formula/Concept
continuous staged Bézier
c(u,O)- Implementation Location
shaders/flower-model.glsl- Role
Persistent skeleton where all segments depart simultaneously and the free end leads
- Formula/Concept
ray-cast flower petal
w(u,O)- Implementation Location
shaders/flower-model.glsl- Role
Narrow base, wide blade, and arc-shaped free end
- Formula/Concept
global basin + analytic Newton
u- Implementation Location
shaders/flower-model.glsl- Role
Nearest-point computation that does not diverge onto a spurious curve branch even for a folded bud
- Formula/Concept
neighbor-gated petal union
- Implementation Location
shaders/flower-model.glsl- Role
overlapping ray-cast flower petals without sector clipping
- Formula/Concept
ρ_p=exp(−2.20(n/τ)²)M- Implementation Location
shaders/flower-model.glsl- Role
thin sheet density with tangential residual boundary
- Formula/Concept
ρ_v,ρ_r,ρ_e- Implementation Location
shaders/flower-model.glsl- Role
central midrib, parallel fibers, and marginal tissue
- Formula/Concept
ρ_white=ρ_pW(u,O)- Implementation Location
shaders/flower-model.glsl- Role
white pigment transition progressing from the free tip toward the base
- Formula/Concept
angular corona repetition
- Implementation Location
shaders/flower-model.glsl- Role
a single-layer corolla of 28–34 petals per flower
- Formula/Concept
canonical angular IDs
mod(i,N)- Implementation Location
shaders/flower-model.glsl- Role
Preventing flowers and petals from splitting in half at the
atanbranch cut
- Formula/Concept
Rock-face local frame and
D_stem- Implementation Location
shaders/flower-model.glsl- Role
Wall normal alignment and flower head tip position
- Formula/Concept
ρ_moss,ρ_vein,ρ_stone- Implementation Location
shaders/flower-model.glsl- Role
Ground moss, moisture veins, and low pebbles attached to the cavern wall
- Formula/Concept
T=exp(−σ_tΔs)- Implementation Location
shaders/render.frag- Role
Beer-Lambert transmittance
- Formula/Concept
L+=T·S·α- Implementation Location
shaders/render.frag- Role
Front-to-back scattering integral
- Formula/Concept
adaptive
Δs- Implementation Location
shaders/render.frag- Role
Empty-space acceleration and thin-petal preservation
- Formula/Concept
look-ahead + roll camera
- Implementation Location
main.js- Role
Curved-cavern travel direction and gaze alignment
File structure
quad.vert
↓
common.glsl — hash / noise / primitive / tone mapping
↓
flower-model.glsl — tunnel frame / wall anchors / petal sheet density
↓
render.frag — flower + cave volume integration / scattering
↓
main.js — static manifest / camera / uniforms / adaptive qualityThe static SHADER_URLS manifest in main.js loads every GLSL file explicitly. The scene is built from GLSL files alone: no external images, textures or CPU flower meshes.
Controls
The panel is hidden by default; press
Hto open it.Flight speedcontrols the camera movement speed.Flowers within
Near bloomdistance open fully.Flowers beyond
Far bud limitremain as buds.Dragging the canvas adjusts the gaze direction relative to the current travel direction.
New cavernregenerates the seed for flower positions and shapes.Spacepauses the camera and wind.
Troubleshooting issues encountered during implementation
The metric is the temporal second-order difference of pixel luminance. For a smoothly moving signal the second difference should be far smaller than the first, so a large value means luminance is reversing direction every frame, and that reversal is the flicker. The fraction of pixels that satisfy |second-order difference| > 12/255 is recorded as popPct.
The release build at 765×595 measured popPct 4.22%, d2 2.583 > d1 1.706.
What was NOT the cause (all ruled out by measurement)
Experiment | popPct |
|---|---|
Original | 4.22% |
Resolution 270 → 1800 px | 4.66 / 4.61 / 4.63 / 4.63% |
Step count 84 → 320, max step 0.26 → 0.05 | 4.61% |
Min step 7 mm → 1.5 mm | 4.49% |
Optical depth per step capped at 0.35 | 4.60% (cost +40%) |
Petal count 28–34 → 8–10 | 3.70% |
Shutter 2-tap average | 6.11% (worse) |
- Experiment
Original
- popPct
4.22%
- Experiment
Resolution 270 → 1800 px
- popPct
4.66 / 4.61 / 4.63 / 4.63%
- Experiment
Step count 84 → 320, max step 0.26 → 0.05
- popPct
4.61%
- Experiment
Min step 7 mm → 1.5 mm
- popPct
4.49%
- Experiment
Optical depth per step capped at 0.35
- popPct
4.60% (cost +40%)
- Experiment
Petal count 28–34 → 8–10
- popPct
3.70%
- Experiment
Shutter 2-tap average
- popPct
6.11% (worse)
The decisive evidence was that a 6.7× resolution increase changed nothing; spatial aliasing would have shown up in the resolution. Holding the camera still (speed = 0) dropped popPct to 0.03%, which also rules out the time terms, wind and bloom.
Root cause
Measured by shrinking dt step by step.
dt | d1 | d2 | d2/d1 | popPct |
|---|---|---|---|---|
1/60 | 1.87 | 2.90 | 1.55 | 4.73 % |
1/240 | 0.62 | 0.67 | 1.09 | 1.19 % |
1/960 | 0.185 | 0.177 | 0.96 | 0.22 % |
- dt
1/60
- d1
1.87
- d2
2.90
- d2/d1
1.55
- popPct
4.73 %
- dt
1/240
- d1
0.62
- d2
0.67
- d2/d1
1.09
- popPct
1.19 %
- dt
1/960
- d1
0.185
- d2
0.177
- d2/d1
0.96
- popPct
0.22 %
The density field is smooth. What was lacking was the frame rate. d1 falls linearly with dt, and d2 does too, the signature of a signal where a hard boundary crosses a pixel. At the base speed of 0.82 a nearby flower travels 8.2 pixels per frame, and its silhouette is a bright white edge against an almost-black cavern.
So it does not move; it strobes. Removing the density terms one at a time, dropping the petal term alone took popPct from 4.23% to 0.67%.
In other words this read as a sampling limitation, not a marching bug. The complete fix would have been temporal accumulation (TAA) or a slower camera, and I ruled out both for this demo.
What was done and what was rolled back
Base speed 0.82 → 0.50: This is the only knob that responds nearly linearly to this metric.
At 765×595, popPct was 4.28% at 0.82, 3.49% at 0.55 and 0.94% at 0.35. The slider still reached 1.25, but visually it was not worth it.
Per-pixel shutter was rolled back: offsetting each pixel's camera viewpoint differently until the next frame
The blending approach did lower the spatial coherence of the strobe on paper, but on nearby white flowers it turned the outline into long white shards cut through the middle. That side effect was severe enough that leaving it in was out of the question. Now every pixel in a frame shares one camera transform, and only a small spatial dither of the ray origin remains.
So without temporal accumulation the motion flicker is still there. What did go away is the fake motion blur that broke up shapes, and running at the default speed does ease the sampling error.
The problem of rays dying after exhausting their budget
While working with AI I hit a new bug:
it turned up in the code below.
if (field.macroDistance < 0.020 || extinction > 0.025) stepSize = MIN_VOLUME_STEP;The earlier condition was the culprit. A ray that merely grazed a flower — roughly 2 cm from a bud — also satisfied macroDistance < 0.020 along a long stretch, crawling forward in 7 mm steps without meeting any material. It then burned through the 84-step budget and left with transmittance near 1, so the pixel fell back to background.
At the time 17.21% of the screen ended that way, and those pixels mapped onto the border of every flower and the entire distant passage. Removing the condition took the diagnostic to 0.00%. A second path stayed outside that check, though: the negative interior of the bounding sphere kept holding the distance field through min.
GPT's suggestion was to let empty space skip ahead by sphere tracing, since petalDistance already feeds macroDistance, with the added rule that steps never became smaller than the pixel cone width (anything thinner than the cone cannot be resolved anyway), and to cut MAX_VOLUME_DISTANCE from 26 to 20 m. The fog is exp(-0.008 d²), already 0.87 at 16 m and 0.96 at 20 m, so past that everything is background whatever the ray finds.
A side effect: buds in the distant passage became visible.
The second failure showed up as radial black wedges on the large nearby flower. Crossing a headBound of diameter 1.16 m in 7 mm steps needs about 166 steps, more than the 96-step budget allows. Instead of treating D_head<0 as the true interior distance, Claude's advice was to swap in a detailed distance field as in the formula above, so the shader skips the empty corolla interior again and uses the minimum step only near real thin petals.
The resolution controller oscillation problem
renderScale went down below 24 fps and up above 52, so a dip that fixed the frame rate pulled it back up, and the next slow stretch pushed it down again. On devices near the thresholds the resolution pulsed every 0.7 seconds, and the resolution change was itself visible enough to be a problem in its own right.
When lowering, the ceiling was also lowered at the same time (ratchet), and raising needed 3 consecutive fast ticks. The downward direction reacts immediately on a single tick.
The problem of steps skipping over petals
The nearby flower appeared shredded in a dithered pattern, and a wedge was sliced out of the flower head. Zoomed in, bright and background pixels alternated like a checkerboard.
Troubleshooting steps taken to resolve it:
Attempt | Result |
|---|---|
Step budget 96 → 512 | Reduced but still present |
Petal proximity distance | No change |
Reduce | No change |
Always evaluate angular neighbor cells | Almost no change |
Evaluate two axial-direction rings | No change |
Remove bud color | Completely identical |
- Attempt
Step budget 96 → 512
- Result
Reduced but still present
- Attempt
Petal proximity distance
proximity× 0.5, × 0.25- Result
No change
- Attempt
Reduce
proximitytoplaneGapalone- Result
No change
- Attempt
Always evaluate angular neighbor cells
- Result
Almost no change
- Attempt
Evaluate two axial-direction rings
- Result
No change
- Attempt
Remove bud color
pigmentReveal- Result
Completely identical
Suspecting shading, I split the marching statistics for dark and bright pixels and re-measured. Nothing separated them: transmittance 0.010 against 0.011, 26.2 material samples against 24.5. Both were completely absorbed by something. The dark pixels were rays that skipped the near petals and hit the back wall.
Cause 1: d_macro is not a Signed Distance Function (SDF)
Sphere tracing assumes a lower bound: nothing exists within this radius. Reading d_macro at an arbitrary point and cutting that distance into 64 steps in one arbitrary direction to look for material yields only a lower bound on the violation rate, because it tests a single direction.
Violating samples | Worst-case ratio | |
|---|---|---|
Before fix | 8.06% | 0.016 |
After fix | 0.29 % | — |
- #1
Before fix
- Violating samples
8.06%
- Worst-case ratio
0.016
- #1
After fix
- Violating samples
0.29 %
- Worst-case ratio
—
So 8% of the samples reported as "empty" held material, and in the worst case the material sat at 1.6% of the claimed distance.
Wall density starts rising not at the surface but from wallEdge = 0.105 + 0.035 fineRock inward, while the marching distance still handed over the full gap to the surface. Subtracting the maximum fineRock can produce — not the local value, since a step crosses an interval rather than a point — drops the error from 8.06% to 0.30%. Subtracting the local wallEdge gives 0.47%, so measurement agrees that the maximum is the right choice.
The rest of the error lives in the petal and ellipsoid approximations, a limit of the approximation itself. So I picked the step factor from the measured envelope: 0.85 breaks, 0.60 is clean, and frame times are identical (6.50 ms vs. 6.52 ms at 819×460). Going lower, 0.45 is slower (7.22 ms) and burns more budget, not less (5.23% vs. 1.83%).
0.60 is just the value that looked good to me, which makes it a value chosen by measurement, not a proven safe bound. Making this section genuinely provable would mean rewriting the petal proximity distance as a true signed distance field.
References and measured-value comparison
This section gathers what the demo takes from the literature and where it leaves it. Match means the implementation sits inside the published range; deviation means the difference is deliberate or not yet fixed.
Item | Literature value | This implementation | Verdict |
|---|---|---|---|
Ratio of ray-cast flower petals to floret radius | 0.667 – 0.706 | 0.687 | Match |
Ray-cast petal count | Typically 13 – 34+ | 28 / 30 / 32 / 34 | Upper bound of range, always even |
Floret/corolla diameter | 34 – 60 mm | 0.805 m | Approximately 17× (intentional scale) |
Distal/basal expansion ratio at bloom | 2.5 | 3.57 → 1.00 (depending on O) | Matches only at initial state |
Floret spiral arm count | Consecutive Fibonacci pairs | 13 (one family only) | Partial match |
Tone-mapping coefficients | a 2.51 · b 0.03 · c 2.43 · d 0.59 · e 0.14 | Identical | Match |
Sphere tracing distance lower bound |
| Violated samples: 0.29% | Approximation |
- Item
Ratio of ray-cast flower petals to floret radius
- Literature value
0.667 – 0.706
- This implementation
0.687
- Verdict
Match
- Item
Ray-cast petal count
- Literature value
Typically 13 – 34+
- This implementation
28 / 30 / 32 / 34
- Verdict
Upper bound of range, always even
- Item
Floret/corolla diameter
- Literature value
34 – 60 mm
- This implementation
0.805 m
- Verdict
Approximately 17× (intentional scale)
- Item
Distal/basal expansion ratio at bloom
- Literature value
2.5
- This implementation
3.57 → 1.00 (depending on O)
- Verdict
Matches only at initial state
- Item
Floret spiral arm count
- Literature value
Consecutive Fibonacci pairs
- This implementation
13 (one family only)
- Verdict
Partial match
- Item
Tone-mapping coefficients
- Literature value
a 2.51 · b 0.03 · c 2.43 · d 0.59 · e 0.14
- This implementation
Identical
- Verdict
Match
- Item
Sphere tracing distance lower bound
- Literature value
|f(x)| ≤ d(x, f⁻¹(0))- This implementation
Violated samples: 0.29%
- Verdict
Approximation
1. Bloom dynamics — Liang & Mahadevan (2011)
This was the reference paper on where the force to open a flower comes from.
Working on Lilium casablanca with surgical manipulation and quantitative measurement, it showed that petal margin growth, not the widely accepted midrib growth or adaxial/abaxial differential growth, drives blooming.
Measured values: midrib growth strain is relatively uniform at about 10% in both petals and sepals, while the longitudinal strain at the margin exceeds 20% at the base and increases to nearly 50% toward the distal end, a distal-to-base ratio of about 2.5.
This implementation produces a gradient in the same direction on a single cubic Bézier skeleton by letting the tip lead the shoulder, and the shoulder lead the hinge, rather than solving for stress.
float release = smootherStep(opening);
float tipRelease = release;
float shoulderRelease = release * (0.58 + 0.42 * opening);
float hingeRelease = release * (0.28 + 0.72 * opening);
| tip | shoulder | hinge | tip/hinge |
|---|---|---|---|---|
0.00 | 1.00 | 0.580 | 0.280 | 3.57 |
0.17 | 1.00 | 0.651 | 0.402 | 2.49 |
0.50 | 1.00 | 0.790 | 0.640 | 1.56 |
1.00 | 1.00 | 1.000 | 1.000 | 1.00 |
- O
0.00
- tip
1.00
- shoulder
0.580
- hinge
0.280
- tip/hinge
3.57
- O
0.17
- tip
1.00
- shoulder
0.651
- hinge
0.402
- tip/hinge
2.49
- O
0.50
- tip
1.00
- shoulder
0.790
- hinge
0.640
- tip/hinge
1.56
- O
1.00
- tip
1.00
- shoulder
1.000
- hinge
1.000
- tip/hinge
1.00
The sign and magnitude are correct, but the time-dependency differs. A real lily keeps its distal/proximal slope through the whole bloom, whereas here the slope passes the literature value of 2.5 near O=0.17 and then keeps falling, reaching 1.00 at full bloom — the slope has vanished. It is the result of starting all three control points at once so that no curvature wrinkle appears in the bud — a visual choice, not a value tuned to measurement.
2. Morphology - Flora of North America, Leucanthemum vulgare
The oxeye daisy is the closest real counterpart. Values from the FNA description:
Involucre diameter 12–20+ mm
Ray florets usually 13–34+, rarely 0
Laminae length 12–20(–35+) mm
Disc diameter 10–20 mm
The corresponding values in this implementation (random mean, fully bloomed):
baseRadius = 0.0261, reach = 0.3763 → petal tip radius 0.4024
coreRadius.x (bloom) = 0.126 → disc floret radiusLiterature | This implementation | |
|---|---|---|
Lamina / capitulum radius | 0.667 – 0.706 | 0.687 |
Capitulum diameter | 34 – 60 mm | 805 mm |
Ray floret count | 13 – 34+ | 28 / 30 / 32 / 34 |
- #1
Lamina / capitulum radius
- Literature
0.667 – 0.706
- This implementation
0.687
- #1
Capitulum diameter
- Literature
34 – 60 mm
- This implementation
805 mm
- #1
Ray floret count
- Literature
13 – 34+
- This implementation
28 / 30 / 32 / 34
The proportions are correct, but the absolute scale is approximately 17× larger. The cavern has a radius of 2.28 m and the demo is about walking past human-sized flowers inside it, so the absolute scale is deliberate.
The ray floret count does sit inside the documented range. But 28 + 2⌊4ξ⌋ makes it always even, and places it on only the top four values of the 13–34+ range. There is no morphological basis for the even-only constraint, and the upper bias is a visual choice — fewer petals look sparse at this size. (It is striking that the FNA lists the range as 13–34 with Fibonacci endpoints, but no sources were found confirming that ray floret counts cluster at Fibonacci numbers. The Fibonacci bias that is documented in the literature is in the spiral counts of the disk below.)
A personal note: I considered making the flowers more varied but held back out of concern that it would introduce problems. The implementation turned out to be simpler than expected. Without references to draw on, and given how many attempts the actual implementation challenges required, it was not easy to push further.
3. Floret Disk Arrangement — Vogel (1979)
This is the standard model for how disk florets are arranged at the center of a capitulum.
θ_n = n · 137.50776° (golden angle)
r_n = c √n (constant area per floret)This implementation does not place a point set; it draws the spiral pattern as a texture.
float phyllotaxis = 0.5 + 0.5 * cos(
76.0 * coreRadiusNormalized - 13.0 * coreAngle
);
float diskRings = 0.5 + 0.5 * cos(54.0 * coreRadiusNormalized + 2.0 * sin(coreAngle * 5.0));An Asteraceae capitulum shows two families of spirals winding in opposite directions — parastichies — and their counts are usually consecutive Fibonacci pairs: 34/55 in gerbera, 55/89 in sunflower. Exceptions are on record, including heads where only one direction is distinct or the spirals cannot be counted.
The 13 in the angular term is a Fibonacci number, so it belongs to that family. The 76 and 54 in the radial term match no Fibonacci pair, and more to the point there is only one spiral family. What this implementation draws winds in one direction only, so up close a real floret disk's crossing spirals give way to a single spiral. What pair would actually be appropriate to the capitulum size of this demo remains unconfirmed.
4. Sphere Tracing Prerequisites — Hart (1996)
The problem of "steps skipping over petals" was a violation of the definition in this paper.
Definition 2. A function
f: R³ → Ris a signed distance bound of its implicit surfacef⁻¹(0)if and only if|f(x)| ≤ d(x, f⁻¹(0)). (7)Theorem 1. Let
fbe Lipschitz with Lipschitz boundλ ≥ Lip f. Thenf/λis a signed distance bound of its implicit surface.
macroDistance sits outside the condition of equation (7). Measured: before the wall term was fixed, 8.06% of samples had material inside the radius they claimed; after the fix, 0.29% do.
So what is the step factor 0.60? In the light of Theorem 1 it is an empirically chosen Lipschitz upper bound λ ≈ 1/0.60 = 1.67. The implementation runs exactly the procedure of dividing f by λ to turn it into a distance lower bound, but it obtains λ by measurement instead of derivation. The remaining 0.29% has the same explanation: λ is not the true constant.
5. Volume Integration — Max (1995)
The front-to-back absorption-emission model falls under absorption plus emission in Max's taxonomy. Its discretization here is T_step = exp(−σ_t Δs) together with L ← L + T·S·α. Scattering is replaced by a single directional derivative and a combined forward/backward phase approximation; multiple scattering is out of scope.
6. Rendering Constants
Constants | References | This implementation |
|---|---|---|
| Jimenez (2014), interleaved gradient noise |
|
| Narkowicz (2016), ACES filmic curve approximation |
|
- Constants
52.9829189,0.06711056,0.00583715- References
Jimenez (2014), interleaved gradient noise
- This implementation
interleavedGradientNoise()as-is
- Constants
a 2.51 · b 0.03 · c 2.43 · d 0.59 · e 0.14- References
Narkowicz (2016), ACES filmic curve approximation
- This implementation
acesToneMap()as-is
Values without a basis yet
I could not find a real-world reference for petal sheet thickness, so it is arbitrary. The sheet here is 0.0099 FWHM, which against a petal length of 0.3763 gives length/thickness ratio = 38. No source documenting the actual thickness of Asteraceae ray floret ligules turned up, so I cannot say whether that ratio is right. Thickness feeds both the optics (transmittance) and the marching (minimum step), so if a source appears, sheetThickness and MIN_VOLUME_STEP should be revisited together.
References
Growth, geometry, and mechanics of a blooming lily
Liang, H. & Mahadevan, L. (2011). PNAS 108(14), 5516–5521. https://doi.org/10.1073/pnas.1007808108
Leucanthemum vulgare Lamarck
Flora of North America Editorial Committee. FNA vol. 19. http://floranorthamerica.org/Leucanthemum_vulgare
A better way to construct the sunflower head
Vogel, H. (1979). Mathematical Biosciences 44(3–4), 179–189.
My favourite flowering image: a capitulum of Asteraceae
(Parastichy pairs and their exceptions in the capitulum of Asteraceae) Journal of Experimental Botany 70(21), e6496. https://academic.oup.com/jxb/article/70/21/e6496/2964617
Computer Graphics & Rendering
Sphere tracing: a geometric method for the antialiased ray tracing of implicit surfaces
Hart, J. C. (1996). The Visual Computer 12(10), 527–545.
Optical models for direct volume rendering
Max, N. (1995). IEEE Transactions on Visualization and Computer Graphics 1(2), 99–108.
Next generation post processing in Call of Duty: Advanced Warfare
Jimenez, J. (2014). SIGGRAPH Advances in Real-Time Rendering in Games. https://www.iryoku.com/next-generation-post-processing-in-call-of-duty-advanced-warfare/
ACES filmic tone mapping curve
Narkowicz, K. (2016). https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/