Move new Temporal AA code to shared header

This commit is contained in:
2026-05-12 17:09:21 +02:00
parent b38f6c5721
commit fc8a9b69d2
3 changed files with 40 additions and 28 deletions
Binary file not shown.
+2 -26
View File
@@ -15,7 +15,6 @@
#define DEBUG_MOTION 0 #define DEBUG_MOTION 0
#define DEBUG_VELOCITY_REJECTION 0 #define DEBUG_VELOCITY_REJECTION 0
#define TAA_EPSILON 0.000001f
#define NO_GBUFFER_SAMPLING #define NO_GBUFFER_SAMPLING
#define NEED_DEPTH_VELOCITY (MINMAX_4TAP_VARYING) #define NEED_DEPTH_VELOCITY (MINMAX_4TAP_VARYING)
#if NEED_DEPTH_VELOCITY #if NEED_DEPTH_VELOCITY
@@ -149,23 +148,6 @@ VelocityDepth SampleVelocityDepth(float2 uv)
return velocityDepth; return velocityDepth;
} }
float4 ClipAAB(float3 aabbMin, float3 aabbMax, float4 p, float4 q)
{
// only clips towards aabb center
float3 pClip = 0.5 * (aabbMax + aabbMin);
float3 eClip = 0.5 * (aabbMax - aabbMin) + TAA_EPSILON;
float4 vClip = q - float4(pClip, p.w);
float3 vUnit = vClip.xyz / eClip;
float3 aUnit = abs(vUnit);
float maUnit = max(aUnit.x, max(aUnit.y, aUnit.z));
if (maUnit > 1.0)
return float4(pClip, p.w) + vClip / maUnit;
else
return q; // point inside aabb
}
// Pixel Shader for Temporal Anti-Aliasing // Pixel Shader for Temporal Anti-Aliasing
META_PS(true, FEATURE_LEVEL_ES2) META_PS(true, FEATURE_LEVEL_ES2)
META_PERMUTATION_1(QUALITY=0) META_PERMUTATION_1(QUALITY=0)
@@ -248,16 +230,10 @@ float4 PS(Quad_VS2PS input) : SV_Target0
//history = clamp(history, cMin, cMax); //history = clamp(history, cMin, cMax);
// Calculate history weight from unbiased luminance diff // Calculate history weight from unbiased luminance diff
// [Reference: "TSSAA (Temporal Super-Sampling AA)" by Timothy Lottes (2011)] float historyBlend = TemporalHistoryWeight(current, history, MotionBlending);
float currentLum = Luminance(current.rgb);
float historyLum = Luminance(history.rgb);
float unbiasedDiff = abs(currentLum - historyLum) / max(currentLum, max(historyLum, 0.2f));
float unbiasedWeight = 1.0 - unbiasedDiff;
float unbiasedWeightSqr = unbiasedWeight * unbiasedWeight;
#if DEBUG_LUMINANCE_DIFF #if DEBUG_LUMINANCE_DIFF
return unbiasedWeightSqr.xxxx; return historyBlend.xxxx;
#endif #endif
float historyBlend = lerp(MotionBlending, min(MotionBlending + 0.2f, 0.97f), unbiasedWeightSqr);
// Higher history blend when there is no motion // Higher history blend when there is no motion
float motion = saturate(length(velocityDepth.xy) * 1000.0f); float motion = saturate(length(velocityDepth.xy) * 1000.0f);
+36
View File
@@ -5,6 +5,25 @@
#include "./Flax/Common.hlsl" #include "./Flax/Common.hlsl"
#define TAA_EPSILON 0.000001f
// Calculates history weight from unbiased luminance diff
// [Timothy Lottes, 2011, "TSSAA (Temporal Super-Sampling AA)"]
float TemporalHistoryWeight(float4 current, float4 history, float motionBlending = 0.85f)
{
float currentLum = Luminance(current.rgb);
float historyLum = Luminance(history.rgb);
float unbiasedDiff = abs(currentLum - historyLum) / max(currentLum, max(historyLum, 0.2f));
float unbiasedWeight = 1.0 - unbiasedDiff;
float unbiasedWeightSqr = unbiasedWeight * unbiasedWeight;
float historyBlend = lerp(motionBlending, min(motionBlending + 0.2f, 0.97f), unbiasedWeightSqr);
#if defined(DEBUG_LUMINANCE_DIFF) && DEBUG_LUMINANCE_DIFF
return unbiasedWeightSqr;
#endif
return historyBlend;
}
// Clamps sample color to neighbourhood pixels bounds
// [Pedersen, 2016, "Temporal Reprojection Anti-Aliasing in INSIDE"] // [Pedersen, 2016, "Temporal Reprojection Anti-Aliasing in INSIDE"]
float4 ClipToAABB(float4 color, float4 minimum, float4 maximum) float4 ClipToAABB(float4 color, float4 minimum, float4 maximum)
{ {
@@ -16,4 +35,21 @@ float4 ClipToAABB(float4 color, float4 minimum, float4 maximum)
return maxUnit > 1.0 ? center + (shift / maxUnit) : color; return maxUnit > 1.0 ? center + (shift / maxUnit) : color;
} }
float4 ClipAAB(float3 aabbMin, float3 aabbMax, float4 p, float4 q)
{
// only clips towards aabb center
float3 pClip = 0.5 * (aabbMax + aabbMin);
float3 eClip = 0.5 * (aabbMax - aabbMin) + TAA_EPSILON;
float4 vClip = q - float4(pClip, p.w);
float3 vUnit = vClip.xyz / eClip;
float3 aUnit = abs(vUnit);
float maUnit = max(aUnit.x, max(aUnit.y, aUnit.z));
if (maUnit > 1.0)
return float4(pClip, p.w) + vClip / maUnit;
else
return q; // point inside aabb
}
#endif #endif