Skip to content

ModulePost-processing / AntialiasingConcept: Scenes and passes

Temporal antialiasing

Smooth stepped edges and shimmer by gathering samples over several frames.

import
import { taa } from '@typegpu/kit'
call
taa.create(root, { source, motion?, depth, camera?, … }) → Taa
facts
recordsencoderallocateson resizelifecycleinitAsync()destroy()needscameras
On this page

With one sample per pixel, angled edges form steps, and thin lines shimmer as they move. MSAA takes multiple samples in each drawing pass, and FXAA smooths the finished picture. TAA distributes samples across . Each frame offsets the scene by a fraction of a pixel. The resolve blends it with the previous image using motion to find each surface’s previous position.

latticeThin beams and rising embers, smoothed over time with TAA.
Hold the pointer over distant beams and turn TAA off. The loupe shows thin beams stepping and shimmering as they turn. Lower the render scale, then turn upscaling off and on to compare the smaller picture stretched with TAA resolving it up.

One edge, sampled at a new spot in every pixel each frame and blended over the cycle

Try Move the edge, or drag it sideways. It writes no motion here, so the pixels in coral find old samples that no longer match their neighbours and throw them out. Draw at two thirds to see the resolve rebuild the same edge from fewer pixels.

Every scene pass must jitter, and that move must write motion. Use pass descriptions for those passes:

import {
import finish
finish
,
import taa
taa
} from '@typegpu/kit';
const
const screen: targets.Targets<Specs<{
readonly hdr: {
readonly format: "rgba16float";
readonly sampled: true;
};
readonly motion: {
readonly format: "rg16float";
readonly sampled: true;
};
readonly depth: {
readonly format: "depth24plus";
readonly sampled: true;
};
}>>
screen
=
import targets
targets
.
function create<{
readonly hdr: {
readonly format: "rgba16float";
readonly sampled: true;
};
readonly motion: {
readonly format: "rg16float";
readonly sampled: true;
};
readonly depth: {
readonly format: "depth24plus";
readonly sampled: true;
};
}>(root: TgpuRoot, source: targets.SizeSource, specs: {
readonly hdr: {
readonly format: "rgba16float";
readonly sampled: true;
};
readonly motion: {
readonly format: "rg16float";
readonly sampled: true;
};
readonly depth: {
readonly format: "depth24plus";
readonly sampled: true;
};
}, options?: targets.Options): targets.Targets<...>

Creates render targets that follow a size. Replaces the whole set when the size changes. Put targets needed only sometimes in their own set and create that set when needed. Throws for transient targets with sampling, storage or mip levels, for multisampled targets with storage or mip levels, and for layered targets that are multisampled, mipped or have more layers than the device allows.

@param ― source the size it follows, such as a surface

@param ― specs a format and options per target, by name

@param ― options.resolution the fraction of each side drawn, which changes without allocating

@returns ― a set of targets you fit every frame and destroy

create
(
const root: TgpuRoot
root
,
const surface: web.Surface
surface
, {
hdr: {
readonly format: "rgba16float";
readonly sampled: true;
}
hdr
: {
format: "rgba16float"
format
: 'rgba16float',
sampled: true
sampled
: true },
motion: {
readonly format: "rg16float";
readonly sampled: true;
}
motion
: {
format: "rg16float"
format
: 'rg16float',
sampled: true
sampled
: true },
depth: {
readonly format: "depth24plus";
readonly sampled: true;
}
depth
: {
format: "depth24plus"
format
: 'depth24plus',
sampled: true
sampled
: true },
});
const
const aa: taa.Taa
aa
=
import taa
taa
.
function create(root: TgpuRoot, options: taa.Options): taa.Taa

Creates temporal antialiasing from subpixel-jittered frames. The resolve blends each frame with history sampled where motion, or depth and camera movement, place the preceding pixel. Without either, it samples history at the same pixel. It clamps history colour to the local colour spread to reduce trails and weights by brightness to reduce bright-pixel flicker. With size, it resolves a smaller source up to that size: each output pixel rebuilds the current frame from the nine source pixels around it with Lanczos-2 weights placed by this frame's jitter, and blends less of it where those weights add up to less. Record its single pass after scene passes and before the final pass reads output.

@allocates ― on resize: targets for the new size and the bind groups of its passes; so does a new source, motion, depth or reactive texture

@owns ― targets, 4 buffers, a sampler, a pipeline, 2 to 4 bind groups: two histories, each frame written into one from the other, the settings, the region and whether to blend, the jitter and its sequence, a group each for the frames that read either history with the source and motion, one for depth and one for reactive

@binds ― 1 uniform: jitter, this frame's offset

@records ― record after the passes that draw the source and the motion, before what reads output.

@param ― options.source this frame's picture, drawn through jitter, read at every record

@param ― options.motion how far each pixel's surface moved since last frame, read at every record; without it, pixels move only with the camera

@param ― options.depth the scene's depth, for the motion of the nearest surface around each pixel and for motion from the camera, or null

@returns ― a resolve you record every frame and destroy

create
(
const root: TgpuRoot
root
, {
Options.source: Source

Provides the current linear-colour picture, drawn through jitter: a function returning a texture, such as () => screen.textures.hdr, or a rendered picture. record reads it on every call.

@cpu

source
: () =>
const screen: targets.Targets<Specs<{
readonly hdr: {
readonly format: "rgba16float";
readonly sampled: true;
};
readonly motion: {
readonly format: "rg16float";
readonly sampled: true;
};
readonly depth: {
readonly format: "depth24plus";
readonly sampled: true;
};
}>>
screen
.
Targets<Specs<{ readonly hdr: { readonly format: "rgba16float"; readonly sampled: true; }; readonly motion: { readonly format: "rg16float"; readonly sampled: true; }; readonly depth: { readonly format: "depth24plus"; readonly sampled: true; }; }>>.textures: {
readonly hdr: targets.Target<{
readonly format: "rgba16float";
readonly sampled: true;
}>;
readonly motion: targets.Target<{
readonly format: "rg16float";
readonly sampled: true;
}>;
readonly depth: targets.Target<{
readonly format: "depth24plus";
readonly sampled: true;
}>;
}

Provides the current textures. A size change replaces them.

textures
.
hdr: targets.Target<{
readonly format: "rgba16float";
readonly sampled: true;
}>
hdr
,
Options.motion?: (() => targets.FloatTexture) | undefined

Returns the motion texture written by motion. Each vector is the preceding UV position minus the current UV position. record reads it on every call. Default none, which moves every pixel as camera moves depth, or keeps it in place without both.

@cpu

motion
: () =>
const screen: targets.Targets<Specs<{
readonly hdr: {
readonly format: "rgba16float";
readonly sampled: true;
};
readonly motion: {
readonly format: "rg16float";
readonly sampled: true;
};
readonly depth: {
readonly format: "depth24plus";
readonly sampled: true;
};
}>>
screen
.
Targets<Specs<{ readonly hdr: { readonly format: "rgba16float"; readonly sampled: true; }; readonly motion: { readonly format: "rg16float"; readonly sampled: true; }; readonly depth: { readonly format: "depth24plus"; readonly sampled: true; }; }>>.textures: {
readonly hdr: targets.Target<{
readonly format: "rgba16float";
readonly sampled: true;
}>;
readonly motion: targets.Target<{
readonly format: "rg16float";
readonly sampled: true;
}>;
readonly depth: targets.Target<{
readonly format: "depth24plus";
readonly sampled: true;
}>;
}

Provides the current textures. A size change replaces them.

textures
.
motion: targets.Target<{
readonly format: "rg16float";
readonly sampled: true;
}>
motion
,
Options.depth: (() => targets.Depth) | null

Returns sampled scene depth without stencil, or null for a picture drawn without depth. Motion then follows the nearest surrounding surface to avoid smearing moving edges over the background. record reads it on every call. Unused without motion or camera. With null, motion is read at each pixel.

@cpu

depth
: () =>
const screen: targets.Targets<Specs<{
readonly hdr: {
readonly format: "rgba16float";
readonly sampled: true;
};
readonly motion: {
readonly format: "rg16float";
readonly sampled: true;
};
readonly depth: {
readonly format: "depth24plus";
readonly sampled: true;
};
}>>
screen
.
Targets<Specs<{ readonly hdr: { readonly format: "rgba16float"; readonly sampled: true; }; readonly motion: { readonly format: "rg16float"; readonly sampled: true; }; readonly depth: { readonly format: "depth24plus"; readonly sampled: true; }; }>>.textures: {
readonly hdr: targets.Target<{
readonly format: "rgba16float";
readonly sampled: true;
}>;
readonly motion: targets.Target<{
readonly format: "rg16float";
readonly sampled: true;
}>;
readonly depth: targets.Target<{
readonly format: "depth24plus";
readonly sampled: true;
}>;
}

Provides the current textures. A size change replaces them.

textures
.
depth: targets.Target<{
readonly format: "depth24plus";
readonly sampled: true;
}>
depth
,
Options.camera?: cameras.CameraBase | undefined

Supplies the scene camera with its preceding view, such as cameras.orbit. With depth, pixels without renderer-written motion reconstruct motion from depth and camera movement. Without both, these pixels stay in place. Default none.

camera
:
const view: cameras.OrbitCamera
view
,
});
const
const scene: passes.Description<{
readonly hdr: typeof passes.color;
readonly motion: passes.Output<unknown, {
position: d.v4f;
}>;
readonly depth: typeof passes.depth;
}>
scene
=
import passes
passes
.
function create<Specs<{
readonly hdr: {
readonly format: "rgba16float";
readonly sampled: true;
};
readonly motion: {
readonly format: "rg16float";
readonly sampled: true;
};
readonly depth: {
readonly format: "depth24plus";
readonly sampled: true;
};
}>, {
readonly hdr: typeof passes.color;
readonly motion: passes.Output<unknown, {
position: d.v4f;
}>;
readonly depth: typeof passes.depth;
}>(root: TgpuRoot, screen: targets.Targets<Specs<{
readonly hdr: {
readonly format: "rgba16float";
readonly sampled: true;
};
readonly motion: {
readonly format: "rg16float";
readonly sampled: true;
};
readonly depth: {
readonly format: "depth24plus";
readonly sampled: true;
};
}>>, writes: {
readonly hdr: typeof passes.color;
readonly motion: passes.Output<unknown, {
position: d.v4f;
}>;
readonly depth: typeof passes.depth;
}, options?: passes.TargetOptions<...> | undefined): passes.Description<...> (+1 overload)

