跳到主要内容
← Advanced Rendering

Advanced Rendering

TAA - Neighbor clamping

In Temporal Anti-Aliasing (TAA), [velocity reprojection](https://shader-learning.com/module-training/advanced-rendering/task/taa-velocity-based-reprojection) he

代码复盘 GLSL

第 18 课:TAA - Neighbor clamping

实现:In Temporal Anti-Aliasing (TAA), velocity reprojection helps align history with moving objects, reducing ghosting. But even with velocity reprojection, ghosting can persist due to:

本课需 多 pass / 后处理,暂以代码复盘呈现。

实现

uniform vec2 iResolution;

uniform sampler2D iRTBuffer0;      // curr color
uniform sampler2D iRTBuffer1;      // velocity
uniform sampler2D iPrevFrameColor; // prev color

out vec4 FragColor;

void main() {
  vec2 uv = gl_FragCoord.xy / iResolution.xy;
  vec2 texelSize = 1.0 / iResolution.xy;

  vec2 velocity = texture(iRTBuffer1, uv).xy;

  vec4 prevColor = texture(iPrevFrameColor, uv - velocity);
  vec4 currColor = texture(iRTBuffer0, uv);

  vec4 c0 = texture(iRTBuffer0, uv + vec2(+1.0, 0.0) * texelSize);
  vec4 c1 = texture(iRTBuffer0, uv + vec2( 0.0,+1.0) * texelSize);
  vec4 c2 = texture(iRTBuffer0, uv + vec2(-1.0, 0.0) * texelSize);
  vec4 c3 = texture(iRTBuffer0, uv + vec2( 0.0,-1.0) * texelSize);
  vec4 minColor = min(currColor, min(c0, min(c1, min(c2, c3))));
  vec4 maxColor = min(currColor, max(c0, max(c1, max(c2, c3))));
  prevColor = clamp(prevColor, minColor, maxColor);

  FragColor = mix(currColor, prevColor, 0.9);
}

复盘笔记

  • In Temporal Anti-Aliasing (TAA), velocity reprojection helps align history with moving objects, reducing ghosting. But even with velocity reprojection, ghosting can persist due to:
  • Disocclusion. New pixels revealed behind moving objects have no valid history, so they get blended with irrelevant data.
  • Incorrect motion vectors. Transparent objects, particles, or post-processing may produce invalid motion data.
  • History accumulation. Even correctly reprojected pixels can accumulate outdated color if not clamped or rejected.
  • Low-resolution velocity buffers. Aliased or quantized motion vectors lead to misaligned reprojection.