# Cameras

> `@typegpu/kit` 0.1.0. If it is installed, read `node_modules/@typegpu/kit/docs/` instead.

Orbit, flat, custom and layered cameras with shader accessors, eased motion and last-frame views.

> `import { cameras } from '@typegpu/kit'`: `cameras.custom(root, options?) → CustomCamera`, `cameras.layered(root, count) → LayeredCamera`, `cameras.turn(goal, dx, dy, options?) → G`, `cameras.pan(goal, dx, dy, { height }) → G`, `cameras.eyeOf`, `cameras.orbit`, `cameras.flat`, `cameras.hitHeight`. Provides orbit, 2D, custom and layered cameras through the `cameras.current` accessor. **records** `update(dt)` once a frame, to ease the view towards its goal, or `jump()` to go there. **owns** 2 buffers: the current and previous camera uniforms. Writes when the view or size changes and once more in the next frame. `cameras.layered` owns 1 buffer, writing a layer's view when it changes. **injects** hook: `cameras.current`, for every shader that projects, and `cameras.reversed` from a camera created with `reversed: true`. **GPU functions** `toClip`, `farDepth`, `nearerDepth`, `forwardOf`, `lensOf`, `distanceOf`, `rayOf`, `towards`, `sees`. **accessors** `current`, `reversed`. **schemas** `Camera`, `Ray`. **types** `Out3`, `CpuRay`, `CpuView`, `CameraBase`, `Orbit`. `src/cameras.ts`; afterimage, benthos, blockfall, censer, classroom, cloister, dominoes, ember-mirror, falling-sand, fireworks, fishtank, forest, hex-isle, jellies, jelly-world, kinetic, lattice, night-market, ocean, platformer, quiver-trees, raymarch, robot-arm, skeletons, solar-system, sph-sculpt, spider, stampede, star-map, survey-model.
>
> `DepthOptions`, taken by `custom`:
> - `reversed?: boolean` Projects reversed depth, 1 at the near plane and 0 at the far plane, for a description created with `depthClear: 0` and `depthCompare: 'greater'`. Default false.
>
> `TurnOptions`, taken by `turn`:
> - `sensitivity?: number | undefined` Sets the radians a dragged pixel or point turns. Default 0.008.
>
> `PanOptions`, taken by `pan`:
> - `height: number` Sets the view's height in the units of the drag, one camera distance of panning.
>
> `OrbitOptions`, taken by `orbit`:
> - `size: SizeSource` Supplies the size used for the aspect ratio, such as the canvas surface.
> - `target: readonly [number, number, number]` Sets the initial point that the camera orbits and looks at.
> - `distance: number` Sets the initial distance from the target to the eye, in world units.
> - `yaw?: number` Sets the initial yaw in radians around +y. Default 0.
> - `pitch?: number` Sets the initial pitch in radians above the horizon. Default 0.6.
> - `fov?: number` Sets the initial vertical field of view in radians. Default 0.8.
> - `near?: number` Sets the initial distance from the eye to the near clipping plane, in world units. Default 0.1.
> - `far?: number` Sets the initial distance from the eye to the far clipping plane, in world units. Default 500.
> - `pitchRange?: readonly [number, number]` Limits the goal pitch to this range, in radians. Default -1.5 to 1.5.
> - `distanceRange?: readonly [number, number]` Limits the goal distance to this range, in world units. Default `near * 2` to `far / 2`, using the option values.
> - `floor?: (x: number, z: number) => number` Returns the lowest height the eye may reach at a point x, z, in world units, such as a terrain's height plus a margin. Default no floor.
> - `reach?: (target: ArrayLike<number>, yaw: number, pitch: number) => number` Returns how far the eye may go from `target` along a yaw and pitch, such as the distance to a room's wall less a margin. Default no limit.
> - `damping?: number` Controls how fast the view approaches the goal. Default 14.
> - `reversed?: boolean` Projects reversed depth, 1 at the near plane and 0 at the far plane, for a description created with `depthClear: 0` and `depthCompare: 'greater'`. Default false.
>
> `FlatOptions`, taken by `flat`:
> - `size: SizeSource` Supplies the size used for the aspect ratio, such as the canvas surface or a low-resolution target.
> - `height?: number` Sets the initial view height in world units, required without `fit`. Default the height `fit` gives.
> - `fit?: { readonly width: number; readonly height: number; readonly mode: 'cover' | 'contain' }` Fits a `width × height` world rectangle centred on the view: `cover` fills the view with it, cropping its longer side, and `contain` shows all of it, leaving bands. Default none.
> - `center?: readonly [number, number]` Sets the initial view center in world units with +y up. Default the origin.
> - `snap?: number` Rounds the view center to multiples of this distance in world units, such as one texel of a pixel-art target. Default 0, which disables rounding.
> - `damping?: number` Controls how fast the view approaches the goal. Default 8.
> - `reversed?: boolean` Projects reversed depth, 1 at the near plane and 0 at the far plane, for a description created with `depthClear: 0` and `depthCompare: 'greater'`. Default false.
>
> `HitOptions`, taken by `hitHeight`:
> - `grazing?: number` Misses rays whose direction's y is nearer 0 than this, so a ray near the horizon finds no hit far away. Default 0, which misses only rays parallel to a level plane.
> - `reach?: number` With a height function, the farthest distance along the ray to search, including a hit exactly there. Default 1000.
> - `step?: number` With a height function, the first step of the search along the ray. Default `reach / 1000`.
>
> `Camera`, a schema:
> - `viewProjection: d.mat4x4f` Transforms world coordinates to clip space.
> - `position: d.vec3f` Gives the eye position in world space.
> - `right: d.vec3f` Gives the unit x and y axes of the view in world space, for quads that face the screen.
> - `up: d.vec3f`
>
> `Ray`, a schema:
> - `origin: d.vec3f`
> - `direction: d.vec3f` Gives the unit ray direction.
>
> `CustomCamera`, from `custom`:
> - `write(view, projection)` Writes the camera from a view matrix and a projection matrix.
> - `uniform: TgpuUniform<typeof Camera>` Holds the camera view from creation onwards.
> - `inject()` Fills `cameras.current` for the pipelines created from the configuration it is piped into.
> - `project(point, out)` Projects a world point to screen coordinates.
> - `projectAt(point, out)` Projects a world point to a point of the surface, as `rayAt` takes it.
> - `ray(x, y, out)` Writes the ray through the screen point `x`, `y` into `out`, as `rayOf` computes it on the GPU.
> - `rayAt(x, y, out)` Writes the ray through a point of the surface into `out`, as `ray` does.
> - `previous: TgpuUniform<typeof Camera>` Holds the previous frame's view for motion vectors and reprojection.
>
> `LayeredCamera`, from `layered`:
> - `layers: number` Reports the number of views.
> - `uniform: TgpuUniform<d.WgslArray<typeof Camera>>` Holds the views, one `Camera` per layer, zeros until written.
> - `inject()` Fills `cameras.current` with the view of the layer drawn, read through `passes.layer`.
> - `write(layer, view, projection)` Writes the view of `layer` from a view matrix and a projection matrix, as a custom camera's `write` does.
>
> `OrbitCamera`, from `orbit`:
> - `goal: Orbit` Sets the desired camera pose.
> - `pose: { readonly yaw: number; readonly pitch: number; readonly distance: number; readonly fov: number; readonly target: readonly [number, number, number] }` Reports the eased pose, the view as drawn while it approaches the goal.
> - `clip: { near: number; far: number }` Sets the distances from the eye to the clipping planes, in world units.
> - `aspect: number` Reports the width divided by the height of the current view, from `size` at the last move.
> - `update(dt)` Eases towards the goal by `dt` seconds and writes the uniform if the view changed.
> - `jump()` Moves the view to the goal at once and writes the uniform if the view changed.
> - `uniform: TgpuUniform<typeof Camera>` Holds the camera view from creation onwards.
> - `inject()` Fills `cameras.current` for the pipelines created from the configuration it is piped into.
> - `project(point, out)` Projects a world point to screen coordinates.
> - `projectAt(point, out)` Projects a world point to a point of the surface, as `rayAt` takes it.
> - `ray(x, y, out)` Writes the ray through the screen point `x`, `y` into `out`, as `rayOf` computes it on the GPU.
> - `rayAt(x, y, out)` Writes the ray through a point of the surface into `out`, as `ray` does.
> - `previous: TgpuUniform<typeof Camera>` Holds the previous frame's view for motion vectors and reprojection.
>
> `FlatCamera`, from `flat`:
> - `goal: { x: number; y: number; height: number }` Sets the desired center in world units with +y up, and the desired view height.
> - `pose: { readonly x: number; readonly y: number; readonly height: number }` Reports the eased center and height, the view as drawn while it approaches the goal.
> - `aspect: number` Reports the width divided by the height of the current view, from `size` at the last move.
> - `update(dt)` Eases towards the goal by `dt` seconds and writes the uniform if the view changed.
> - `jump()` Moves the view to the goal at once and writes the uniform if the view changed.
> - `uniform: TgpuUniform<typeof Camera>` Holds the camera view from creation onwards.
> - `inject()` Fills `cameras.current` for the pipelines created from the configuration it is piped into.
> - `project(point, out)` Projects a world point to screen coordinates.
> - `projectAt(point, out)` Projects a world point to a point of the surface, as `rayAt` takes it.
> - `ray(x, y, out)` Writes the ray through the screen point `x`, `y` into `out`, as `rayOf` computes it on the GPU.
> - `rayAt(x, y, out)` Writes the ray through a point of the surface into `out`, as `ray` does.
> - `previous: TgpuUniform<typeof Camera>` Holds the previous frame's view for motion vectors and reprojection.