Describes the targets and outputs for scene passes. With a surface such as the canvas, writes only each renderer's colour. With a target set, writes colour into the target marked color, depth into the target marked depth, and other outputs into their named targets. Multisampled targets resolve according to resolve. Targets with layers draw one pass per layer, and every target the description draws into needs the same layers. add builds a renderer's drawing. begin starts a pass. pipe supplies fills such as a camera.

@param ― screen the surface, or the targets, which give the formats; each one the description names is drawn into

@param ― writes what fills each target, by its key in screen

@returns ― a description you destroy, which holds the pipelines it builds

create
(
const root: TgpuRoot
root
,
const screen: targets.Targets<Specs<{
readonly hdr: {
readonly format: "rgba16float";
readonly sampled: true;
};
readonly motion: {
readonly format: "rg16float";
readonly sampled: true;
};
readonly depth: {
readonly format: "depth24plus";
readonly sampled: true;
};
}>>
screen
,
{
hdr: typeof passes.color
hdr
:
import passes
passes
.
const color: typeof passes.color

Marks the target that receives each renderer's colour.

color
,
motion: passes.Output<unknown, {
position: d.v4f;
}>
motion
:
import taa
taa
.
const motion: passes.Output<unknown, {
position: d.v4f;
}>

This output writes surface motion into an rg16float target. It stores preceding UV position minus current UV position. It computes the preceding position by compiling renderer vertex code with history.previously, which reads the preceding camera and values of other temporal fills.

motion
,
depth: typeof passes.depth
depth
:
import passes
passes
.
const depth: typeof passes.depth

Marks the depth target.

depth
},
{
Options.jitter?: Position | undefined

Moves clip positions for rasterisation. Outputs read the original vertex positions. Use for a sub-pixel offset in temporal antialiasing. Default none.

@gpu

jitter
:
const aa: taa.Taa
aa
.
Taa.jitter: (position: d.v4f) => d.v4f

Offsets vertices by a different fraction of a source pixel each frame so frames sample the whole pixel together: 8 offsets in turn, or at size 8 for each output pixel a source pixel covers, 18 at 1.5 times per side. Supply this as jitter in passes.create.

jitter
},
)
.
Description<{ readonly hdr: typeof color; readonly motion: Output<unknown, { position: d.v4f; }>; readonly depth: typeof depth; }>.pipe(fill: Inject): passes.Description<{
readonly hdr: typeof passes.color;
readonly motion: passes.Output<unknown, {
position: d.v4f;
}>;
readonly depth: typeof passes.depth;
}>

Adds fill after existing fills and returns a description of the same passes. Piped fills take precedence over a drawing's own. For example, passes.create(…).pipe(view.inject()) uses the camera from view.

pipe
(
const view: cameras.OrbitCamera
view
.
CameraBase.inject(): Inject

Fills cameras.current for the pipelines created from the configuration it is piped into.

inject
());
const
const drawn: passes.Drawn
drawn
=
const scene: passes.Description<{
readonly hdr: typeof passes.color;
readonly motion: passes.Output<unknown, {
position: d.v4f;
}>;
readonly depth: typeof passes.depth;
}>
scene
.
Into<{ readonly hdr: typeof color; readonly motion: Output<unknown, { position: d.v4f; }>; readonly depth: typeof depth; }>.add<d.WgslStruct<{
position: d.Vec4f;
}>, {
color: d.v4f;
}>(drawing: passes.Drawing<d.WgslStruct<{
position: d.Vec4f;
}>, {
color: d.v4f;
}>): passes.Drawn (+1 overload)

Builds a pipeline for drawing that writes every described output and returns its draw methods. If the drawing cannot supply the fields an output reads, type checking fails with that target's name and those fields. Use without to leave it out or instead to replace it.

add
(
const beams: passes.Drawing<d.WgslStruct<{
position: d.Vec4f;
}>, {
color: d.v4f;
}>
beams
); // a drawing, such as the lattice's beams
const
const final: finish.Finish
final
=
import finish
finish
.
function create(root: TgpuRoot, options: finish.Options): finish.Finish

Creates the final pass of a frame. It reads the source, adds glow, tone maps, grades, applies the vignette, encodes and dithers. It draws one triangle into the caller pass.

@allocates ― on resize: a bind group for a new source or glow

@owns ― 2 buffers, a sampler, a pipeline, 2 bind groups: the settings, the regions it reads, a group for the glow and one for each texture the source returns

@records ― record into a pass of its own on the view you give, usually the canvas's, or draw into the caller's pass, after the bloom's record.

@param ― options.source the picture, rendered or a texture, read at every draw

@param ― options.region the part of the source that holds the picture, read at every draw

@param ― options.glow a bloom, or a glow of your own, added before tone mapping

@param ― options.exposure an adapted exposure, read on the GPU

@returns ― a final pass you draw every frame

