Skip to content
This repository was archived by the owner on Nov 30, 2020. It is now read-only.

Commit 79350d3

Browse files
committed
Improved TAA (NaN fix, physical light units fix, sharpness fix, performance bump)
1 parent ef53492 commit 79350d3

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

PostProcessing/Shaders/Builtins/TemporalAntialiasing.shader

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,10 @@ Shader "Hidden/PostProcessing/TemporalAntialiasing"
8787

8888
// Sharpen output
8989
color += (color - (corners * 0.166667)) * 2.718282 * _Sharpness;
90-
color = max(0.0, color);
90+
color = clamp(color, 0.0, HALF_MAX_MINUS1);
9191

9292
// Tonemap color and history samples
93-
float4 average = FastTonemap((corners + color) * 0.142857);
94-
95-
topLeft = FastTonemap(topLeft);
96-
bottomRight = FastTonemap(bottomRight);
97-
98-
color = FastTonemap(color);
93+
float4 average = (corners + color) * 0.142857;
9994

10095
float4 history = SAMPLE_TEXTURE2D(_HistoryTex, sampler_HistoryTex, UnityStereoClamp(texcoord - motion));
10196

@@ -107,8 +102,6 @@ Shader "Hidden/PostProcessing/TemporalAntialiasing"
107102
float4 minimum = min(bottomRight, topLeft) - nudge;
108103
float4 maximum = max(topLeft, bottomRight) + nudge;
109104

110-
history = FastTonemap(history);
111-
112105
// Clip history samples
113106
history = ClipToAABB(history, minimum.xyz, maximum.xyz);
114107

@@ -118,7 +111,8 @@ Shader "Hidden/PostProcessing/TemporalAntialiasing"
118111
_FinalBlendParameters.y, _FinalBlendParameters.x
119112
);
120113

121-
color = FastTonemapInvert(lerp(color, history, weight));
114+
color = lerp(color, history, weight);
115+
color = clamp(color, 0.0, HALF_MAX_MINUS1);
122116

123117
OutputSolver output;
124118
output.destination = color;

PostProcessing/Shaders/StdLib.hlsl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
// -----------------------------------------------------------------------------
3535
// Constants
3636

37-
#define HALF_MAX 65504.0
37+
#define HALF_MAX 65504.0 // (2 - 2^-10) * 2^15
38+
#define HALF_MAX_MINUS1 65472.0 // (2 - 2^-9) * 2^15
3839
#define EPSILON 1.0e-4
3940
#define PI 3.14159265359
4041
#define TWO_PI 6.28318530718

0 commit comments

Comments
 (0)