A camera keeps a **goal** that your input handlers and game logic can change. Once a frame, `update(dt)` eases the view towards it and writes the uniform only if the view moved. Shaders read it through one `cameras.current` accessor, whichever kind of camera filled it.

```ts
import { cameras } from '@typegpu/kit';

const view = cameras.orbit(root, { size: surface, target: [0, 1, 0], distance: 12 });
web.orbitControls(view, canvas); // drag writes view.goal

view.goal.yaw += Math.PI / 2; // or turn it from game logic

frames.create(root, (frame) => {
  view.update(frame.dt); // eases, and writes the uniform if the view moved
  // ..
});
```

## Goal and update

- **Following** Write `goal.target` to follow something; the `target` option is only where it starts. A knob that writes `goal.fov` eases like the rest.
- **Pose** Read `pose` for CPU work that has to match the frame, such as a pan.
- **Easing** `update(dt)` multiplies the gap by e<sup>−damping·dt</sup>. At the default damping of 14, half the gap closes every 50 ms at any frame rate. A gap under 1e-5 snaps shut.
- **Cuts** Use `jump()` for a camera cut or a view drawn on demand. It preserves the view it replaced as last frame's view.
- **Writes** The camera writes its current-view uniform at creation and whenever the view or projection changes. The queue write lands before the frame's commands. A still camera costs a few comparisons and allocates nothing.
- **Yaw** Yaw eases along the shorter arc. A small change that crosses from near π to near −π in `Math.atan2` still turns the camera only a little. A goal a whole number of turns away leaves the view where it is.
- **Ranges** `pitchRange` and `distanceRange` clamp the orbit goal at creation and in `update` and `jump`. Input can write past them, and the camera clamps the result.
- **Floor** `floor(x, z)` returns the lowest height the eye may reach over a point, such as the ground there plus a margin. At creation and in `update` and `jump`, the camera raises the goal's pitch as far as needed to clear that height, up to the top of `pitchRange`.
- **Reach** `reach(target, yaw, pitch)` returns how far the eye may go from the target along a direction, such as to a room's wall less a margin. `update` and `jump` pull the pose's distance in to it. `goal.distance` keeps the viewer's zoom, so the eye comes back out as it turns away from the wall. [Cloister](../examples/cloister.md) keeps its eye inside the court this way.

