A flashlight that does not blow out, even up close
· 5 min read · three.js, webgpu, tsl, shaders, lighting
In Ravenhush the flashlight is the only warm light in the world. The art rules say it in one line: cold, wet and dim everywhere, and the torch, a warm white of about 4500 K, is the main warm thing in it, next to the red of the rituals. If the flashlight looks wrong, the game looks wrong. This post is about what is behind it.
One light, always #
The scene has three lights, and the count is fixed for the whole game: a cold hemisphere light for the overcast dusk, a faint directional light for the moon, with no shadows, which lifts the floor and rims the trunks, and the flashlight, which casts shadows. Windows, candles and the ritual glow are not lights at all, they are emissive materials that the bloom picks up.
The count never changes, because in this renderer a different number of lights recompiles every material. The flashlight is one IESSpotLight created at startup, and everything about it afterwards is a uniform or a texture that is rewritten in place.
A beam is a curve #
An IES profile is one curve: relative intensity by angle off the axis, swept round the axis. Instead of shipping a file, Ravenhush generates the curve, as the sum of what a real reflector torch is made of:
- a hot core from the reflector's focus, the hotspot,
- a flood, the broad body of the beam, with a flat-ish top and a soft shoulder,
- a faint spill, light that never touched the reflector,
- a small concentric ripple from a textured reflector,
- and a tail that fades to zero, because a hard cut at the field angle reads as a lens edge.
Each lobe is described by its full width at half maximum, and one line draws any of them:
const lobe = ( d, fwhm, p ) => Math.exp( -Math.LN2 * ( Math.abs( 2 * d ) / fwhm ) ** p );
The exponent p is what shapes the flood: 2 is a bell, and higher values flatten the top and steepen the shoulder. A wide, even flood is what makes a wall look lit by a torch and not spotlit by a stage lamp. The shipped beam is this data, in degrees:
export const FLASHLIGHT_PROFILE = {
beam: 30, // FWHM of the flood
shape: 2.6, // 2 = bell, higher = flatter top, steeper shoulder
hot: 0.3, // weight of the hot core
hotBeam: 11, // FWHM of the hot core
spill: 0.06, // weight of the spill
spillBeam: 60, // FWHM of the spill
ring: 0.03, // the reflector's ripple
ringFreq: 0.3, // ripples per degree
edge: [ 54, 36 ], // zero at 54 degrees, starts fading at 36
flux: 1, // total light relative to the old beam
};
The previous beam is kept as data too. It was a narrow hotspot with a thin skirt, cut at 36 degrees. The new one has the same total light spread wider, so the center is dimmer and the scene is as bright, and a self-test pins both shapes. The look panel edits every number live, and changing one rewrites the texture without touching anything else.

Round by nature #
An IES curve is round, and a real flashlight is not. The faint blotches that a lens throws on a wall come from a cookie, a small texture on the light, and it applies to surfaces only. The air is different.
The same curve lights the air #
The fog is half resolution, with in-scatter from the flashlight's cone, and the floating dust motes catch the beam too. All of them read the same one-dimensional texture as the lit surfaces. That is the rule I care about most: the lit surfaces and the lit air must always agree, so the profile lives in one place and nowhere else.
Close-ups must not blow out #
A torch obeys the inverse-square law, and the law has no limit at the lamp. Walk up to a trunk and its bark turns white. Three things keep it readable, all tuned live in the look panel:
- The torch uses
√(d² + r²)as its distance, so the light stops growing as the distance goes to zero. - The exposure follows a cone of five rays and not only the center one.
- The bloom takes at most a fixed share of the exposed luminance of each pixel.
A fourth trap is the material. At 3 m the torch puts about 130 lux on a surface, and even the 4% reflectance of a dielectric sends enough of it back to read as white. So everything you walk up to is a physical material with a knob for its specular sheen, 0.3 to start with, twice that for iron, and water stays a mirror.
Exposure had its own bugs. The ray that measures how far the eye is from what it looks at used to step a fixed 0.7 m from 0.6 m out, so it stepped over a trunk at arm's length, found what stood 2 m behind it and left the bark burnt white. It now steps 12% of the distance, between 0.08 and 0.7 m, starting at 0.2 m. A friend also pointed out that the inside of a cabin looked one way and the outside another. I measured both at fixed poses, and changed the rule so that near surfaces follow the torch's own law, inside and outside:
| Pose | Exposure before | Exposure after |
|---|---|---|
| Cabin wall at 1.3 m, outside | 0.37 | 0.198 |
| Cabin wall at 1.3 m, inside | 0.15 | 0.198 |
| Trunk at 0.7 m | held between 0.24 and 0.71 | 0.11 |
| The far road | 1.64 | 1.64, untouched |
The eye gets used to the dark #
With the torch off, the first version was pitch black. I wanted something subtle, never blown out: after 0.8 seconds with the torch off, the cold fill light around you and the edge light on the trunks grow, and the eye opens a little past its cap, 18% more exposure, over a couple of seconds. Turning the torch on takes it away at once. At three fixed poses the near trunk, the road and the plants read, while the far forest and the fog stay as they were, and the mean value of the frame went from 6.9 to 8.4.
Ravenhush is free in the browser at ravenhush.vercel.app, and the project page is here.
Related projects
- Ravenhush — Free sci-fi horror game for the browser