Feature Library

Film lens: focus pulls, a shutter and a grade (engine-free)

1.03 GPU · 0.54 CPU ms
A still of the Film lens: focus pulls, a shutter and a grade (engine-free) demo
Still
The live demo starts when it’s in view.Watch the take · drag the focus ring or press a subject’s mark · Whip pan (W) · aperture, iris, shutter and film in the panel

The HaTac engine’s cinematic lens, lifted engine-free with the parts of bloom, present and light shafts it drives.

The HaTac engine’s cinematic lens, lifted engine-free with the parts of bloom, present and light shafts it drives: depth of field from a signed circle of confusion with a 24-tap round or bladed pupil on a prefiltered quarter-size surface (eight taps at half size on Medium), the focused subject restored from native colour and depth so type and edges stay sharp; a shutter that smears only the camera’s own travel between rendered frames, from last frame’s view-projection rebased onto this eye; shafts from a low sun through gaps in the skyline on an isolated twelfth-size field; bloom from a coarser first level; and one display pass that mixes the scattering, applies a lift, gamma, gain and highlight shoulder, then grain that moves only when the picture does, a colour fringe and anamorphic streaks from the brightest lights. Focus is set in metres and pulled in dioptres, so a rack moves evenly through the depths. A small host runs the chain on any raw WebGPU page with an HDR target and reverse-Z depth. No three.js, no dependencies.

What it costs a frame

1.03 ms
0.54 ms
GPU
1.03 ms
CPU, median
0.54 ms
CPU, 95th pct
1.04 ms
Draw calls
0
Weight
Moderate

Measured 28 November 2026 on RTX 4060 Laptop, 13th Gen Intel(R) Core(TM) i9-13900H, Chrome 158, 1920×1080 at 1×. 600 frames × 3 rounds, median kept (rounds ranged GPU 0.90–1.36, CPU 0.54–0.59 ms). What ran: The lens alone on the engine’s optics bench (its gallery shader, one cheap pass): a 24-tap six-bladed pupil racking between dials at 4, 8 and 16 m, bloom at a quarter-size first level, shafts at a twelfth, streak, fringe and grain; the camera at rest (the shutter closed). Phones: tiers are being measured next.

How steadily it runs on RTX 4060 Laptop · 13th Gen Intel(R) Core(TM) i9-13900H · reference

Typical frame ?
16.65 ms
1% low ?
56 fps
Varies by ?
±0.48 ms
All metricsRTX 4060 Laptop · 13th Gen Intel(R) Core(TM) i9-13900H · reference
p50p95p9916.02 ms17.96 ms +
How long each frame took. Most frames sit in the tall bars; a long tail to the right is hitching.

Frames run on a 60 Hz timer (a page demo), so most frames take about one tick, 16.7 ms: the spread around it is what matters.

Frames

Median (p50) ?
16.65 ms
p95 ?
17.61 ms
p99 ?
17.88 ms
Slowest ?
17.98 ms
Mean ?
16.70 ms
Standard deviation ?
0.48 ms
1% low ?
56 fps
0.1% low ?
56 fps
Hitches ?
0 of 600
Over budget ?
0 of 600

Main thread

Long tasks ?
0
Long frames ?
0
Event-loop delay ?
0.1 / 1.0 / 1.4 ms

Input

No input during this run.

Memory

JavaScript heap ?
30.9 → 32.7 MB
Growth ?
+1.85 MB

Browser

JavaScript a frame ?
0.56 ms
All tasks a frame ?
2.89 ms
Layout / style ?
0.21 / 0.72 ms
Main thread busy ?
17%

Garbage collection

Collections ?
3 (2 minor, 1 major)
Pauses ?
4.9 ms in all, longest 1.7

What it needs

Renders with
WebGPUNeeds WebGPU: current Chrome and Edge, Safari 26+, Firefox 141+ on Windows.
Your browser
Checking…Looking for WebGPU
Depends on
NothingNo other packages
With an agent
install("film-lens")Your coding agent reads its pitfalls and installs it through the library’s MCP server. Set it up