create
(
const root: TgpuRoot
root
, {
Options.format: GPUTextureFormat

Sets the output format, such as the canvas format.

format
:
const surface: web.Surface
surface
.
Surface.format: GPUTextureFormat

Reports the format of its textures, which pipelines that draw into it target.

format
,
Options.source: Source

Provides the picture at any size: a rendered picture, such as aa or blur, or a function returning a texture, such as () => screen.textures.hdr. draw reads it on every call, so the texture can be rebuilt.

@cpu

source
:
const aa: taa.Taa
aa
});
// Each frame
const screen: targets.Targets<Specs<{
readonly hdr: {
readonly format: "rgba16float";
readonly sampled: true;
};
readonly motion: {
readonly format: "rg16float";
readonly sampled: true;
};
readonly depth: {
readonly format: "depth24plus";
readonly sampled: true;
};
}>>
screen
.
Targets<Specs<{ readonly hdr: { readonly format: "rgba16float"; readonly sampled: true; }; readonly motion: { readonly format: "rg16float"; readonly sampled: true; }; readonly depth: { readonly format: "depth24plus"; readonly sampled: true; }; }>>.fit(): boolean

Rebuilds all textures if the source size changed, destroying the old textures first. Updates regions for the current resolution. Returns true after a rebuild so callers can update bind groups that hold old textures. Call before recording passes that use the targets. A rebuild that throws destroys what it made and leaves the set unfitted, so the next call rebuilds it.

fit
();
const scene: passes.Description<{
readonly hdr: typeof passes.color;
readonly motion: passes.Output<unknown, {
position: d.v4f;
}>;
readonly depth: typeof passes.depth;
}>
scene
.
Description<{ readonly hdr: typeof color; readonly motion: Output<unknown, { position: d.v4f; }>; readonly depth: typeof depth; }>.record(frame: Frame | TgpuCommandEncoder, drawn: passes.Drawn | readonly passes.Drawn[], options?: passes.BeginOptions<{
readonly hdr: typeof passes.color;
readonly motion: passes.Output<unknown, {
position: d.v4f;
}>;
readonly depth: typeof passes.depth;
}> | undefined): void

Begins a pass, draws drawn or each drawing in a list in order, then ends the pass. Reuse the list to avoid allocating each frame. Call begin yourself when you need to choose drawings per frame. Records nothing while enabled is false.

record
(
const frame: Frame
frame
,
const drawn: passes.Drawn
drawn
);
const aa: taa.Taa
aa
.
Taa.record(target: Frame | TgpuCommandEncoder, options?: Timed): void

Records the resolve after source and motion passes, then sets jitter for the next frame. Records nothing while disabled. Optional timer writes measure the resolve. Given a frame, a resolve that never submits leaves the history as it was.

record
(
const frame: Frame
frame
);
const final: finish.Finish
final
.
Finish.record(target: Frame | TgpuCommandEncoder, view: GPUTextureView, options?: finish.RecordOptions): void

Opens a pass on view, such as surface.view(frame), draws into it and ends it. A viewport draws the picture into that rectangle and clears the rest, transparent with alpha: 'premultiplied' and black otherwise. Optional timer writes measure the pass.

record
(
const frame: Frame
frame
,
const surface: web.Surface
surface
.
Surface.view(frame: Frame): GPUTextureView

Returns a view of the current canvas texture, created once per texture. Applies pending size changes first, which a pass using context would skip.

view
(
const frame: Frame
frame
));
  • Motion taa.motion writes each surface’s movement since the previous frame in UV coordinates. It reruns vertex code with history.previously to read the previous camera and other temporal fills.
  • Object motion All include camera motion. Object motion requires vertex code to read temporal state. Particles use velocity, and the lattice stores its turn in a history. Skinned poses keep last frame’s joints, so posed joints show their own motion.
  • Rows By default, , trails and text include only camera motion. A set of instances or a created with history: true gives each that moves its own motion, whether write or a moved it.
  • Still vertices Renderers with stationary vertices, such as a full-screen sky, use scene.without('motion'). See Passes for their .
  • Unwritten pixels Unwritten motion pixels retain the taa.motion clear value, and taa.written(motion) is false for them in a shader of yours. With camera and depth, the resolve reconstructs surface position from depth and applies camera motion. Otherwise those pixels stay fixed.
  • Depth depth is required. Pass null for a picture drawn without depth, such as a 2D game: the resolve then reads motion at each pixel, and pixels without motion stay in place.
  • Without motion Omit motion when no drawing’s vertices move, as in the ray-marched jelly slider. The resolve then binds no motion texture, and the scene writes no motion target. With camera and depth, every pixel follows the camera. Without them, history stays at each pixel, which suits a still camera.
  • Jitter Jitter cycles through 8 subpixel offsets, or more at size. GPU copies advance it after each resolve without per-frame CPU writes. aa.offset holds the current clip-space offset for custom jitter shaders.
  • The resolve The resolve clamps previous colour within spread standard deviations of nearby current colours. It takes blend of the current frame and downweights bright values in both frames. With depth, each pixel uses motion from the nearest surrounding surface.
  • Compiling await aa.initAsync() compiles the resolve and binds both histories to the current source, so recording binds nothing new until a source or size changes.
  • Resetting Call reset() after a camera cut. Resizing, region changes and enable(true) also reset history. A frame that throws before it submits the resolve leaves history as it was.
  • Turning off After enable(false), jitter is zero, record records nothing and output is the source, so keep calling record and keep aa as the next pass’s source.
  • As a source Give bloom source: aa to bloom the antialiased picture. Every post-processing source takes aa and reads its output and region at each call, because output alternates between two textures.
  • Recording record takes the frame or an encoder. record(frame, { timestampWrites }) times the resolve under a profiler timer.

A finished look for model scenes runs it after a scene lit with shadows and ambient occlusion, before bloom and the final pass.

Drawing fewer pixels saves fragment work, and stretching the smaller picture to the canvas blurs it. Over a jitter cycle, TAA samples each output pixel at many positions, so it can rebuild detail finer than one drawn pixel. Draw at two thirds in the edge figure above to watch it rebuild one edge. Give it size, and it resolves a scene drawn at a lower resolution up to that size:

import {
import taa
taa
} from '@typegpu/kit';
const
const settings: {
scale: number;
}
settings
= {
scale: number
scale
: 0.67 }; // two thirds of each side
const
const screen: targets.Targets<Specs<{
readonly hdr: {
readonly format: "rgba16float";
readonly sampled: true;
};
readonly motion: {
readonly format: "rg16float";
readonly sampled: true;
};
readonly depth: {
readonly format: "depth24plus";
readonly sampled: true;
};
}>>
screen
=
import targets
targets
.
function create<{
readonly hdr: {
readonly format: "rgba16float";
readonly sampled: true;
};
readonly motion: {
readonly format: "rg16float";
readonly sampled: true;
};
readonly depth: {
readonly format: "depth24plus";
readonly sampled: true;
};
}>(root: TgpuRoot, source: targets.SizeSource, specs: {
readonly hdr: {
readonly format: "rgba16float";
readonly sampled: true;
};
readonly motion: {
readonly format: "rg16float";
readonly sampled: true;
};
readonly depth: {
readonly format: "depth24plus";
readonly sampled: true;
};
}, options?: targets.Options): targets.Targets<...>

Creates render targets that follow a size. Replaces the whole set when the size changes. Put targets needed only sometimes in their own set and create that set when needed. Throws for transient targets with sampling, storage or mip levels, for multisampled targets with storage or mip levels, and for layered targets that are multisampled, mipped or have more layers than the device allows.

@param ― source the size it follows, such as a surface

@param ― specs a format and options per target, by name

@param ― options.resolution the fraction of each side drawn, which changes without allocating

@returns ― a set of targets you fit every frame and destroy

create
(
const root: TgpuRoot
root
,
const surface: web.Surface
surface
,
{
hdr: {
readonly format: "rgba16float";
readonly sampled: true;
}
hdr
: {
format: "rgba16float"
format
: 'rgba16float',
sampled: true
sampled
: true },
motion: {
readonly format: "rg16float";
readonly sampled: true;
}
motion
: {
format: "rg16float"
format
: 'rg16float',
sampled: true
sampled
: true },
depth: {
readonly format: "depth24plus";
readonly sampled: true;
}
depth
: {
format: "depth24plus"
format
: 'depth24plus',
sampled: true
sampled
: true },
},
{
Options.resolution?: number | (() => number) | undefined

Sets the fraction of each side to draw, capped at 1 and read at each fit(). Textures keep the source size, so changing resolution allocates nothing. Passes use viewports for the drawn regions, and sampling reads only those regions. Default 1.

@cpu

resolution
: () =>
const settings: {
scale: number;
}
settings
.
scale: number
scale
},
);
const
const aa: taa.Taa
aa
=
import taa
taa
.
function create(root: TgpuRoot, options: taa.Options): taa.Taa

