Log inGet started
Package

bokehBlur.renderFeature

Newest version

This package holds more than this page lists. See all of its files in its world.

README.md

bokehBlur

The render feature behind DepthOfField and @builtin::systems.depthOfField.depthOfField. Three compute passes run in the preTemporal stage, on the raster before the temporal resolve:

local orderpassoutput
0dof_cocthe signed radius of the circle of confusion each pixel projects, in pixels, and the widest circle of each field (in front of the focal plane, behind it) in each 16x16 tile
2dof_neighbormaxthe widest circle of each field that can reach each tile
3dof_gathera disc gather over that radius, which is the composite

The circle of confusion

A point at distance d images as a disc whose diameter follows from focal length, aperture and where the lens is focused — the thin-lens relation. The map holds half that diameter: the radius a tap reaches, clamped to maxBlur. Deriving the blur radius that way is what makes fStop and focalLength behave the way they do on a camera instead of being two more arbitrary sliders.

It is stored signed: negative in front of the focal plane, positive behind it. The two fields are not symmetric — a near blur spills over what it occludes and a far blur does not — and the sign is what lets the gather tell them apart.

The sky sits at the far plane, which stands for infinity, and takes the circle the lens images a point at infinity as: the widest circle the far field reaches, the one distant scenery approaches, clamped to maxBlur like every other.

The gather

Taps follow a golden-angle spiral: even coverage of the disc with no stored sample table and no directional structure for the eye to catch.

The taps spread over the widest circle that can land on the pixel, which the tile maxima state: the widest circle in front of the focal plane that can reach the pixel's tile, and the widest behind it out to twice the pixel's own radius, the farthest a far-field circle covers the pixel from. Where no near-field circle wider than the pixel's own reaches it, the taps come in two sets: the pixel's own disc, sampled as densely as with nothing wider beside it, and the ring out to that radius, each ring tap weighted by the share of the disc it stands for. A small circle is sampled as densely as a large one, whatever maxBlur allows and however wide the far-field circles beside it.

Each tap contributes only if the radius of its OWN circle of confusion reaches the pixel gathering it — scatter expressed as a gather. Without that test a sharp foreground bleeds outward onto a blurred background, which is the classic tell of a defocus that was applied rather than photographed.

Weights are 1/spread², so a wide circle contributes proportionally less per sample than a tight one — energy spread over a larger disc. The centre pixel is weighted by the same rule as every tap; seeding it at 1 while taps carry 1/spread² would let it outweigh the whole disc. The gather is the pixel's picture: an in-focus pixel keeps its own colour by the weight of its tight circle, and a defocused one is the disc its circle of confusion states.

Parameters arrive through the dof_params buffer, packed by @builtin::systems.depthOfField.depthOfField.