Drawing
Temporal anti-aliasing
MSAA takes several samples of a pixel in one frame, at a cost in memory, and only for triangle edges. Temporal anti-aliasing (TAA) takes one sample per frame, at a different point of the pixel each frame, and blends the frames. Over a few frames each pixel sees many points, and edges, thin lines, texture detail and highlights all get smooth, for the cost of one full-screen pass. The hard part is motion: the frames before must be found where things were then. This page explains the jitter, the history, motion vectors, how to stop ghosts and blur, and when to start over. The last part shows how RASM does it.
In short
- Each frame moves the projection by a sub-pixel jitter, so the one sample per pixel lands somewhere else in it. A short sequence (Halton) covers the pixel evenly in 8 frames.
- A history image keeps the blend of the frames before: each frame adds about 10 % of its own color.
- Things move, so the history is read where the point was last frame: motion vectors, from the last frame's object transforms and camera.
- What the history saw that is gone now (a surface that moved away) would ghost. The history is clipped to the colors around the pixel this frame.
- Resampling every frame blurs, so the history is read with a sharp filter (Catmull-Rom), and textures with a negative mip bias. Bright pixels are weighted down so they do not flicker.
- On a camera cut, a resize or the first frame, the history is dropped.
1The jitter: a different sample each frame
The rasterizer samples each pixel at its center. Move the whole projection by a fraction of a pixel and it samples another point. TAA moves it every frame along a short sequence that fills the pixel evenly, the Halton sequence in bases 2 and 3:
Blending the frames then averages the pixel over these points: an edge that covers a third of the pixel ends at a third of the way between its two colors, as with MSAA. Try it on one edge pixel:
2The history and motion vectors
The history is last frame's output. Each frame mixes a small share of the new frame into it: output = lerp(history, current, 0.1), an exponential mean of about the last 10 frames. In a still scene that is all. But when the camera or an object moves, last frame's color for this pixel is somewhere else in the history. A motion vector says where:
motion = (ndcnow − ndclast) · (0.5, −0.5)
- ndcnow
- the point through this frame's camera, without the jitter, divided by w
- ndclast
- the same point of the model through last frame's object transform and last frame's camera
- (0.5, −0.5)
- from NDC (y up) to texture coordinates (v down)
So the renderer keeps, for every object, the transform it drew last frame, and for every view, last frame's view-projection. A still object under a moving camera has motion too: only the camera changed. The sky is infinitely far: only the camera's turn moves it. At an object's outline, the pixel takes the motion of the nearest surface among its 3 × 3 neighbors, so the outline moves with the object and not with what is behind it.
3Ghosts and clipping
The history is wrong where what it saw is gone: a surface moved away and uncovered what is behind it (a disocclusion), a light turned off, an object left the screen. Read through the motion of what is there now, the history still holds the old color, and fades only by 10 % a frame: a ghost trail.
The fix: what the pixel shows this frame is most likely among the colors around it this frame. So the history is clipped into the range of the 3 × 3 neighbors' colors: their mean plus or minus one standard deviation, in YCoCg (brightness and two color differences, which fits colors tighter than RGB). A history color outside that box is moved toward its center until it is inside.
Clamp
Each channel is cut to the box. Simple, but the result can be a color that was in neither.
Clip
The history moves toward the box's center until it is inside: it keeps its direction, so the hue changes less.
Variance box
Mean ± one standard deviation of the 9 neighbors: tighter than their minimum and maximum, so one odd neighbor does not open the box wide.
4Staying sharp, staying calm
A sharp resample
The history is read at a point between texels every frame. Bilinear filtering would blur it a little each time; a Catmull-Rom filter (5 bilinear taps) keeps edges sharp.
A mip bias
The frames together see more detail than one frame. Textures are read one mip sharper (bias −1), or the image looks soft; the blend hides the extra aliasing that would cause in one frame.
Brightness weights
HDR light can hold one very bright sample (a specular sparkle) that flashes in and out. Blending colors compressed by c / (1 + luminance) and turning the result back weighs it down, the same weights as an HDR MSAA resolve.
5When to start over
The history only helps when last frame shows the same place. It is dropped, and the output is the current frame alone for a frame, when:
| Case | Why |
|---|---|
| the first frame | there is no history yet |
| a resize | the history's pixels no longer match the screen's |
| a camera cut | the application jumps to another shot; it says so with a call |
| a camera jump | the camera turned or moved so far in one frame that almost nothing of the history fits; the history would show as a ghost of the old view |
| a point now outside last frame's screen | for that pixel only: there is no history for it |
A jump needs a threshold. A turn has a natural one, an angle; a move needs a length that fits the scene's scale, which the camera's near plane gives (a scene in meters has a near plane of about 0.1 m, one in kilometers a larger one). Fast motion that is not a jump keeps the history, but gives the current frame more weight, since fast-moving history is resampled more and blurs.
6TAA and MSAA
| MSAA | TAA | |
|---|---|---|
| What it smooths | triangle edges and cut-outs (with alpha-to-coverage) | everything: edges, thin lines, textures, specular highlights |
| Memory | N samples of color and depth (95 MiB at 4x, 1080p) | a history (two copies) and a motion image |
| Cost | more where there are edges | one full-screen pass, the motion output |
| Weaknesses | no help inside triangles | a little blur, ghosts where clipping fails (see-through surfaces), the first frames after a cut |
| Needs | nothing more | motion vectors, last frame's transforms, a jittered projection |
Both together cost both and help little more, so engines usually pick one. Deferred renderers and games with much fine detail use TAA; forward renderers, VR and tools that need a crisp image use MSAA.
7Pitfalls
- Trails behind moving objects
- No clipping, or wrong motion: an object whose last transform is not kept moves with zero motion and smears.
- A still image shakes by a pixel
- The jitter is in the image: a pass after TAA read the jittered scene, or the motion was computed with the jitter in it.
- Everything is a little blurry
- Bilinear history resampling and no mip bias. Use a sharp filter and a negative bias; a light sharpen after TAA is the last resort.
- See-through surfaces smear
- A glass pane over a moving background keeps the background's motion; its own color is clipped against neighbors that mix both. A known limit of TAA.
- A camera cut shows the old shot for a moment
- The history was not dropped. Reset it on cuts.
- Specular sparkles flicker
- Blending raw HDR: weight by brightness.
8In RASM
The scene target gets a second color, MOTION_FORMAT (R16G16_SFLOAT), which the scene passes fill. Renderer::addTaaPass jitters the view and adds the TAA compute pass, which writes a history target that bloom and the tone map read. With Renderer::render, one line turns it on, before the engine is made:
config.antiAliasing = rasm::AntiAliasing::TAA;
SAMPLED and STORAGE.Last frame's transforms
Each instance row of the GPU scene keeps previousWorld, the rows of the affine world matrix the frame before drew (48 of the row's 164 bytes). It is written only through GpuTable::setRow in the frame's sync, like every row. A sub-mesh that a clip moves (keyframe animation) gets its matrices, previousWorld included, from the Animate pass instead, which reads last frame's matrix from the other frame slot; the shaders read both kinds through getPreviousWorldPosition:
- updateTransformrows: new world, previousWorld = the last synced matrix
- syncthe new matrix becomes the synced one
- this framemotion = new − old
- next sync, no moverows again: previousWorld = world
- next frameno motion
A skinned or morphed vertex moves inside its mesh too, so one matrix cannot say where it was. The Skin pass writes the posed vertices to one buffer per frame slot, and a vertex keeps its index in both. So the frame before's position is the same vertex in the other slot's buffer (SceneData::previousSkinnedVertsPtr), read by getPreviousObjectPosition and then moved by previousWorld:
setMorphWeights after none, a clearMorphWeights and a growth of the buffers have no frame before, so the Animate pass writes skinnedMotion = 0 for that frame and the shader takes this frame's vertex for both. A smooth change of the weights is motion, like a clip.Where RASM follows this page, and where it differs
| Part | This page | RASM |
|---|---|---|
| Jitter | Halton (2, 3) | getTaaJitter: points 1 to TAA_JITTER_PHASES (8), from a counter per scene view (SceneView::jitterFrame), so the same frames give the same pixels. writeViewMotion puts it in the projection as a translation of clip space, which removeJitter takes out of the motion and the sky. |
| Motion | last transforms, last camera | InstanceData::previousWorld (or an animated sub-mesh's InstanceTransform::previousWorld, from the Animate pass; a skinned or morphed vertex's last position from the other slot's skinned vertices), SceneData::previousViewProjection and jitter. Each view draws in its camera's render space, whose origin moves with the camera, so the rows' last translation is stored as last minus now, and the view keeps last frame's view-projection in world space, in doubles (SceneView::previousViewProjection), moved into this frame's render space (large worlds); the uber, MASK and sky pipelines of a target with a motion color are compiled with RASM_MOTION_VECTORS. A BLEND draw writes zero motion with alpha 0, which its premultiplied blend turns into "keep": see-through surfaces keep the motion behind them. |
| See-through motion | — | A sorted see-through draw keeps the motion behind it, a vector feature lays its own over it by its alpha. Weighted surfaces sum motion × alpha × weight, and the composite lays their mean motion over the motion behind by their coverage; additive ones lay theirs by their alpha (weighted blended transparency). |
| The pass | nearest motion, clip, sharp resample, weights | taaMain in shaders/passes/taa.slang: the nearest of 3 × 3 depths picks the motion; the history through 5 Catmull-Rom taps; clipped to mean ± 1 σ in YCoCg; blended at 10 % (30 % when the pixel moves 8 pixels a frame or more), on colors compressed by 1 / (1 + luminance · exposure). |
| Mip bias | about −1 | TAA_TEXTURE_LOD_BIAS (−1) in SceneData::textureLodBias, read by sampleMaterial for every material texture of a jittered view. |
| Resets | first frame, resize, cut, jump | The pass keeps its last size, its history's RenderTarget::version (a resize or a new swapchain makes new textures, at any size, under the same handles), camera and Camera::historyResets, in a TaaState. Renderer::resetCameraHistory counts that up. A jump is a turn above TAA_JUMP_ANGLE (30°) or a move above TAA_JUMP_NEAR_PLANES (100) near planes, for an orthographic camera half its width (isCameraJump). |
| With MSAA | usually one or the other | One or the other: addTaaPass refuses a multisampled source, and AntiAliasing is one value. |
| Sharpen | last resort | None: side by side with no anti-aliasing and MSAA 4x, the result was not clearly softer. |
What it costs
examples/09_gltf_materials --aa taa, RTX 3060, Release, median of 5 runsWhere it lives in code
| What | Where |
|---|---|
| The pass | Renderer::addTaaPass in src/renderer/taa.cpp; shaders/passes/taa.slang; gfx::TaaPushConstants |
| Jitter and jumps | getTaaJitter, isCameraJump and the constants in src/renderer/taa.h; tested in tests/taaTests.cpp |
| Motion | writeViewMotion and Renderer::writeInstanceRows in src/renderer/gpuScene.cpp; removeJitter, getMotion in shaders/lib/core.slang; shaders/passes/rasm.slang and shaders/passes/sky.slang |
| Storage history | RenderTargetDesc::storage with history: one storage slot per copy (RenderTarget::storageSlots); the graph moves last frame's copy to SAMPLED for readPrevious |
| The default frame | ViewGraph::addView in src/renderer/viewGraph.cpp with EngineConfig::antiAliasing or View::antiAliasing: each view keeps its history target and TaaState in its ViewState, so a new graph (another view added, removed or moved) goes on with the history (Many views of one scene) |
| Examples | examples/09_gltf_materials (its lantern turns 1° a frame) and examples/02_gltf (its models turn): --aa taa |
- Instance rows change only through
setRow, and the frame's sync is what turns a moved entity's matrix into last frame's. - The motion and the sky take the jitter out; nothing after TAA reads the jittered scene.
- The same frames give the same pixels: the jitter comes from a frame counter, never from time or random numbers.
- A new kind of moving geometry also needs last frame's vertices, or it smears. Skinning and morph targets get them from the
Skinpass's other slot.
Further reading
- Brian Karis, "High Quality Temporal Supersampling" (SIGGRAPH 2014, Advances in Real-Time Rendering): Unreal Engine 4's TAA.
- Lasse Jon Fuglsang Pedersen, "Temporal Reprojection Anti-Aliasing in INSIDE" (GDC 2016): clipping toward the center.
- Marco Salvi, "An Excursion in Temporal Supersampling" (GDC 2016): variance clipping.
- Lei Yang, Shiqiu Liu, Marco Salvi, "A Survey of Temporal Antialiasing Techniques" (Eurographics 2020).