A pan moves the target by the distance the finger moves over the ground. `pan` below works out that distance from the camera's pose:

```ts
/** Moves the target by a drag of `dx`, `dy` pixels on a view `height` pixels tall. */
function pan(dx: number, dy: number, height: number) {
  const { yaw, distance, fov } = view.pose;
  const scale = (2 * distance * Math.tan(fov / 2)) / height;
  const cos = Math.cos(yaw);
  const sin = Math.sin(yaw);

  view.goal.target[0] -= (cos * dx + sin * dy) * scale;
  view.goal.target[2] -= (cos * dy - sin * dx) * scale;
}
```

The stampede keeps the eye 1.2 m above its hills, however low input turns it:

```ts
const view = cameras.orbit(root, {
  size: { width: 8, height: 6 },
  target: [0, 2, 0],
  distance: 40,
  floor: (x, z) => heightAt(x, z) + 1.2,
});
```

`cameras.eyeOf(pose, out)` writes an orbit camera's eye position for either `goal` or `pose`. Use it for CPU work at the eye, such as placing a sound.

## What shaders read

`root.pipe(view.inject())` fills the `cameras.current` accessor from `@typegpu/kit` with the camera's uniform:

| Field            | Type      | Meaning                                                                 |
| ---------------- | --------- | ----------------------------------------------------------------------- |
| `viewProjection` | `mat4x4f` | World to clip space.                                                    |
| `position`       | `vec3f`   | The eye, in world space.                                                |
| `right`, `up`    | `vec3f`   | The view's x and y axes in world space, for quads that face the screen. |

