Rebuilding the light engine so the picture stayed identical
Over two days, 27 and 28 September, I rebuilt the site’s light engine in about fourteen steps. My condition was that neither the quality of the lights nor the way they look could change. The engine came out as one ordered model of causes, and quiet on a still page.
Each step was checked against the one before by pixel comparison, with the page’s randomness seeded so that two runs draw the same frame, and had to come out the same at rest.
27 September: each pane described once, as causes
First, every pane got a description of what it is made of: <Pane material="frosted-float" thickness={18} ...>. Every property is a cause, written onto the element that the light passes (the stages that draw the light) already measure. The frosted-float preset has refractive index 1.518 (how much it bends light), Abbe number 60 (a measure of how little it splits colours) and frost 0.6.
Next the lights became a list, and the whole scene was measured once a frame in a fixed order: read every rectangle, then compute, then write. Then one compositor, the code that stacks the layers into the final picture, got the order of every pane layer: bokeh, refraction, liquid, glare, under, surface.
The engine stopped working when nothing moved
Two steps made the engine quiet. Eight animation loops moved onto one scheduler; four of them had never slept. The light passes shared one WebGL context (the page’s connection to the graphics card) instead of each making its own.
36 knobs became constants
I set causes and the physics sets effects, so one step locked 36 knobs that set an effect directly (Fresnel, gloss, refraction, the floor’s light and shadow gains and so on) into model constants, with no control left for them on the lab page. Twenty-eight causes remain.
The last optics step made smudges and scratches change the light under the glass as well as on it: a smudge takes about half the beam and returns a soft glow, a scratch is a tiny cylinder lens.
28 September: everything comes from the lights
On the second day each light got a kind, height, radius, colour and gain, and the room became a light in the list. The glass and floor passes then looped over the lights, up to four.
A rename in the floor shader (the program that draws the floor on the graphics card) broke it silently: the pass logged an error and went dark while every other test passed. The end-to-end test, which runs the whole page, now fails on any shader or link error.
The CSS and liquid glass moved behind adapters (one common interface), and the camera became its own module. The last step added stacks of panes, solved with the full s and p Fresnel equations, which give how much light a surface reflects for each of the two polarisations (4.2% at normal incidence in its tests).
One regression, from darkening the room
After the last step I could no longer see three things: the reflection, the edge light and bloom, and light travelling through the glass to the other edges. Screenshots at the same lamp position traced all three to an earlier change that darkened the room, not to the light steps before it.
I had that change put back. Room brightness went back to 1, and the reflection, resting edges and bloom came back together. The project log does not say how the cause was found, only that screenshots at the same lamp position placed it.
Sources and notes (4)
- List of physical properties of glass (Wikipedia) — soda-lime index 1.518 and Abbe number about 60 for the frosted-float preset
- Fresnel equations (Wikipedia) — the s and p equations used for stacks of panes
- Glass presets — the notes this was written from
- Light catalogue — the notes this was written from
Light & shadowAll 19 parts →
