Lensman
An Optical Lab in Three.js: vintage lenses from my museum on a virtual camera, in a real-time Bieszczady landscape built from elevation data and shaders.
A camera you can take into the mountains
A specification table can tell you that a lens has eight blades and opens to f/2. It cannot show you what that does to a sunrise. So I built the Optical Lab on lensman.pl: take a lens off the museum shelf, put it on a virtual camera, carry it into the Bieszczady and look through it.
- React
- TypeScript
- Django
- Python
- HTMX
- Tailwind
- PostgreSQL
- Docker
The page is the viewfinder
The Lab opens above a sea of fog at dawn, with a hiker on the path in front of the camera. The scene fills the screen and the controls sit along the bottom, as they would in a camera: place, lens, focal length, aperture, focus, exposure, time and date. Drag to look around, click to focus, turn a dial and the picture answers.

It starts on a shelf
The Lens Museum on lensman.pl holds 109 lenses from my collection, each with its specifications and studio portraits. It is the catalog the Lab grew out of.

The object
This is a Helios 44-2. The table says 58 mm, f/2, eight blades, six elements in four groups. All of it is true, and none of it tells you why people still look for this lens.

And what it sees
The same Helios below the summit of Tarnica, wide open. The hiker holds focus, the cross softens behind them and the grass in front melts.

Choosing the glass
Ten museum lenses can be mounted, from a 14 mm Samyang to a Pentacon 200, along with three generic zooms. Django serves the specifications from the museum and adds what a table leaves out: swirl, cat's-eye bokeh, bright disc edges, vignetting, color fringing, glow and flare.

I tuned these profiles as visual approximations. They explain the character of a lens and do not replace an optical bench.
Render the world, then photograph it
React Three Fiber holds the scene, but I took over its render loop. Three.js first draws the world into a half-float HDR target with a depth texture. A chain of my own shader passes then acts as the lens, and exposure and tone mapping come last, so the sun is still far brighter than white when it gets blurred.
- Scene: terrain, sky, grass and hiker, rendered to HDR color and depth.
- Focus: a thin-lens circle of confusion for every pixel, from focal length, f-number and focus distance.
- Bokeh: a 48-sample gather at half resolution, shaped by the aperture blades and bent by the faults of the selected lens.
- Light: sunstar and flare in HDR, followed by metering and tone mapping.

Above is one frame at f/2 and at f/16. Keeping the lens separate from the world pays off twice: an A/B comparison runs two lenses over a single scene render, and in a still frame a new aperture only reruns the optics.
A sunstar from a Fourier transform
I did not paint the rays. The Lab draws the aperture on a 512 by 512 grid, runs an FFT over it and uses the resulting diffraction pattern as a texture, scaled by wavelength for each color channel. Straight blades give the familiar rule for free: an even count makes as many rays, an odd count twice as many. The shader also samples depth across the sun's disc, so the star fades behind a ridge and flickers through grass.

Mountains from measurements
The land starts as 40 by 40 kilometers of Copernicus elevation data. At each of the seven places a one-meter laser model from GUGiK, the Polish mapping agency, adds the crags and the shape of the ridge. Each place travels as its own pack of 0.3 to 1.1 MB, loaded only when you go there. The rest is made in code: there are no downloaded models or photographic textures for the hiker, grass, stones, clouds or sky.

The ground moves with the camera
Walking broke the original assumption of one fixed viewpoint. The terrain is now a polar mesh with no heights in it, dense at your boots and sparse toward the horizon. It follows the camera while the vertex shader reads the ground from height textures. The CPU repeats the same calculation for the tripod, the stones and the hiker's feet, so they land on the ground the GPU draws.

That opens 27 kilometers of real trails from OpenStreetMap across the seven places, walked with the keyboard or with buttons on a phone. At a junction you look where you want to go. The URL keeps the spot, so a composition can be shared as a link.
Seven places to set up a tripod
The map connects Polonina Wetlinska, Smerek, Polonina Carynska, Rawki, Tarnica, Bukowe Berdo and Halicz, with the marked trails and a cone showing what the current lens takes in. Pick up the hiker and every stretch you can walk lights up.

Drop the hiker, stand on the trail
The map has its own pegman. Drag the little hiker from the corner onto a glowing trail, or tap the hiker and then the trail, with a mouse or a finger. It snaps to the path, and you are standing there with the hiker 12 meters ahead, in focus, looking along the trail.

From there the arrow keys walk on. Each place keeps its own detailed ground, so a walk ends at that place's edge and the pegman makes the jump to the next one.
Waiting for the light
The sun follows the place, date and time through a simulated atmosphere. Meadows change with the season, fog fills the valleys, and there is cloud, rain and snow. After dark come the Moon, stars, the Milky Way, meteors and passing satellites. As in real landscape photography, much of the picture is choosing when to be there.

From 109 milliseconds to a moving picture
An early version needed 109 ms for a foggy dawn on my laptop's integrated Radeon, about 9 frames per second. I removed one layer at a time to see what it cost, then prototyped the fixes in order:
- Reversed depth instead of logarithmic, so the GPU can reject hidden pixels early again: 109 to 73 ms.
- Drawing near to far, with the sky last: 70 ms.
- Levels of detail for shrubs, which had been 8.2 of the 12.8 million triangles: 49 ms.
- A cheaper terrain shader that deals with fog first: 37 ms.
- Culling terrain and grass outside the view: 33 ms.
Adaptive resolution covers the remaining gap by giving up pixels before smoothness. Before the laser terrain grew beyond Tarnica, I measured 54 to 60 fps standing at the seven places and 56 to 59 walking on Tarnica. Those runs used headless Chromium on that one laptop, mostly at half render scale. With animation off, an idle frame costs zero draw calls.
Still one website
The Lab is a React island built with Vite inside the Django site that also serves the museum and my photography, next to pages made with htmx and Alpine.js. One application serves Polish and English and runs with Docker Compose on my homelab.

Go and take a picture
Start in the fog, or go straight to Tarnica and walk. Open the aperture all the way, put something close to the camera and wait for the sun.
Data: Produced using Copernicus WorldDEM-30 (c) DLR e.V. 2010-2014 and (c) Airbus Defence and Space GmbH 2014-2018 provided under COPERNICUS by the European Union and ESA; all rights reserved. Digital terrain model by GUGiK (geoportal.gov.pl). Trails (c) OpenStreetMap contributors, available under the Open Database License 1.0.
