Skip to main content

Module camera

Module camera 

Source
Expand description

The shared 3D camera (ADR-0257): an orbit camera that projects world points through a perspective lens, for every pipeline that draws a 3D primitive.

Two halves, one function. CAMERA_WGSL is prepended to each 3D pipeline’s shader and projects on the GPU; CameraView is the same matrix on the CPU, where a scene clips its primitives against the near plane and culls what lies outside the frustum before anything is uploaded. The two are held equal by a test that runs the WGSL project() in a compute pass and compares it with CameraView::clip on a fixed set of points.

§The space

The camera orbits the world origin. yaw turns it about the world’s +y axis, pitch raises it above the xz plane, and distance is how far the eye sits from the origin. At yaw = 0, pitch = 0 the eye is on +z looking down -z, with world +x to the right and +y up on screen.

Clip space puts the view depth in w, so the perspective divide is a divide by the distance in front of the eye along the view axis. The z row is zero: no 3D pipeline has a depth attachment, because additive light needs no occlusion (ADR-0044).

§Depth of field is per primitive, not per pixel

Lens::coc is the thin-lens circle of confusion at a view depth, aperture * |depth - focus| / depth, in pixels and clamped to the tier’s cap. A pipeline evaluates it at each endpoint of what it draws and widens the primitive by it, so one line can be sharp at the focal plane and soft at both ends (ADR-0257). The additive scenes this serves have no single depth per pixel for a post-process blur to read.

§The framing controls keep their meaning

The aspect is the render target’s, handed in by the caller, never an internal grid’s (ADR-0037). The engine-wide zoom divides the field of view, and pan_x / pan_y shift after the projection, in the same units the 2D ViewTransform pans in: pan_x is divided by the aspect on the way to clip space, so one unit of pan moves the picture the same number of pixels on both axes.

Structs§

Camera3d
An orbit camera, as a preset binds it (ADR-0257).
CameraUniform
The Camera uniform CAMERA_WGSL declares, as it is uploaded.
CameraView
One frame’s projection: the matrix CAMERA_WGSL multiplies by, and what the CPU needs to clip against it.
Lens
A lens: the CPU half of coc() in CAMERA_WGSL, with its inputs made safe once.

Constants§

NEAR
How close to the eye a primitive may reach before it is clipped, in world units. A point nearer than this projects through a divide by nearly zero.