Which sides of a glass pane can you actually see?
A pane of glass shows a side face only when your eye is on that side of its edge, and only as wide as perspective allows. Building the sides, and the light through the glass, from geometry instead of fixed settings made both behave as real glass does.
In this piece
- A side face shows only from its own side of the edge
- Perspective alone sets how wide a side looks
- The eye no longer follows the pointer; scrolling moves the panes
- The scroll parallax is only half physical
- Light through the glass throws a shadow with a bright seam
- The shadow softens with distance because none of it is a setting
- Three more faults found by looking
- One edge width for everything, and shadows on for everyone
- Still open: the parallax, and a check against a real pane
A pane of glass on a screen has four side faces a few pixels wide, and they make it look like a slab instead of a flat rectangle. Between 26 September and 1 October I worked out which of those sides you may see, and how wide, from geometry alone. The same approach gave the light passing through the glass a shadow that behaves.
My photographs are wet streets, neon and glass, so the site has panes of glass. A pane has a front face, a back face and four sides.
A side face shows only from its own side of the edge
On 26 September the side strip was a dichroic rainbow, the shifting colours of coated glass. I replaced it with what photographs of stacked clear sheets show: float glass (ordinary window glass) seen edge-on is deep teal, because iron absorbs along the long path. On the 27th I calibrated the edge against my reference photographs of clear float glass. The record disagrees on how many: four close-ups in the code comments, five in the project log.
On the 29th, in about forty minutes between 13:27 and 14:08 UTC, three changes fixed three faults I had noted. First, a pane whose left and right edges are in view should have left and right sides, so panes got them. A band as wide as the view has no left or right edge in sight, so it gets none.
Second, the panes in the lab, the site’s private page of test panes and settings, showed top and bottom faces at once. For a flat pane that is impossible: you can never see the top and bottom at the same time.
The cause was a resting minimum: every face kept a small opening, so all of them showed. The replacement rule is geometry: a face shows only when your eye is on its side of that edge. The top face shows when the top edge is below your eye, the bottom face when the bottom edge is above it, and the same for left and right.
A pane that straddles your eye shows none. A unit test holds it: no opposite pair, for any eye.
Perspective alone sets how wide a side looks
Third, far too much of each side was showing; seen from the front, a side should be a thin strip. The width now comes from perspective and nothing else. The front arris (the eased corner of the glass) sits some offset past your eye, and the back one is foreshortened toward it: width = offset × thickness / (distance + thickness).
An 18 px slab with its edge half a view past the eye shows under 5 px of side; the lab’s small panes show one to three. By my arithmetic, on the unit test’s geometry (a 1,280 px screen, eye at 1.2 widths), an edge 400 px past the eye gives 4.6 px.
The next day I wanted one view to show a lot more of the top side of the pane. The fix was two lab settings, viewing distance and glass thickness, in place of a bigger constant. At the default distance an 18 px pane shows 3-4 px of its top face; at half a screen width, 8 px.
The eye no longer follows the pointer; scrolling moves the panes
Everything above needs an eye. On the 27th the page stopped being seen from one fixed point. The eye sits 1.2 viewport widths in front of the screen and followed the pointer by a fraction, default 0.6. A photograph some gap behind the glass slides on it by eye × gap / (distance + gap), by similar triangles: about 16 px each way at the defaults.
Things resting on the glass do not move.
On the 29th the image behind the glass still was not parallaxing, that is, shifting against the glass as the eye moves. It moved 28 px in one of the site’s two glass renderers (CSS glass) and none in the other (liquid glass), which was covering the live photograph with a cached copy. That was fixed.
On 30 September I decided the hero images should not pan with the mouse, and that only scrolling should move the parallax. The default went from 0.6 to 0, and the mechanism stayed as a lab setting, “Viewpoint follows pointer”. At the default the eye stays straight in front of the screen.
The sides still answer to the page, because scrolling carries a pane through the view while the eye stays put. By the rule above, a pane in the lower half shows its top face, one crossing the middle shows none, and one in the upper half shows its bottom face. That is from the code; I have not measured it in a browser.
The scroll parallax is only half physical
The same triangles say a photograph lags its glass by gap / (distance + gap) of the scroll. On 30 September I built that as a preview, behind a switch on the site. On the home page’s Kind words band the current preset lags the photograph 27.8 px per 200 px of scroll, where the physical lag at the default 70 px gap is 7.7 px, about a quarter.
The glass would have to stand about 260 px off for the current feel. The physical version is a preview; the default is still the preset.
Light through the glass throws a shadow with a bright seam
If the lamp shines through a pane, what lands on the photograph behind? On 26 September a new layer traced, for each point on the photograph, back toward the lamp to the glass plane. Outside the pane nothing is in the way.
The bevel (the sloped rim of the pane) is a lens: dark where it throws light away, with a bright seam where that light lands, which is the edge of the shadow a glass of water throws. The face passes slightly less light.
The second version took a swimming-pool floor as its picture. Twenty minutes later I changed it: a pool-floor net only happens when glass is wavy, and these panes are flat. The face now throws no pattern, the frost spreads the beam into a wider, dimmer pool, and the bevel acts as a prism. The wave caustic (the net of bright lines a wavy surface focuses) waits behind a waviness setting, default 0.
On the 29th I added that the glass surface itself must bend what is seen through it, as well as throw caustics. The wavy surface became one model read twice: its curvature gives the caustic, its slope bends the view.
The shadow softens with distance because none of it is a setting
When I replaced one fixed sharpness, the change listed the causes instead. Brightness falls as cos θ / d², where θ is the angle the light arrives at and d its distance, and less gets through at a slant. An edge softens by lamp size × gap / (height − gap), stretched by 1 / cos θ. Frost spreads light further over a longer slant path.
With the lamp 170 px and then 300 px below the edge of a band on the hero, the shadow rim’s width goes from 37 to 57 px and its contrast from 28 to 17. Before, it was a fixed 17 px or so at both.
Three more faults found by looking
The first came when I wanted stronger cast light. The setting for light through glass was 0.35, so clear float glass lost two thirds of its light, where real float glass passes about 90%; it went to 0.9.
The second was a hard line near the top of the lab. A ray stopped at the first pane it crossed, so where two panes overlap, the light on the floor beneath flipped to the lower pane’s answer in one pixel. Each pane now multiplies in what it lets through, and the 156 to 150 step down a column is gone.
The third: on 1 October I noted that light through one pane and then another is changed by both, so each pane now filters at its own height.
One edge width for everything, and shadows on for everyone
Underneath sits a decision from 26 September. The same pane edge had been defined four times, at 26, 40, 90 and 150 px, so one edge’s bend, light and shadow landed in different places. One width of 40 now serves them all.
On 1 October shadows through and on the glass went on for everyone. They are correct behaviour and a fix, so I did not want them behind a switch to try.
Still open: the parallax, and a check against a real pane
The physical scroll parallax is a preview, and following the pointer is off by default. The side-width formula has unit tests; the record shows no comparison of its widths with a real pane.
Sources and notes (7)
- Clear float glass data sheet (Vitro) — float glass is slightly green and deepens with thickness
- Total internal reflection (Wikipedia) — the glass's side faces and echo
- Soler and Sillion 1998, convolution soft shadows — the shadow of a flat caster through the glass
- Ony's reference photographs of clear float glass — his photographs, as recorded in the commit that calibrated the edges
- Edge side model — the notes this was written from
- Viewpoint — the notes this was written from
- Shadow model — the notes this was written from
Light & shadowAll 19 parts →