Creates temporal antialiasing from subpixel-jittered frames. The resolve blends each frame with history sampled where motion, or depth and camera movement, place the preceding pixel. Without either, it samples history at the same pixel. It clamps history colour to the local colour spread to reduce trails and weights by brightness to reduce bright-pixel flicker. With size, it resolves a smaller source up to that size: each output pixel rebuilds the current frame from the nine source pixels around it with Lanczos-2 weights placed by this frame's jitter, and blends less of it where those weights add up to less. Record its single pass after scene passes and before the final pass reads output.

@allocates ― on resize: targets for the new size and the bind groups of its passes; so does a new source, motion, depth or reactive texture

@owns ― targets, 4 buffers, a sampler, a pipeline, 2 to 4 bind groups: two histories, each frame written into one from the other, the settings, the region and whether to blend, the jitter and its sequence, a group each for the frames that read either history with the source and motion, one for depth and one for reactive

@binds ― 1 uniform: jitter, this frame's offset

@records ― record after the passes that draw the source and the motion, before what reads output.

@param ― options.source this frame's picture, drawn through jitter, read at every record

@param ― options.motion how far each pixel's surface moved since last frame, read at every record; without it, pixels move only with the camera

@param ― options.depth the scene's depth, for the motion of the nearest surface around each pixel and for motion from the camera, or null

@returns ― a resolve you record every frame and destroy

create
(
const root: TgpuRoot
root
, {
Options.source: Source

Provides the current linear-colour picture, drawn through jitter: a function returning a texture, such as () => screen.textures.hdr, or a rendered picture. record reads it on every call.

@cpu

source
: () =>
const screen: targets.Targets<Specs<{
readonly hdr: {
readonly format: "rgba16float";
readonly sampled: true;
};
readonly motion: {
readonly format: "rg16float";
readonly sampled: true;
};
readonly depth: {
readonly format: "depth24plus";
readonly sampled: true;
};
}>>
screen
.
Targets<Specs<{ readonly hdr: { readonly format: "rgba16float"; readonly sampled: true; }; readonly motion: { readonly format: "rg16float"; readonly sampled: true; }; readonly depth: { readonly format: "depth24plus"; readonly sampled: true; }; }>>.textures: {
readonly hdr: targets.Target<{
readonly format: "rgba16float";
readonly sampled: true;
}>;
readonly motion: targets.Target<{
readonly format: "rg16float";
readonly sampled: true;
}>;
readonly depth: targets.Target<{
readonly format: "depth24plus";
readonly sampled: true;
}>;
}

Provides the current textures. A size change replaces them.

textures
.
hdr: targets.Target<{
readonly format: "rgba16float";
readonly sampled: true;
}>
hdr
,
Options.region?: targets.SizeSource | undefined

Selects the source region from its top-left corner, such as regions.hdr when drawing below full resolution. record reads it on every call. Default the region of a rendered source, else the whole texture.

region
:
const screen: targets.Targets<Specs<{
readonly hdr: {
readonly format: "rgba16float";
readonly sampled: true;
};
readonly motion: {
readonly format: "rg16float";
readonly sampled: true;
};
readonly depth: {
readonly format: "depth24plus";
readonly sampled: true;
};
}>>
screen
.
Targets<Specs<{ readonly hdr: { readonly format: "rgba16float"; readonly sampled: true; }; readonly motion: { readonly format: "rg16float"; readonly sampled: true; }; readonly depth: { readonly format: "depth24plus"; readonly sampled: true; }; }>>.regions: {
readonly hdr: targets.SizeSource;
readonly motion: targets.SizeSource;
readonly depth: targets.SizeSource;
}

Reports each drawn region from the top-left corner of its target. Multiplies target size by resolution and rounds up. fit() updates the same objects for the lifetime of the set.

regions
.
hdr: targets.SizeSource
hdr
,
Options.size?: targets.SizeSource | undefined

Resolves to this size, such as the surface, from a source drawn smaller, up to 1.5 times larger per side. History then keeps this size, each output pixel rebuilds the current frame from the source pixels around it, and jitter takes more phases. Scene shaders sample textures with a mip bias of log2(render / output) - 1. Default the source region's size.

size
:
const surface: web.Surface
surface
,
Options.motion?: (() => targets.FloatTexture) | undefined

Returns the motion texture written by motion. Each vector is the preceding UV position minus the current UV position. record reads it on every call. Default none, which moves every pixel as camera moves depth, or keeps it in place without both.

@cpu

motion
: () =>
const screen: targets.Targets<Specs<{
readonly hdr: {
readonly format: "rgba16float";
readonly sampled: true;
};
readonly motion: {
readonly format: "rg16float";
readonly sampled: true;
};
readonly depth: {
readonly format: "depth24plus";
readonly sampled: true;
};
}>>
screen
.
Targets<Specs<{ readonly hdr: { readonly format: "rgba16float"; readonly sampled: true; }; readonly motion: { readonly format: "rg16float"; readonly sampled: true; }; readonly depth: { readonly format: "depth24plus"; readonly sampled: true; }; }>>.textures: {
readonly hdr: targets.Target<{
readonly format: "rgba16float";
readonly sampled: true;
}>;
readonly motion: targets.Target<{
readonly format: "rg16float";
readonly sampled: true;
}>;
readonly depth: targets.Target<{
readonly format: "depth24plus";
readonly sampled: true;
}>;
}

Provides the current textures. A size change replaces them.

textures
.
motion: targets.Target<{
readonly format: "rg16float";
readonly sampled: true;
}>
motion
,
Options.depth: (() => targets.Depth) | null

Returns sampled scene depth without stencil, or null for a picture drawn without depth. Motion then follows the nearest surrounding surface to avoid smearing moving edges over the background. record reads it on every call. Unused without motion or camera. With null, motion is read at each pixel.

@cpu

depth
: () =>
const screen: targets.Targets<Specs<{
readonly hdr: {
readonly format: "rgba16float";
readonly sampled: true;
};
readonly motion: {
readonly format: "rg16float";
readonly sampled: true;
};
readonly depth: {
readonly format: "depth24plus";
readonly sampled: true;
};
}>>
screen
.
Targets<Specs<{ readonly hdr: { readonly format: "rgba16float"; readonly sampled: true; }; readonly motion: { readonly format: "rg16float"; readonly sampled: true; }; readonly depth: { readonly format: "depth24plus"; readonly sampled: true; }; }>>.textures: {
readonly hdr: targets.Target<{
readonly format: "rgba16float";
readonly sampled: true;
}>;
readonly motion: targets.Target<{
readonly format: "rg16float";
readonly sampled: true;
}>;
readonly depth: targets.Target<{
readonly format: "depth24plus";
readonly sampled: true;
}>;
}

Provides the current textures. A size change replaces them.

textures
.
depth: targets.Target<{
readonly format: "depth24plus";
readonly sampled: true;
}>
depth
,
Options.camera?: cameras.CameraBase | undefined

Supplies the scene camera with its preceding view, such as cameras.orbit. With depth, pixels without renderer-written motion reconstruct motion from depth and camera movement. Without both, these pixels stay in place. Default none.

camera
:
const view: cameras.OrbitCamera
view
,
});
const
const scene: passes.Description<{
readonly hdr: typeof passes.color;
readonly motion: passes.Output<unknown, {
position: d.v4f;
}>;
readonly depth: typeof passes.depth;
}>
scene
=
import passes
passes
.
function create<Specs<{
readonly hdr: {
readonly format: "rgba16float";
readonly sampled: true;
};
readonly motion: {
readonly format: "rg16float";
readonly sampled: true;
};
readonly depth: {
readonly format: "depth24plus";
readonly sampled: true;
};
}>, {
readonly hdr: typeof passes.color;
readonly motion: passes.Output<unknown, {
position: d.v4f;
}>;
readonly depth: typeof passes.depth;
}>(root: TgpuRoot, screen: targets.Targets<Specs<{
readonly hdr: {
readonly format: "rgba16float";
readonly sampled: true;
};
readonly motion: {
readonly format: "rg16float";
readonly sampled: true;
};
readonly depth: {
readonly format: "depth24plus";
readonly sampled: true;
};
}>>, writes: {
readonly hdr: typeof passes.color;
readonly motion: passes.Output<unknown, {
position: d.v4f;
}>;
readonly depth: typeof passes.depth;
}, options?: passes.TargetOptions<...> | undefined): passes.Description<...> (+1 overload)