`cameras.toClip(point)` returns a world point in clip space, the position a vertex shader returns. It reads `cameras.current` itself. Code that projects with a view of its own, such as a shadow's, multiplies by that view's `viewProjection`.

A function of your own that takes `cameras.current.$` types that parameter as `cameras.Camera`. These `'use gpu'` functions take it and derive the rest:

- **Forward** `cameras.forwardOf(view)` returns the direction the view looks in.
- **Lens** `cameras.lensOf(view)` returns the projection's x and y scales.
- **Ray** `cameras.rayOf(view, ndc)` returns an `origin` and a unit `direction` through a screen point. `ndc` ranges from −1 to 1 with +y up. Orbit rays start at the eye. Flat rays are parallel and start at their screen points. To go back to the screen, multiply a point on the ray, such as `origin + direction`, by `viewProjection` and divide by `w`.
- **To the viewer** `cameras.towards(view, point)` returns the unit direction from a point to the viewer for shading. For a flat camera it is the opposite of the view direction.
- **Distance** `cameras.distanceOf(view, depth)` returns the distance along the view direction to the point a depth value holds, for orbit and flat cameras alike. Read `depth` from the depth target the view drew. Depth of field, ambient occlusion and the [night market](../examples/night-market.md)'s focus pull read distance this way.

`forwardOf` returns `cross(up, right)`, so `right`, `up` and the view direction form a right-handed basis. A `Camera` you build in a shader must keep that basis. A view of a reflection must also mirror the image, as the [fireworks](../examples/fireworks.md) lake does. Read what it drew with u mirrored.

```ts
import { cameras } from '@typegpu/kit';

/** Where the pointer's ray meets the ground, y = 0. */
const ground = () => {
  'use gpu';
  const ray = cameras.rayOf(cameras.current.$, pointer.$.ndc);
  return ray.origin + ray.direction * (-ray.origin.y / ray.direction.y);
};
```

`cameras.sees(view, center, radius)` returns false only when a sphere lies wholly outside one of the view's six planes. It can accept a sphere beyond a corner. Use it in the `alive` callback of [live lists](live-lists.md) with the camera's fill:

```ts
// Balls, each a centre and a radius in a vec4f
const balls = root.createReadonly(d.arrayOf(d.vec4f, 256));

const seen = liveLists.create(root, {
  capacity: 256,
  draws: [{ vertexCount: 36 }],
  alive: tgpu
    .fn((i: number) => {
      'use gpu';
      const ball = balls.$[i];
      return cameras.sees(cameras.current.$, ball.xyz, ball.w);
    })
    .pipe(view.inject()),
});
```

To find what is under a pointer among things that move on the GPU, use [picker](picker.md), which projects each candidate with this camera.

## Last frame's view

`view.previous` holds last frame's view. Code compiled with [`history.previously`](history.md) reads it through `cameras.current` for motion vectors and reprojection. `toClip` compiled this way finds where a world position appeared on screen last frame:

```ts
const clipBefore = history.previously(cameras.toClip);
```

The orbit and flat cameras write `previous` in `update` and `jump`. When they move, they store the view they replace. On the frame after they stop, they store the current view.

## On the CPU

Each kit camera keeps a CPU copy of the view its uniform holds, for CPU work that has to match the frame. None of these calls allocates:

