Three.js Temporal Anti-Aliasing (TAA from Scratch)
Temporal anti-aliasing implemented by hand in Three.js, with Halton sub-pixel jitter via setViewOffset, an exponential history buffer and neighbourhood clamping, shown split-screen against the raw aliased frame.
Key topics: three.js taa, temporal anti aliasing, jitter, halton sequence, history buffer, ghosting
Game Over
What this code does
- Jitter: each frame shifts the projection by a Halton(2,3) sub-pixel offset using `camera.setViewOffset`.
- Accumulation: the resolve blends each frame into history with weight α, effectively supersampling over time.
- Neighbourhood Clamp: history is clamped to the 3×3 min/max of the current frame, which limits ghosting when things move.
- Aliasing Bait: nearest-filtered checkers, thin wires and spokes shimmer on the raw side and settle on the TAA side.
- Ghosting Test: moving the camera without motion vectors shows why clamping (or reprojection) is essential.
- Controls: show TAA, split, blend α, clamp, jitter sequence length, zoom, camera motion and animation.
Related Demos
Continue Learning
JavaScript Implementation
// Temporal AA core: jitter, render, blend with clamped history
const halton = (i, b) => { let f = 1, r = 0; while (i > 0) { f /= b; r += f * (i % b); i = Math.floor(i / b) } return r }
let frame = 0
function renderTAA () {
const i = (frame % 16) + 1
camera.setViewOffset(w, h, halton(i, 2) - 0.5, halton(i, 3) - 0.5, w, h) // sub-pixel shift
renderer.setRenderTarget(current); renderer.render(scene, camera)
camera.clearViewOffset()
// resolve shader: hist = clamp(history, min3x3(current), max3x3(current)); out = mix(hist, current, 0.1)
renderer.setRenderTarget(historyB); renderer.render(resolveScene, quadCamera)
;[historyA, historyB] = [historyB, historyA]
frame++
}