What it’s for

  1. A cutscene, a trailer shot or an attract loop that racks focus from a subject close by to one far off, with the lights behind melting into bladed discs
  2. A whip pan or a fast camera move that smears like a film camera’s, and stays crisp on a cut, a seek or a held frame
  3. A product or exhibition piece shot with a shallow depth of field, the subject sharp to its silhouette and text drawn over it untouched
  4. A dusk or sunrise scene with shafts through the skyline, bloom on lamps and streaks on the brightest lights, all from one HDR image
  5. A film look for any raw WebGPU renderer: grade, shoulder, grain that holds still on a paused frame, colour fringe and vignette
  6. A director’s camera (shot-director) that hands each shot its focus, aperture and shutter, with one cut flag for all histories

Pitfalls, in brief

  1. The demo needs WebGPU: the jetty is one sphere-traced pass and the lens is a chain of WebGPU render passes reading reverse-Z depth.
  2. The lens reads perspective reverse-Z depth with an infinite far plane (depth = near ÷ distance, sky 0) and works the circle of confusion out from it and the camera’s near.
  3. Keep the sign of the circle of confusion when you filter or reconstruct a silhouette: it is positive behind the focus plane and negative in front.
  4. Normalise the surviving pupil weights after rejecting occluded samples.
  5. Advance the camera history once per rendered frame (the host’s frame()), never per input event or per cue: counting events as frames overstates the pan’s speed and smears a seek.
13 more in brief
  1. Flag every cut, seek and first frame (cut: true): the shutter then stays closed and the bloom’s settle history is dropped.
  2. A gathered depth of field cannot spread a blurred foreground over what is behind it: in the engine a defocused lantern or post kept a hard cut-out outline.
  3. Spread the shutter’s taps with a per-pixel random offset.
  4. Hold the camera still between moves if your scene has hard edges and no anti-aliasing: a camera that breathes by a fraction of a pixel makes window edges and silhouettes crawl, and opens the shutter on every frame.
  5. Resolve fine in-focus detail from the source at the output pixel.
  6. Draw text, live feeds and other front layers after present, at native resolution: they then miss the grain, the grade and the streak, and their anti-aliased edges stay clean.
  7. The grain’s seed moves on only when the camera moves or you say the subject moves (subjectMoving).
  8. Apply the shoulder to HDR highlights before the tone curve, and the grain after it: present does both.
  9. Bloom amplifies a bad pixel into a flash: one sample at the half-float floor, a NaN or an infinity became a one-frame flash a hundred pixels across.
  10. Light shafts come from the sky mask (depth 0), not the sun’s disc, so a sun off screen still fans them in from the edge.
  11. The Low tier keeps only the grade and the vignette: no depth of field, shutter, shafts, bloom or film effects (the engine’s rule, which the host keeps).
  12. maxBokehPx and maxShutterPx are in pixels of the picture you hand the lens: scale them with its height (the demo uses height ÷ 1080) so a phone and a 4K screen show the same discs.
  13. Call prepareSamples(n) before changing the depth attachment’s sample count (1 or 4): the lens and the shafts compile a variant for each.
18 pitfalls in full, the hook-up guide, the module source and its tests come with the part.

Where it comes from

From HaTac. Adapted from published work, named below.

Hannes Andersson: The HaTac engine’s lens, bloom, present and light-shaft modules, their decisions, tests and measurements, and the optics gallery; the library’s host and demo.

Jorge Jimenez, Next-generation post-processing in Call of Duty: Advanced Warfare (SIGGRAPH 2014): The bloom’s 13-tap downsample with a Karis-weighted first level and the tent upsample, and the gathered depth of field’s idea of a prefiltered half-size surface with signed circles of confusion.

Kenny Mitchell, Volumetric light scattering as a post-process (GPU Gems 3, 2007): The light shafts: a march from each pixel toward the sun over the sky mask, weighted by a decay.

Jorge Jimenez, Interleaved gradient noise (Next generation post processing in Call of Duty: Advanced Warfare, 2014): The per-pixel offset that turns the shafts’ step bands into grain, and the grain’s own pattern.

Krzysztof Narkowicz, ACES filmic tone mapping curve (2016): The fitted curve present tone maps with (aces-fit).

Inigo Quilez, distance functions: The demo’s jetty is drawn with his signed distance functions (box, capsule, capped cylinder, torus, ellipsoid).

depth of fielddofbokehapertureirisbladescircle of confusionfocus pullrack focusfollow focusdioptresmotion blurcamera motion blurshutter anglewhip panreprojectionprevious view-projectioncutbloomkarislight shaftsgod rayscrepuscular raystone mapping

Near it in the frame