Making smudges and scratches block light by opacity
The site’s panes carry smudges and scratches from two photographs, so they look handled. Each pixel of a mark now blocks as much light as its own opacity says, and a scratch only takes light away.
In this piece
- The first grime filter lit the whole pane
- Two photographs, hex-tiled so they do not repeat
- A smudge on the face dims the photograph beneath it
- The rule: a mark blocks light in proportion to its opacity
- The correction: a scratch does not make a bright copy of itself
- On the face, marks show where the lamp rakes, and fade before the edge
- Still open: no comparison with a real handled pane
The panes on this site are meant to look handled, which means smudges and scratches. The hard part is deciding what a mark does: how much light it blocks, how much it scatters, whether it ever adds any.
The answer I settled on is that each pixel of a mark blocks as much light as its own opacity says, and that a scratch only takes light away. Between 26 and 28 September the marks were made to behave, and on 30 September the scratches were corrected.
The first grime filter lit the whole pane
On 23 September the grime was moved into a layer drawn by the page, and on 24 September I put the smudges back the way they were. That attempt failed because I had derived a contrast curve from the texture’s percentiles and called it measured, but I measured the input, not the output. Run over the real map, the filter lit 11% of every pixel on the pane and blew 5.9% of them past 0.5.
The result read as generated, and the arithmetic was the reason; a wiped pane has only a few marks on it.
The fix was to draw the grime in the light pass again, the stage that draws the lamp’s light on the glass, where a mark shows only where the lamp rakes across it. The same day I also removed a hashed noise texture, so the pane’s texture comes only from the supplied smudge and scratch photographs.
Two photographs, hex-tiled so they do not repeat
On 26 September the marks changed from one packed 2×2 atlas (four textures in one image) to two photographs, each its own layer. The smudge photograph is 1024 px square and the scratch photograph 2048 px, both greyscale, with the mark’s amount in the brightness and black where the glass is clean.
They come from frames 09 and 14 of a glass texture pack, run through a preparation script of mine. It crops square, high-passes (removes slow changes in brightness) to throw away the studio lamp’s hot spot, which tiled would repeat as a blotch, and makes each seamless. My to-do list flags that the pack’s licence is unchecked.
The smudge map averages 0.080 across the whole image and the scratch map 0.014: most of the glass is clear, as a wiped pane is. The script matches each map’s histogram, its spread of brightness values, to the channel it replaced. Without that, the script’s notes say, the scratch map let seven times as many pixels through and the pane read as rain.
A plain grid repeats and the eye finds it at once; the atlas gave itself away as identical tick marks along a lit edge. The shader (the program the graphics card runs for each pixel) now uses hex-tiling (Mikkelsen, 2022). The plane is covered in hexagons, each reading the photograph at its own pseudo-random offset. Every point blends the three hexagons around it, with weights raised to the power 7 so one sample dominates and the blend does not average into grey.
It uses offsets only, with no rotation, because both photographs have a grain. Wiping strokes and hairline scratches run one way, and rotated cells would each point a different way and draw the hexagons.
The notes at the top of the preparation script still say the shader samples with a random offset and rotation. The code and the project log say offset only, and I have gone by the code.
Each layer is its own site setting, so either photograph can be swapped from the admin portal without touching the other.
A smudge on the face dims the photograph beneath it
Until 27 September the marks touched only the light on the glass, the lamp catching a smudge on the face. At 02:14 UTC that morning I let the light through the pane read them as well. The marks now sit in one piece of shader code shared by the light on the glass and the light under it, and the light under the glass reads them at the point where each ray crossed the pane. So the smudge that catches the lamp on the face is the one that dims the photograph beneath it, in the same place.
The model has three constants, fixed and not controls. A smudge takes 0.55 of the direct beam out and returns 0.25 as a soft glow: dimmer and softer, the halo of a greasy window. A scratch, in that first version, did the opposite. It added a bright line at 1.8 times the beam, because I reasoned that a groove is a tiny cylinder lens gathering light.
The rule: a mark blocks light in proportion to its opacity
The marks still went through a clarity threshold, a smooth cut-off that sets everything below the “Grime clarity” setting (default 0.34) to nothing. That is good for cleaning a pane, but it makes marks all-or-nearly-all. On 28 September I set the rule, with a preview switch to try it: the shadow cast and the light let through by the scratch and smudge layers follow the opacity of each pixel in that layer.
That made the marks one function, read by both the light on the glass and the light under it. Each pixel covers exactly as much as its value in the layer says: a faint mark blocks a little, a dense one a lot. Under the glass the pattern is also averaged over five samples spread by the shadow model’s penumbra (the soft fringe of a shadow), so marks soften like any other shadow.
The correction: a scratch does not make a bright copy of itself
On 30 September I noticed that the scratch and smudge layers were casting light as well as shadow: under each speck was a light dot of the same brightness and colour as the speck itself.
That was the cylinder lens. Every speck in the scratch layer threw a bright copy of itself, at 1.8 times the beam, onto the photograph; the project log mentions white blobs under the “Kind words” band. The reasoning in its place: a groove only redistributes what crosses it, and grit scatters light out of the beam, so at this distance, through the frost, the effect is a thin darkening.
The brightening term was removed, and a scratch shadow of 0.6 takes light away instead. Nothing is added back except the smudge’s glow. A test now fails if the shader still contains the old term or if any term adds light under a scratch.
One comment above that code still describes a scratch as a line brighter than its surroundings. It is out of date; the code and the test say otherwise.
On the face, marks show where the lamp rakes, and fade before the edge
On the glass itself, a mark shows where the lamp rakes across it. A scratch’s glint is scaled by 3.4 and a smudge by 1.25, both times a “handled” factor that comes from a wear channel with a floor of about a third. A photograph standing on the glass cuts the rake by up to 88%, not to zero, because grime in a shadow still catches the room. The lab, the site’s private settings page, has three controls for this: “Grime, raked” (2.4), “Specks” (9.5), “Grime clarity” (0.34).
Two later changes shaped the edges. At some point before 1 October I noticed I could see where the layer cut off, and on 1 October I ruled out scratches and smudges on the edges and sides. The marks now fade across the bevel (the sloped rim of the pane), none on its outer 35% and full on the flat face, so there is no line where they stop.
That fade applies both on the glass and in the light under it.
Still open: no comparison with a real handled pane
The proportional rule started as a switch I had to approve. On 1 October I decided that a fix to an existing feature should be the default without a trial, and a note in the code from that day moves the rule into the list of previews that are on by default. I have not checked that in a browser for this piece; I read it from the code.
The 30 September and 1 October follow-ups are in the code; the first has a test. I have not compared the marks against photographs of a real handled pane.
Sources and notes (5)
- Ony's glass texture pack photographs — the smudge and scratch photographs he supplied, as recorded in the commit
- Map-building script for the texture pack — how his photographs were turned into the two layers
- Hex-tiling — the notes this was written from
- Surface layers — the notes this was written from
- Pending database work — the notes this was written from
Light & shadowAll 19 parts →
