3D engine that AI agents drive
Document thin-lens depth of field and add its change note (#896)
Nguyen Xuan And20ec35c90a6
diff --git a/changes/896-depth-of-field.md b/changes/896-depth-of-field.mdnew file mode 100644index 00000000..6b2ccb8f--- /dev/null+++ b/changes/896-depth-of-field.md@@ -0,0 +1 @@+- A camera with an `fStop` now renders with depth of field in the native path tracer's `cycles` kernel, with Cycles' thin lens (round or polygonal aperture, focus distance along the view axis), and a pinhole camera renders the same pixels as before (#896)diff --git a/docs/path-tracer.md b/docs/path-tracer.mdindex f7697d12..eb9f8321 100644--- a/docs/path-tracer.md+++ b/docs/path-tracer.md@@ -36,7 +36,7 @@ A part with a material `subsurface` weight above 0 sends that share of its diffu- The procedural sky when there is no environment map (the sky is black).- Occlusion maps. Normal and metallic-roughness maps are drawn on UV-mapped and on box-projected materials. Material graphs and patterns are drawn through the colour map they bake.- Translucent leaves without a `subsurface` block (foliage looks darker than in the rasterizer), liquids, foam and blended transparency (traced as plain or opaque surfaces).-- Lights seen in mirrors (area lights and spot lights are lit but not visible), caustics, motion blur, depth of field, bloom and colour grade.+- Lights seen in mirrors (area lights and spot lights are lit but not visible), caustics, motion blur, bloom and colour grade. Depth of field is drawn only by the native `cycles` kernel, for a camera with an `fStop` (a thin lens with Cycles' aperture, focus distance and blades; see the render-native README); the CPU, GPU and legacy native tracers draw a pinhole.- Multiple-scattering GGX: rough metal is a little darker than in Blender.## Limitsdiff --git a/packages/render-native/FORMAT-v2.md b/packages/render-native/FORMAT-v2.mdindex 70e244fc..88befdfa 100644--- a/packages/render-native/FORMAT-v2.md+++ b/packages/render-native/FORMAT-v2.md@@ -93,6 +93,8 @@ Total size: **320 bytes** (`20 × 16 B`), alignment: **16 bytes**.| `300` | `4` | `4` | `f32` | `filter_glossy` | Cycles Filter Glossy (`blur_glossy`) factor (`0.0` = off, default `1.0`) || `304` | `16` | `16` | `vec4<u32>` | `reserved_tail` | Reserved (`[0, 0, 0, 0]`) |+The four thin-lens words (`aperture_radius`, `focal_distance`, `aperture_blades`, `aperture_rotation`, bytes 156, 172, 184 and 188) are set by `resolveThinLensParameters` in `pack-input-v2.mjs`, from the camera object that `createCamera` returns for a camera with an `fStop` (or from `options.apertureRadius`, `focalDistance`, `apertureBlades`, `apertureRotation`). A pinhole writes `0`, `10`, `0` and `0`, as before, so its params bytes do not change. Cycles' model: the aperture radius is `focal length (mm) / 1000 / (2 * f-stop)`, a point on the lens (a disk, or a regular polygon of `aperture_blades` corners turned by `aperture_rotation`) is the ray origin, and the ray goes through the point that lies `focal_distance` along `camera_forward` from the pinhole ray (the focus distance is measured on the view axis, not along the ray). The lens sample is the kernel's existing `lens_uv` draw, taken for every sample whether or not the aperture is 0, so depth of field does not move any other random number. A FORMAT-v1 input carries the same four values in the unused fourth float of the eye, forward, right and above vectors (floats 3, 7, 11 and 15 of the 64-float block); the legacy kernel ignores them and `upgradeNativeInputV1ToV2` reads them back.+---## 2. Instance Table — `InstanceRecord` (`@binding(2)`)diff --git a/packages/render-native/README.md b/packages/render-native/README.mdindex 4a6363fc..c132444b 100644--- a/packages/render-native/README.md+++ b/packages/render-native/README.md@@ -42,6 +42,16 @@ Three more options of the `cycles` kernel; `pathRegeneration` is on by default,Numbers, GPU and method: [docs/cycles-parity.md](../../docs/cycles-parity.md), section "Path regeneration, environment compensation and the a-trous filter together (#897)".+## Depth of field (`cycles` kernel)++A camera with an `fStop` is a thin lens in the `cycles` kernel, with Cycles' model. `createCamera(camera, width, height)` (from `src/path-tracer.js`) adds `apertureRadius`, `focalDistance`, `apertureBlades` and `apertureRotation` to the view it returns, and `buildNativeInput` and `buildNativeInputV2` pack them; a camera without an `fStop` is a pinhole and packs the same bytes as before.++- `fStop`: the aperture radius is `focalLength / 1000 / (2 * fStop)` metres. The focal length is `focalLength` (mm), or the one that gives `fov` on a sensor `sensorWidth` mm wide (default 36) across the image.+- `focusDistance` (metres, along the view axis; default: the distance from eye to target).+- `apertureBlades` (0 for a round aperture, or 3 to 64 for a regular polygon) and `apertureRotation` (degrees).+- Lower-level: pass `apertureRadius`, `focalDistance`, `apertureBlades` or `apertureRotation` (radians) on the camera or in the pack options. Values the kernel cannot use throw a `RangeError` that names the field and what to pass.+- The legacy kernel draws a pinhole. `bench/cycles-parity/trace-native.mjs` and `render-cycles.py` take `--f-stop`, `--focus-distance`, `--aperture-blades`, `--aperture-rotation` (degrees) and `--sensor-width`, so the same camera goes to both renderers. Layout: [FORMAT-v2.md](./FORMAT-v2.md). Measurements: [docs/cycles-parity.md](../../docs/cycles-parity.md), "Depth of field (#896, slice D1)".+## DispatchesThe Cook kernel splits a render into dispatches that each aim for about 0.5 s, sized from the time of the previous one, so a heavy scene does not run past the driver timeout and lose the device. `samplesPerDispatch` fixes the batch instead. A lost device raises an error that names the dispatch and how to lower the work per dispatch. The split is tested in `tests/dispatch.rs` (`cargo test --test dispatch`).