Describes the targets and outputs for scene passes. With a surface such as the canvas, writes only each renderer's colour. With a target set, writes colour into the target marked color, depth into the target marked depth, and other outputs into their named targets. Multisampled targets resolve according to resolve. Targets with layers draw one pass per layer, and every target the description draws into needs the same layers. add builds a renderer's drawing. begin starts a pass. pipe supplies fills such as a camera.

@param ― screen the surface, or the targets, which give the formats; each one the description names is drawn into

@param ― writes what fills each target, by its key in screen

@returns ― a description you destroy, which holds the pipelines it builds

create
(
const root: TgpuRoot
root
,
const screen: targets.Targets<Specs<{
readonly hdr: {
readonly format: "rgba16float";
readonly sampled: true;
};
readonly motion: {
readonly format: "rg16float";
readonly sampled: true;
};
readonly depth: {
readonly format: "depth24plus";
readonly sampled: true;
};
}>>
screen
,
{
hdr: typeof passes.color
hdr
:
import passes
passes
.
const color: typeof passes.color

Marks the target that receives each renderer's colour.

color
,
motion: passes.Output<unknown, {
position: d.v4f;
}>
motion
:
import taa
taa
.
const motion: passes.Output<unknown, {
position: d.v4f;
}>

This output writes surface motion into an rg16float target. It stores preceding UV position minus current UV position. It computes the preceding position by compiling renderer vertex code with history.previously, which reads the preceding camera and values of other temporal fills.

motion
,
depth: typeof passes.depth
depth
:
import passes
passes
.
const depth: typeof passes.depth

Marks the depth target.

depth
},
{
Options.jitter?: Position | undefined

Moves clip positions for rasterisation. Outputs read the original vertex positions. Use for a sub-pixel offset in temporal antialiasing. Default none.

@gpu

jitter
:
const aa: taa.Taa
aa
.
Taa.jitter: (position: d.v4f) => d.v4f

Offsets vertices by a different fraction of a source pixel each frame so frames sample the whole pixel together: 8 offsets in turn, or at size 8 for each output pixel a source pixel covers, 18 at 1.5 times per side. Supply this as jitter in passes.create.

jitter
},
)
.
Description<{ readonly hdr: typeof color; readonly motion: Output<unknown, { position: d.v4f; }>; readonly depth: typeof depth; }>.pipe(fill: Inject): passes.Description<{
readonly hdr: typeof passes.color;
readonly motion: passes.Output<unknown, {
position: d.v4f;
}>;
readonly depth: typeof passes.depth;
}>

Adds fill after existing fills and returns a description of the same passes. Piped fills take precedence over a drawing's own. For example, passes.create(…).pipe(view.inject()) uses the camera from view.

pipe
(
const view: cameras.OrbitCamera
view
.
CameraBase.inject(): Inject

Fills cameras.current for the pipelines created from the configuration it is piped into.

inject
());
const
const final: finish.Finish
final
=
import finish
finish
.
function create(root: TgpuRoot, options: finish.Options): finish.Finish

Creates the final pass of a frame. It reads the source, adds glow, tone maps, grades, applies the vignette, encodes and dithers. It draws one triangle into the caller pass.

@allocates ― on resize: a bind group for a new source or glow

@owns ― 2 buffers, a sampler, a pipeline, 2 bind groups: the settings, the regions it reads, a group for the glow and one for each texture the source returns

@records ― record into a pass of its own on the view you give, usually the canvas's, or draw into the caller's pass, after the bloom's record.

@param ― options.source the picture, rendered or a texture, read at every draw

@param ― options.region the part of the source that holds the picture, read at every draw

@param ― options.glow a bloom, or a glow of your own, added before tone mapping

@param ― options.exposure an adapted exposure, read on the GPU

@returns ― a final pass you draw every frame

create
(
const root: TgpuRoot
root
, {
Options.format: GPUTextureFormat

Sets the output format, such as the canvas format.

format
:
const surface: web.Surface
surface
.
Surface.format: GPUTextureFormat

Reports the format of its textures, which pipelines that draw into it target.

format
,
Options.source: Source

Provides the picture at any size: a rendered picture, such as aa or blur, or a function returning a texture, such as () => screen.textures.hdr. draw reads it on every call, so the texture can be rebuilt.

@cpu

source
:
const aa: taa.Taa
aa
});
  • Output size History, aa.output and aa.region take size, so bloom, exposure and the final pass read aa at the output size. While off, output is the source in its own region.
  • Reconstruction Each output pixel rebuilds the frame from the nine drawn pixels around it, weighted by where this frame’s jitter placed each one. A frame whose samples land far from the pixel counts for less.
  • Jitter Jitter stays within a drawn pixel. It takes 8 offsets for each output pixel a drawn pixel covers: 18 at two thirds of each side.
  • Changing scale History keeps through changes to the region, so the scale can follow dynamicResolution. A new size starts over.
  • Smaller sources A source texture smaller than the output, such as one made with targets.scaled, needs no region.
  • Lowest scale Draw at least two thirds of each side.
  • Mip bias Shaders of the scene that sample mipmapped textures pass a bias of log2(drawn / output) - 1 to std.textureSampleBias, -1.58 at two thirds of each side. Without it, their textures stay as blurred as the drawn size.

Particles, additive glows and dithered fades change from frame to frame without motion that explains the change. Their surroundings vary too much for the colour clamp to reject old colours, so they leave trails. A reactive texture the size of the source sets how much history to drop at each pixel. Write it from the drawings that need it:

const
const screen: targets.Targets<Specs<{
readonly hdr: {
readonly format: "rgba16float";
readonly sampled: true;
};
readonly motion: {
readonly format: "rg16float";
readonly sampled: true;
};
readonly reactive: {
readonly format: "r8unorm";
readonly sampled: true;
};
readonly depth: {
readonly format: "depth24plus";
readonly sampled: true;
};
}>>
screen
=
import targets
targets
.
function create<{
readonly hdr: {
readonly format: "rgba16float";
readonly sampled: true;
};
readonly motion: {
readonly format: "rg16float";
readonly sampled: true;
};
readonly reactive: {
readonly format: "r8unorm";
readonly sampled: true;
};
readonly depth: {
readonly format: "depth24plus";
readonly sampled: true;
};
}>(root: TgpuRoot, source: targets.SizeSource, specs: {
readonly hdr: {
readonly format: "rgba16float";
readonly sampled: true;
};
readonly motion: {
readonly format: "rg16float";
readonly sampled: true;
};
readonly reactive: {
readonly format: "r8unorm";
readonly sampled: true;
};
readonly depth: {
readonly format: "depth24plus";
readonly sampled: true;
};
}, options?: targets.Options): targets.Targets<...>

Creates render targets that follow a size. Replaces the whole set when the size changes. Put targets needed only sometimes in their own set and create that set when needed. Throws for transient targets with sampling, storage or mip levels, for multisampled targets with storage or mip levels, and for layered targets that are multisampled, mipped or have more layers than the device allows.