- **Surface points** `view.projectAt` and `view.rayAt` take points of the surface, x and y from 0 to 1 with +y down, as [`web.pointer`](web.md#pointer-input) reports them. A point from `projectAt` gives `rayAt` a ray through the world point.
- **Level planes** `cameras.hitHeight(ray, height, out)` writes where a ray meets the level plane at `height` and returns how far along the ray that is. It returns undefined, writing nothing, for a ray that runs level or points away. With `{ grazing }`, it also rejects rays whose absolute y direction is at or below `grazing`. Rays this close to level can hit far beyond the scene, near the horizon.
- **Terrain** `height` can also be a function of x and z, such as a terrain's height. `hitHeight` searches along the ray up to `reach`. It starts with `step` and grows the step by 4% each time. When a step reaches the ground or goes below it, the function bisects that interval 16 times. An infinite `reach` searches until a hit and needs a `step`. It allocates nothing, so a pointer can find the hills under it every frame, as in the [stampede](../examples/stampede.md).

```ts
const at = [0, 0, 0];
const ray = { origin: [0, 0, 0], direction: [0, 0, 0] };

// A label over a point, in CSS pixels of an 800 by 600 canvas
if (view.projectAt([0, 2, 0], at)) {
  label.style.translate = `${at[0] * 800}px ${at[1] * 600}px`;
}

// The ground under the pointer, y = 0; a miss leaves `aim` where it was
const aim = [0, 0, 0];
const pointing = {
  move(x: number, y: number) {
    view.rayAt(x, y, ray);
    cameras.hitHeight(ray, 0, aim, { grazing: 0.01 });
  },
};
```

Both read the view the frame draws, as the last `update`, `write` or `jump` left it. They ignore the goal. A `custom` camera projects nothing before its first `write`. A function that takes the ray types it as `cameras.CpuRay`.

A module that reads a camera of its own takes it as an argument and pipes it in, as `particles.create` does. [Meshes](meshes.md) shows a vertex shader that reads it.

## Orbit controls

`web.orbitControls(view, element, { sensitivity, zoomSpeed, button, pan, page, pointer, onChange })` writes the goal from the pointer.

- **Orbit and zoom** A drag with the primary button orbits by `sensitivity` radians per pixel, 0.008 by default, and keeps going outside the element. The wheel and a pinch zoom without scrolling the page. The wheel multiplies the distance by e<sup>deltaY·zoomSpeed</sup>, with a default `zoomSpeed` of 0.001. A two-finger pinch multiplies the distance by the ratio of the previous finger spread to the new one.
- **Other buttons** With `button: 'secondary'` or `'middle'`, that button orbits. Without panning enabled, two fingers also orbit as their midpoint moves during a pinch. The primary button and one finger stay free for the scene, such as for strokes from [`web.pointer`](web.md#pointer-input) that paint.
- **Panning** With `pan: true`, the secondary button pans the target as `cameras.pan` does. When the secondary button orbits, the middle one pans instead. Two fingers moving together pan too. Buttons the controls use open no context menu and start no autoscroll.
- **In a page** With `page: true`, vertical swipes and the wheel scroll the page. Horizontal drags turn the camera. Pinches and wheel events with Ctrl or ⌘ held zoom it. Trackpad pinches send those wheel events. Use it for a canvas inside a page that scrolls.
- **Changes** `onChange` runs after each input that wrote the goal, for a view that draws only when asked.
- **Touch action** It sets the element's `touch-action` to `none`, or `pan-y` with `page`. `destroy()`, or `[Symbol.dispose]`, removes listeners and restores the original value. Create controls in [`attach`](hosting.md#on-the-web) on a hosted page to dispose them with the scene.
- **Beside a pointer** On an element that a [`web.pointer`](web.md#pointer-input) also follows, pass it as `pointer`. The pointer then sets `touch-action` from its own `page` and captures each press. The controls' `page` decides only the wheel. Destroy the controls before the pointer.
- **Taps** The controls leave taps to the app. Listen on the same element and count a release within a few pixels of its press as a tap, such as one that places a tower on a board the drag orbits.

Here the primary button paints through the pointer and the secondary button orbits:

```ts
const brush = web.pointer(canvas, {
  move: (x, y, event) => {
    if (event.buttons === 1) paint(x, y);
  },
});
web.orbitControls(view, canvas, { button: 'secondary', pointer: brush });
```

For a binding the controls don't offer, write the goal yourself. `cameras.turn(goal, dx, dy, { sensitivity })` turns it by a drag as the controls do. `cameras.pan(goal, dx, dy, { height })` pans it, where `height` is the view's height in the units of the drag. Here a drag turns the view, a drag with Shift held pans it and the wheel zooms:

```ts
web.pointer(canvas, {
  move(_x, _y, event) {
    if (event.buttons !== 1) return;
    const { movementX: dx, movementY: dy } = event;
    if (event.shiftKey) cameras.pan(view.goal, dx, dy, { height: canvas.clientHeight });
    else cameras.turn(view.goal, dx, dy);
  },
  zoom: (by) => {
    view.goal.distance *= by;
  },
});
```

WebKit and Firefox for Android report `movementX` and `movementY` as 0 for touch, so a binding for fingers takes the change in `clientX` and `clientY` between moves, as the controls do.

On React Native, write `goal` from gesture handlers. Here the scene runs on the JS thread and `height` is the view's height in points. One finger turns the view and two pan it:

```ts
const orbit = Gesture.Pan()
  .runOnJS(true)
  .maxPointers(1)
  .onChange((event) => {
    cameras.turn(view.goal, event.changeX, event.changeY);
  });
const pan = Gesture.Pan()
  .runOnJS(true)
  .minPointers(2)
  .onChange((event) => {
    cameras.pan(view.goal, event.changeX, event.changeY, { height });
  });
const zoom = Gesture.Pinch()
  .runOnJS(true)
  .onChange((event) => {
    view.goal.distance /= event.scaleChange;
  });
```

A handler can't access a scene on another runtime. Write cumulative gesture values to a [`runtimes.cell`](hosting.md#values-between-runtimes). Each frame, have the scene move the goal by the change in those values.

## Flat camera

`cameras.flat(root, { size, height })` gives an orthographic view `height` world units tall, with +y up and z from −1 to 1. `snap` rounds the drawn centre to a grid, such as one texel of a pixel-art target, so the art doesn't shimmer as the view follows a hero. Pass that target as `size`.

`fit: { width, height, mode }` replaces `height` with a world rectangle centred on the view. `'cover'` fills the view with it and crops its longer side; `'contain'` shows all of it and leaves bands. At creation and whenever the aspect changes, the camera sets `goal.height` and its eased height at once. A zoom you write still eases, until the next resize sets the height again. The [ember mirror](../examples/ember-mirror.md) covers the screen with its camera feed this way.

## A camera of your own

`cameras.custom(root)` takes matrices you supply for a follow camera, a scripted shot or a repeatable benchmark view. Pass `write(view, projection)` a view matrix containing rotation and translation, such as one from `mat4.lookAt`, and a projection matrix. It derives the eye and screen axes and fills `cameras.current`. The orbit and flat cameras use this implementation.

```ts
import { cameras } from '@typegpu/kit';
import { mat4 } from 'wgpu-matrix';

const chase = cameras.custom(root);
const eye = new Float32Array(3);
const up = [0, 1, 0];
const view = mat4.create();
const projection = mat4.perspective(0.8, aspect, 0.1, 500);

// after the hero moves
eye[0] = hero[0];
eye[1] = hero[1] + 3;
eye[2] = hero[2] + 6;
chase.write(mat4.lookAt(eye, hero, up, view), projection);
```

- Skipping `write` while the view is still leaves `previous` stale.
- Until the first `write` the uniform holds zeros, and nothing drawn with it shows.
- `write` throws for a view matrix that mirrors the world. For a reflection, mirror the image too with `mat4.multiply(mat4.scaling([-1, 1, 1]), view)`. Triangles then keep their winding.

## A view per layer

`cameras.layered(root, n)` holds `n` views in one uniform array, one for each layer of a [description drawn into layers](passes.md#layers), such as a shadow cascade each. `write(k, view, projection)` writes layer `k` from the same matrices as a custom camera's `write`. `cameras.current.$` in a pass into layer `k` is view `k`:

```ts
import { cameras } from '@typegpu/kit';
import { mat4 } from 'wgpu-matrix';

const views = cameras.layered(root, 2);
const casters = passes.create(root, maps, { depth: passes.depth }).pipe(views.inject());

const sun = mat4.lookAt([20, 40, 20], [0, 0, 0], [0, 1, 0]);
views.write(0, sun, mat4.ortho(-10, 10, -10, 10, 0, 200)); // near
views.write(1, sun, mat4.ortho(-40, 40, -40, 40, 0, 200)); // far
```

- It keeps no last frame's views, so code compiled with `history.previously` reads the current view.
- It has no CPU `project`, `ray` or `rayAt`.

## Limits

- **Snapping** A gap under 1e-5 snaps shut in any unit. That suits radians and scenes a few units to a few hundred across.
- **Copies** `goal.target` is an array, so a goal copied with a spread shares its target.
- **Projection** `lensOf`, `rayOf`, `ray` and `rayAt` assume a projection centred on the view axis.
- **Flat rays** `rayOf` tells a flat camera from an orbit one by the matrix's last row, (0, 0, 0, 1) under an orthographic projection. A `custom` camera's rays follow the same test.
- **Fixed struct** `Camera` is one fixed struct with no inverse view-projection. Put other values per view in a uniform of your own, split by how often they change.
- **Other cameras** A camera implementing `CameraBase` works with every module that reads the camera in shaders. It needs no `project`, `ray` or `previous`, which belong to the kit's cameras. A fitted sun shadow's `eye` needs a `CpuView`, which has them. Without a temporal fill, `history.previously` reads the same camera uniform as current-frame code, so motion vectors omit camera motion.
