Modelling a torch beam with a hotspot and spill
The flashlight tool added on 30 September is the first light on the site with a direction. Its beam is a hotspot and a dim spill set by three constants, taken from flashlight forums and a beam model rather than measured from a real torch.
Until 30 September every light on the site shone the same in every direction. That day I added a flashlight to the site’s cursor tools, the first light in the engine with a front, and a beam made of a hotspot, a spill and an edge.
It works like the other cursor tools: press and hold, and it stays where it was pressed and points wherever the pointer goes, throwing a beam across the page that lights whatever responds to light.
A torch beam is a hotspot plus a dim spill
A reflector gathers the LED’s light into a hotspot a few degrees across. What the reflector misses leaves as a wide, dim spill with a visible edge where the lip cuts it off.
The design note takes its vocabulary from flashlight enthusiasts: a hotspot under about 10° across is called throwy, and a true flood is 60 to 120° of spill. Beam profiles are modelled as super-Gaussians: flat on top, steep at the sides.
The site’s beam model is one line: a hotspot term that is half its centre value 8° off the axis, plus a spill at 7% of the centre out to the lip at 32°, and nothing beyond it or behind the torch. The torch’s centre is three times the lamp’s strength. Its colour is the cool white a white LED gives, which is also why it charges glow paint, as a real LED torch does.
Every light can now carry an aim
A light may now carry an aim, a unit vector (a direction of length one). Every pass that lights a point multiplies each light by a beam factor toward that point: the light on the glass, the light under it, the plastic buttons, the glow paint’s charging.
The same formula also runs on the graphics card, in the shared shader code, and a test in a real browser graphics context checks that copy against the original. A light with no aim shines all round, so every other light on the site is unchanged.
In the hand it points down; set down, it follows the pointer
Moving, the torch sits in your hand pointing straight down and throws a hard round hotspot with dim spill. Hold, and it is set down where you pressed and turns to follow the pointer. The beam gets longer, thinner and dimmer as it reaches further, by the inverse square and the slant. Let go and it is back in your hand.
It is drawn from above: a dark anodised body, a knurled grip, the lit rim of the lens, foreshortened as it tilts.
Not yet: lens flare, haze and a measured torch
The design note lists what is missing: the camera’s flare from the torch lens when it points at you, and the visible shaft of the beam in hazy air. The 8°, 32° and 7% are the model’s constants, taken from flashlight forums and a beam model, and not measured from a particular torch.
The tool is in the site’s preview tray, waiting for me to try it.
Sources and notes (4)
- Candle Power Forums, Beam Angles — hotspot, spill, throwy and flood vocabulary
- Map of Flashlights, model description — beam profiles as super-Gaussians
- Flashlight note — the notes this was written from
- Beam model — the notes this was written from
Light & shadowAll 19 parts →