@param ― source the size it follows, such as a surface

@param ― specs a format and options per target, by name

@param ― options.resolution the fraction of each side drawn, which changes without allocating

@returns ― a set of targets you fit every frame and destroy

create
(
const root: TgpuRoot
root
,
const surface: web.Surface
surface
, {
hdr: {
readonly format: "rgba16float";
readonly sampled: true;
}
hdr
: {
format: "rgba16float"
format
: 'rgba16float',
sampled: true
sampled
: true },
motion: {
readonly format: "rg16float";
readonly sampled: true;
}
motion
: {
format: "rg16float"
format
: 'rg16float',
sampled: true
sampled
: true },
reactive: {
readonly format: "r8unorm";
readonly sampled: true;
}
reactive
: {
format: "r8unorm"
format
: 'r8unorm',
sampled: true
sampled
: true },
depth: {
readonly format: "depth24plus";
readonly sampled: true;
}
depth
: {
format: "depth24plus"
format
: 'depth24plus',
sampled: true
sampled
: true },
});
const
const aa: taa.Taa
aa
=
import taa
taa
.
function create(root: TgpuRoot, options: taa.Options): taa.Taa

Creates temporal antialiasing from subpixel-jittered frames. The resolve blends each frame with history sampled where motion, or depth and camera movement, place the preceding pixel. Without either, it samples history at the same pixel. It clamps history colour to the local colour spread to reduce trails and weights by brightness to reduce bright-pixel flicker. With size, it resolves a smaller source up to that size: each output pixel rebuilds the current frame from the nine source pixels around it with Lanczos-2 weights placed by this frame's jitter, and blends less of it where those weights add up to less. Record its single pass after scene passes and before the final pass reads output.

@allocates ― on resize: targets for the new size and the bind groups of its passes; so does a new source, motion, depth or reactive texture

@owns ― targets, 4 buffers, a sampler, a pipeline, 2 to 4 bind groups: two histories, each frame written into one from the other, the settings, the region and whether to blend, the jitter and its sequence, a group each for the frames that read either history with the source and motion, one for depth and one for reactive

@binds ― 1 uniform: jitter, this frame's offset

@records ― record after the passes that draw the source and the motion, before what reads output.

@param ― options.source this frame's picture, drawn through jitter, read at every record

@param ― options.motion how far each pixel's surface moved since last frame, read at every record; without it, pixels move only with the camera

@param ― options.depth the scene's depth, for the motion of the nearest surface around each pixel and for motion from the camera, or null

@returns ― a resolve you record every frame and destroy

create
(
const root: TgpuRoot
root
, {
Options.source: Source

Provides the current linear-colour picture, drawn through jitter: a function returning a texture, such as () => screen.textures.hdr, or a rendered picture. record reads it on every call.

@cpu

source
: () =>
const screen: targets.Targets<Specs<{
readonly hdr: {
readonly format: "rgba16float";
readonly sampled: true;
};
readonly motion: {
readonly format: "rg16float";
readonly sampled: true;
};
readonly reactive: {
readonly format: "r8unorm";
readonly sampled: true;
};
readonly depth: {
readonly format: "depth24plus";
readonly sampled: true;
};
}>>
screen
.
Targets<Specs<{ readonly hdr: { readonly format: "rgba16float"; readonly sampled: true; }; readonly motion: { readonly format: "rg16float"; readonly sampled: true; }; readonly reactive: { readonly format: "r8unorm"; readonly sampled: true; }; readonly depth: { ...; }; }>>.textures: {
readonly hdr: targets.Target<{
readonly format: "rgba16float";
readonly sampled: true;
}>;
readonly motion: targets.Target<{
readonly format: "rg16float";
readonly sampled: true;
}>;
readonly reactive: targets.Target<{
readonly format: "r8unorm";
readonly sampled: true;
}>;
readonly depth: targets.Target<{
readonly format: "depth24plus";
readonly sampled: true;
}>;
}

Provides the current textures. A size change replaces them.

textures
.
hdr: targets.Target<{
readonly format: "rgba16float";
readonly sampled: true;
}>
hdr
,
Options.motion?: (() => targets.FloatTexture) | undefined

Returns the motion texture written by motion. Each vector is the preceding UV position minus the current UV position. record reads it on every call. Default none, which moves every pixel as camera moves depth, or keeps it in place without both.

@cpu

motion
: () =>
const screen: targets.Targets<Specs<{
readonly hdr: {
readonly format: "rgba16float";
readonly sampled: true;
};
readonly motion: {
readonly format: "rg16float";
readonly sampled: true;
};
readonly reactive: {
readonly format: "r8unorm";
readonly sampled: true;
};
readonly depth: {
readonly format: "depth24plus";
readonly sampled: true;
};
}>>
screen
.
Targets<Specs<{ readonly hdr: { readonly format: "rgba16float"; readonly sampled: true; }; readonly motion: { readonly format: "rg16float"; readonly sampled: true; }; readonly reactive: { readonly format: "r8unorm"; readonly sampled: true; }; readonly depth: { ...; }; }>>.textures: {
readonly hdr: targets.Target<{
readonly format: "rgba16float";
readonly sampled: true;
}>;
readonly motion: targets.Target<{
readonly format: "rg16float";
readonly sampled: true;
}>;
readonly reactive: targets.Target<{
readonly format: "r8unorm";
readonly sampled: true;
}>;
readonly depth: targets.Target<{
readonly format: "depth24plus";
readonly sampled: true;
}>;
}

Provides the current textures. A size change replaces them.

textures
.
motion: targets.Target<{
readonly format: "rg16float";
readonly sampled: true;
}>
motion
,
Options.reactive?: (() => targets.FloatTexture) | undefined

Returns a texture the size of the source whose red channel, from 0 to 1, takes away history at each pixel, for translucent, dithered or particle drawings that write no motion of their own. 0 accumulates as usual; values above 0.9 count as 0.9, so history never drops out. record reads it on every call. Default none.

@cpu

reactive
: () =>
const screen: targets.Targets<Specs<{
readonly hdr: {
readonly format: "rgba16float";
readonly sampled: true;
};
readonly motion: {
readonly format: "rg16float";
readonly sampled: true;
};
readonly reactive: {
readonly format: "r8unorm";
readonly sampled: true;
};
readonly depth: {
readonly format: "depth24plus";
readonly sampled: true;
};
}>>
screen
.
Targets<Specs<{ readonly hdr: { readonly format: "rgba16float"; readonly sampled: true; }; readonly motion: { readonly format: "rg16float"; readonly sampled: true; }; readonly reactive: { readonly format: "r8unorm"; readonly sampled: true; }; readonly depth: { ...; }; }>>.textures: {
readonly hdr: targets.Target<{
readonly format: "rgba16float";
readonly sampled: true;
}>;
readonly motion: targets.Target<{
readonly format: "rg16float";
readonly sampled: true;
}>;
readonly reactive: targets.Target<{
readonly format: "r8unorm";
readonly sampled: true;
}>;
readonly depth: targets.Target<{
readonly format: "depth24plus";
readonly sampled: true;
}>;
}

Provides the current textures. A size change replaces them.

textures
.
reactive: targets.Target<{
readonly format: "r8unorm";
readonly sampled: true;
}>
reactive
,
Options.depth: (() => targets.Depth) | null

Returns sampled scene depth without stencil, or null for a picture drawn without depth. Motion then follows the nearest surrounding surface to avoid smearing moving edges over the background. record reads it on every call. Unused without motion or camera. With null, motion is read at each pixel.

@cpu

depth
: () =>
const screen: targets.Targets<Specs<{
readonly hdr: {
readonly format: "rgba16float";
readonly sampled: true;
};
readonly motion: {
readonly format: "rg16float";
readonly sampled: true;
};
readonly reactive: {
readonly format: "r8unorm";
readonly sampled: true;
};
readonly depth: {
readonly format: "depth24plus";
readonly sampled: true;
};
}>>
screen
.
Targets<Specs<{ readonly hdr: { readonly format: "rgba16float"; readonly sampled: true; }; readonly motion: { readonly format: "rg16float"; readonly sampled: true; }; readonly reactive: { readonly format: "r8unorm"; readonly sampled: true; }; readonly depth: { ...; }; }>>.textures: {
readonly hdr: targets.Target<{
readonly format: "rgba16float";
readonly sampled: true;
}>;
readonly motion: targets.Target<{
readonly format: "rg16float";
readonly sampled: true;
}>;
readonly reactive: targets.Target<{
readonly format: "r8unorm";
readonly sampled: true;
}>;
readonly depth: targets.Target<{
readonly format: "depth24plus";
readonly sampled: true;
}>;
}

Provides the current textures. A size change replaces them.

textures
.
depth: targets.Target<{
readonly format: "depth24plus";
readonly sampled: true;
}>
depth
,
Options.camera?: cameras.CameraBase | undefined

Supplies the scene camera with its preceding view, such as cameras.orbit. With depth, pixels without renderer-written motion reconstruct motion from depth and camera movement. Without both, these pixels stay in place. Default none.

camera
:
const view: cameras.OrbitCamera
view
,
});
// How much history to drop where a drawing covers
const
const fresh: passes.Output<unknown, unknown>
fresh
=
import passes
passes
.
function output<d.F32, unknown, unknown, undefined>(schema: d.F32, spec: {
readonly clear?: number | undefined;
readonly varyings?: undefined;
readonly vary?: ((current: unknown, previous: unknown) => undefined) | undefined;
readonly previous?: boolean;
readonly write: (pixel: unknown, carried: undefined) => number;
}): passes.Output<unknown, unknown>

Defines how a pass writes one target from renderer data. write takes the renderer's data at a pixel, and its parameter type declares the fields it needs. For vertex data, supply varyings and vary. vary runs per vertex, and its interpolated result reaches write. With previous: true, vary also receives the previous frame's vertex. Throws if vary has no varyings schema, previous has no vary, or vary takes two parameters without previous: true.

@param ― schema what the target holds per pixel, such as d.vec2f for an rg16float target

@param ― spec write, which gives the value at a pixel, and what it clears to and carries from the vertex

@returns ― an output to give a target in passes.create

output
(
import d
d
.
const f32: d.F32
export f32

A schema that represents a 32-bit float value. (equivalent to f32 in WGSL)

Can also be called to cast a value to an f32.

@example const value = f32(); // 0

@example const value = f32(1.23); // 1.23

@example const value = f32(true); // 1

f32
, {
write: (pixel: unknown, carried: undefined) => number
write
: () => {
'use gpu';
return 0.8;
},
});
const
const scene: passes.Description<{
readonly hdr: typeof passes.color;
readonly motion: passes.Output<unknown, {
position: d.v4f;
}>;
readonly reactive: passes.Output<unknown, unknown>;
readonly depth: typeof passes.depth;
}>
scene
=
import passes
passes
.
function create<Specs<{
readonly hdr: {
readonly format: "rgba16float";
readonly sampled: true;
};
readonly motion: {
readonly format: "rg16float";
readonly sampled: true;
};
readonly reactive: {
readonly format: "r8unorm";
readonly sampled: true;
};
readonly depth: {
readonly format: "depth24plus";
readonly sampled: true;
};
}>, {
readonly hdr: typeof passes.color;
readonly motion: passes.Output<unknown, {
position: d.v4f;
}>;
readonly reactive: passes.Output<unknown, unknown>;
readonly depth: typeof passes.depth;
}>(root: TgpuRoot, screen: targets.Targets<Specs<...>>, writes: {
readonly hdr: typeof passes.color;
readonly motion: passes.Output<unknown, {
position: d.v4f;
}>;
readonly reactive: passes.Output<unknown, unknown>;
readonly depth: typeof passes.depth;
}, options?: passes.TargetOptions<...> | undefined): passes.Description<...> (+1 overload)

Describes the targets and outputs for scene passes. With a surface such as the canvas, writes only each renderer's colour. With a target set, writes colour into the target marked color, depth into the target marked depth, and other outputs into their named targets. Multisampled targets resolve according to resolve. Targets with layers draw one pass per layer, and every target the description draws into needs the same layers. add builds a renderer's drawing. begin starts a pass. pipe supplies fills such as a camera.

@param ― screen the surface, or the targets, which give the formats; each one the description names is drawn into

@param ― writes what fills each target, by its key in screen

@returns ― a description you destroy, which holds the pipelines it builds

create
(
const root: TgpuRoot
root
,
const screen: targets.Targets<Specs<{
readonly hdr: {
readonly format: "rgba16float";
readonly sampled: true;
};
readonly motion: {
readonly format: "rg16float";
readonly sampled: true;
};
readonly reactive: {
readonly format: "r8unorm";
readonly sampled: true;
};
readonly depth: {
readonly format: "depth24plus";
readonly sampled: true;
};
}>>
screen
,
{
hdr: typeof passes.color
hdr
:
import passes
passes
.
const color: typeof passes.color

Marks the target that receives each renderer's colour.

color
,
motion: passes.Output<unknown, {
position: d.v4f;
}>
motion
:
import taa
taa
.
const motion: passes.Output<unknown, {
position: d.v4f;
}>

This output writes surface motion into an rg16float target. It stores preceding UV position minus current UV position. It computes the preceding position by compiling renderer vertex code with history.previously, which reads the preceding camera and values of other temporal fills.

motion
,
reactive: passes.Output<unknown, unknown>
reactive
:
const fresh: passes.Output<unknown, unknown>
fresh
,
depth: typeof passes.depth
depth
:
import passes
passes
.
const depth: typeof passes.depth

Marks the depth target.

depth
},
{
Options.jitter?: Position | undefined

Moves clip positions for rasterisation. Outputs read the original vertex positions. Use for a sub-pixel offset in temporal antialiasing. Default none.

@gpu

jitter
:
const aa: taa.Taa
aa
.
Taa.jitter: (position: d.v4f) => d.v4f

Offsets vertices by a different fraction of a source pixel each frame so frames sample the whole pixel together: 8 offsets in turn, or at size 8 for each output pixel a source pixel covers, 18 at 1.5 times per side. Supply this as jitter in passes.create.

jitter
},
)
.
Description<{ readonly hdr: typeof color; readonly motion: Output<unknown, { position: d.v4f; }>; readonly reactive: Output<unknown, unknown>; readonly depth: typeof depth; }>.pipe(fill: Inject): passes.Description<{
readonly hdr: typeof passes.color;
readonly motion: passes.Output<unknown, {
position: d.v4f;
}>;
readonly reactive: passes.Output<unknown, unknown>;
readonly depth: typeof passes.depth;
}>

Adds fill after existing fills and returns a description of the same passes. Piped fills take precedence over a drawing's own. For example, passes.create(…).pipe(view.inject()) uses the camera from view.

pipe
(
const view: cameras.OrbitCamera
view
.
CameraBase.inject(): Inject

Fills cameras.current for the pipelines created from the configuration it is piped into.

inject
());
const
const solid: passes.Drawn
solid
=
const scene: passes.Description<{
readonly hdr: typeof passes.color;
readonly motion: passes.Output<unknown, {
position: d.v4f;
}>;
readonly reactive: passes.Output<unknown, unknown>;
readonly depth: typeof passes.depth;
}>
scene
.
Into<{ readonly hdr: typeof color; readonly motion: Output<unknown, { position: d.v4f; }>; readonly reactive: Output<unknown, unknown>; readonly depth: typeof depth; }>.without<"reactive">(...keys: "reactive"[]): passes.Into<Omit<{
readonly hdr: typeof passes.color;
readonly motion: passes.Output<unknown, {
position: d.v4f;
}>;
readonly reactive: passes.Output<unknown, unknown>;
readonly depth: typeof passes.depth;
}, "reactive">>

Returns a description with keys left out for a renderer that cannot write them. Opaque drawings write each omitted output's clear. Drawings with a blend preserve the value underneath. No varyings are carried for omitted outputs.

without
('reactive').
Into<Omit<{ readonly hdr: typeof color; readonly motion: Output<unknown, { position: d.v4f; }>; readonly reactive: Output<unknown, unknown>; readonly depth: typeof depth; }, "reactive">>.add<d.WgslStruct<{
position: d.Vec4f;
}>, {
color: d.v4f;
}>(drawing: passes.Drawing<d.WgslStruct<{
position: d.Vec4f;
}>, {
color: d.v4f;
}>): passes.Drawn (+1 overload)

Builds a pipeline for drawing that writes every described output and returns its draw methods. If the drawing cannot supply the fields an output reads, type checking fails with that target's name and those fields. Use without to leave it out or instead to replace it.

add
(
const beams: passes.Drawing<d.WgslStruct<{
position: d.Vec4f;
}>, {
color: d.v4f;
}>
beams
);
const
const flying: passes.Drawn
flying
=
const scene: passes.Description<{
readonly hdr: typeof passes.color;
readonly motion: passes.Output<unknown, {
position: d.v4f;
}>;
readonly reactive: passes.Output<unknown, unknown>;
readonly depth: typeof passes.depth;
}>
scene
.
Into<{ readonly hdr: typeof color; readonly motion: Output<unknown, { position: d.v4f; }>; readonly reactive: Output<unknown, unknown>; readonly depth: typeof depth; }>.add<d.WgslStruct<{
position: d.Vec4f;
}>, {
color: d.v4f;
}>(drawing: passes.Drawing<d.WgslStruct<{
position: d.Vec4f;
}>, {
color: d.v4f;
}>): passes.Drawn (+1 overload)

Builds a pipeline for drawing that writes every described output and returns its draw methods. If the drawing cannot supply the fields an output reads, type checking fails with that target's name and those fields. Use without to leave it out or instead to replace it.

add
(
const sparks: passes.Drawing<d.WgslStruct<{
position: d.Vec4f;
}>, {
color: d.v4f;
}>
sparks
);
  • 0 accumulates as usual. Higher values take that share of history’s weight away, up to 0.9, so some history always stays and edges stay smooth.
  • Draw opaque drawings first. One left out with without writes 0 over what is beneath it, while a blended one keeps it.
  • Write what changes, such as a particle’s alpha, for soft edges.
  • Without reactive, the resolve binds and reads nothing more.
Part
aa.settings Blend and spread, a uniform.
aa.jitter, aa.offset The jitter for passes.create, and this frame’s offset in clip space, a uniform.
aa.output, aa.region Antialiased rgba16float image at size or the source’s, and its region, or the source while off. Read each frame because output alternates between two textures.
aa.enabled Whether enable last turned it on.
  • The kit’s model materials sample textures without a mip bias, so at size their textures stay as blurred as the drawn size.
  • TAA writes alpha 1, so it doesn’t suit a canvas over a page.
  • A renderer that leaves out motion, such as an additive glow, takes the motion of what is under it.
  • Moving instances, trails, text and skinned poses need their own motion to avoid dimming. Their default motion includes only the camera.
  • Lines thinner than one drawn pixel can lose most of their brightness, even while stationary.
frameA frame is one turn of the loop, and the object your function gets for it, which holds the encoder, the time and the time since the last frame.You own the frame →
drawingA drawing is what a renderer hands to a pass description: what each vertex carries to its pixels, what a pixel looks like and the draw call.Every renderer is a drawing →
rendererA renderer draws one sort of thing, such as instances or particles, by handing a pass description a drawing.Every renderer is a drawing →
instanceAn instance is one copy of a mesh with its own position, rotation, scale and material, kept as a row of a table.Instances →
tableA table is a buffer of rows with named fields, some written by the CPU and the others by kernels.Rows →
rowA row is one object's values in a buffer, such as one enemy, one particle or one light.Objects are rows in buffers →
kernelA kernel is a compute function that the GPU runs many times at once, each run on its own thread.A frame in plain TypeGPU →
outputAn output is a value every drawing writes at each pixel beside its colour, such as motion or an id.Outputs every drawing writes →

Reference

Callsborrows, never destroystakesneeds a modulereturns

taa.create(root, { source, motion?, depth, camera?, … }) → Taa

root
the root
source
this frame's picture, drawn through jitter, read at every record
motion?
how far each pixel's surface moved since last frame, read at every record; without it, pixels move only with the camera
depth
the scene's depth, for the motion of the nearest surface around each pixel and for motion from the camera, or null
camera?
cameras
Taa
a resolve you record every frame and destroy
takes

Options

9 fields
source

Source

Provides the current linear-colour picture, drawn through jitter: a function returning a texture, such as () => screen.textures.hdr, or a rendered picture.

motion?

() => FloatTexture

Returns the motion texture written by motion.Default none, which moves every pixel as camera moves depth, or keeps it in place without both.

depth

(() => Depth) | null

Returns sampled scene depth without stencil, or null for a picture drawn without depth.

camera?

CameraBase

Supplies the scene camera with its preceding view, such as cameras.orbit.Default none.

reversed?

boolean

Reads depth as reversed, 1 at the near plane and 0 at the far plane, without a camera to say so.Default the camera's cameras.reversed, or false without one.

region?

SizeSource

Selects the source region from its top-left corner, such as regions.hdr when drawing below full resolution.Default the region of a rendered source, else the whole texture.

size?

SizeSource

Resolves to this size, such as the surface, from a source drawn smaller, up to 1.5 times larger per side.Default the source region's size.

reactive?

() => FloatTexture

Returns a texture the size of the source whose red channel, from 0 to 1, takes away history at each pixel, for translucent, dithered or particle drawings that write no motion of their own.Default none.

settings?

Partial<Settings>

Sets initial values over defaults.Default defaults, with blend 0.1 and spread 1.

returns

Taa

11 members
settings

TgpuUniform<Settings>

Holds defaults with overrides from settings.

jitter(position)

Offsets vertices by a different fraction of a source pixel each frame so frames sample the whole pixel together: 8 offsets in turn, or at size 8 for each output pixel a source pixel covers, 18 at 1.5 times per side.

offset

TgpuUniform<d.Vec2f>

Holds the current clip-space offset used by jitter, for custom jitter shaders.

output

FloatTexture

Provides the antialiased image in rgba16float for the final pass source.

region

SizeSource

Gives the part of output that holds the picture: all of it at size, else the source region, which is also the region while disabled.

enabled

boolean

Reports whether TAA is on, as the last enable set it.

enable(on)

Enables or disables TAA.

reset()

Resets history to the current frame, for example after a camera cut.

initAsync()

Compiles the pipeline and binds both history textures.

record(target, options?)

Records the resolve after source and motion passes, then sets jitter for the next frame.

destroy()

Destroys the history textures and the jitter sequence.

In a frame

records

record after the passes that draw the source and the motion, before what reads output.

Holds

owns

targets ·4 buffers ·a sampler ·a pipeline ·2 to 4 bind groups

Two histories, each frame written into one from the other, the settings, the region and whether to blend, the jitter and its sequence, a group each for the frames that read either history with the source and motion, one for depth and one for reactive.

allocates

on resize

Targets for the new size and the bind groups of its passes; so does a new source, motion, depth or reactive texture.

lifecycle

initAsync()destroy()[Symbol.dispose]

binds
  • 1 uniform

    jitter, this frame's offset.

Connects to

needs
  • cameras

    As options.camera; fills a hook in its pipelines.

Exports

GPU functions
written
outputs
motion
schemas
Settings
constants
defaults
schema

Settings

2 fields
blend

d.f32

Sets the fraction of current-frame colour to blend, from 0 to 1.

spread

d.f32

Limits history colour to this many standard deviations from current colours around the pixel.

used byClassroomCloisterJelly worldLatticeNight marketSurvey model