|
12 | 12 |
|
13 | 13 | #define TAA_USE_GATHER4_FOR_DEPTH_SAMPLE (SHADER_TARGET >= 41)
|
14 | 14 |
|
15 |
| -#define TAA_USE_STABLE_BUT_GHOSTY_VARIANT 0 |
| 15 | +//#define TAA_USE_STABLE_BUT_GHOSTY_VARIANT 0 |
16 | 16 |
|
17 | 17 | #if !defined(TAA_DILATE_MOTION_VECTOR_SAMPLE)
|
18 | 18 | #define TAA_DILATE_MOTION_VECTOR_SAMPLE 1
|
@@ -54,6 +54,10 @@ float2 _Jitter;
|
54 | 54 | float4 _SharpenParameters;
|
55 | 55 | float4 _FinalBlendParameters;
|
56 | 56 |
|
| 57 | +//Debug |
| 58 | +float _StableVariant; |
| 59 | +//End Debug |
| 60 | + |
57 | 61 | VaryingsSolver VertSolver(AttributesDefault input)
|
58 | 62 | {
|
59 | 63 | VaryingsSolver output;
|
@@ -128,56 +132,63 @@ float4 ClipToAABB(float4 color, float p, float3 minimum, float3 maximum)
|
128 | 132 | OutputSolver FragSolver(VaryingsSolver input)
|
129 | 133 | {
|
130 | 134 | #if TAA_DILATE_MOTION_VECTOR_SAMPLE
|
131 |
| - float2 motion = tex2D(_CameraMotionVectorsTexture, GetClosestFragment(input.uv.zw)).xy; |
| 135 | + float2 motion = tex2D(_CameraMotionVectorsTexture, GetClosestFragment(input.uv.zw)).xy; |
132 | 136 | #else
|
133 |
| - // Don't dilate in ortho ! |
134 |
| - float2 motion = tex2D(_CameraMotionVectorsTexture, input.uv.zw).xy; |
| 137 | + // Don't dilate in ortho ! |
| 138 | + float2 motion = tex2D(_CameraMotionVectorsTexture, input.uv.zw).xy; |
135 | 139 | #endif
|
136 | 140 |
|
137 |
| - const float2 k = _MainTex_TexelSize.xy; |
138 |
| - float2 uv = input.uv.xy; |
| 141 | + const float2 k = _MainTex_TexelSize.xy; |
| 142 | + float2 uv = input.uv.xy; |
139 | 143 |
|
140 | 144 | #if UNITY_UV_STARTS_AT_TOP
|
141 |
| - uv -= _MainTex_TexelSize.y < 0 ? _Jitter * float2(1.0, -1.0) : _Jitter; |
| 145 | + uv -= _MainTex_TexelSize.y < 0 ? _Jitter * float2(1.0, -1.0) : _Jitter; |
142 | 146 | #else
|
143 |
| - uv -= _Jitter; |
| 147 | + uv -= _Jitter; |
144 | 148 | #endif
|
145 | 149 |
|
146 |
| - float4 color = tex2D(_MainTex, uv); |
| 150 | + float4 color = tex2D(_MainTex, uv); |
147 | 151 |
|
148 |
| - float4 topLeft = tex2D(_MainTex, uv - k * 0.5); |
149 |
| - float4 bottomRight = tex2D(_MainTex, uv + k * 0.5); |
| 152 | + float4 topLeft = tex2D(_MainTex, uv - k * 0.5); |
| 153 | + float4 bottomRight = tex2D(_MainTex, uv + k * 0.5); |
150 | 154 |
|
151 |
| - float4 corners = 4.0 * (topLeft + bottomRight) - 2.0 * color; |
| 155 | + float4 corners = 4.0 * (topLeft + bottomRight) - 2.0 * color; |
152 | 156 |
|
153 |
| - // Sharpen output |
154 |
| - color += (color - (corners * 0.166667)) * 2.718282 * _SharpenParameters.x; |
155 |
| - color = max(0.0, color); |
| 157 | + // Sharpen output |
| 158 | + color += (color - (corners * 0.166667)) * 2.718282 * _SharpenParameters.x; |
| 159 | + color = max(0.0, color); |
156 | 160 |
|
157 |
| - // Tonemap color and history samples |
158 |
| - float4 average = FastToneMap((corners + color) * 0.142857); |
| 161 | + // Tonemap color and history samples |
| 162 | + float4 average = FastToneMap((corners + color) * 0.142857); |
159 | 163 |
|
160 |
| - topLeft = FastToneMap(topLeft); |
161 |
| - bottomRight = FastToneMap(bottomRight); |
| 164 | + topLeft = FastToneMap(topLeft); |
| 165 | + bottomRight = FastToneMap(bottomRight); |
162 | 166 |
|
163 |
| - color = FastToneMap(color); |
| 167 | + color = FastToneMap(color); |
164 | 168 |
|
165 |
| - float4 history = tex2D(_HistoryTex, input.uv.zw - motion); |
| 169 | + float4 history = tex2D(_HistoryTex, input.uv.zw - motion); |
166 | 170 |
|
167 |
| -// Only use this variant for arch viz or scenes that don't have any animated objects (camera animation is fine) |
168 |
| -#if TAA_USE_STABLE_BUT_GHOSTY_VARIANT |
169 |
| - float4 luma = float4(Luminance(topLeft.rgb), Luminance(bottomRight.rgb), Luminance(average.rgb), Luminance(color.rgb)); |
170 |
| - float nudge = lerp(6.28318530718, 0.5, saturate(2.0 * history.a)) * max(abs(luma.z - luma.w), abs(luma.x - luma.y)); |
| 171 | + // Only use this variant for arch viz or scenes that don't have any animated objects (camera animation is fine) |
171 | 172 |
|
172 |
| - float4 minimum = lerp(bottomRight, topLeft, step(luma.x, luma.y)) - nudge; |
173 |
| - float4 maximum = lerp(topLeft, bottomRight, step(luma.x, luma.y)) + nudge; |
174 |
| -#else |
175 |
| - float2 luma = float2(Luminance(average.rgb), Luminance(color.rgb)); |
176 |
| - float nudge = 4.0 * abs(luma.x - luma.y); |
| 173 | + float4 minimum = float4(0, 0, 0, 0); |
| 174 | + float4 maximum = float4(0, 0, 0, 0); |
177 | 175 |
|
178 |
| - float4 minimum = min(bottomRight, topLeft) - nudge; |
179 |
| - float4 maximum = max(topLeft, bottomRight) + nudge; |
180 |
| -#endif |
| 176 | + if (_StableVariant == 1) |
| 177 | + { |
| 178 | + float4 luma = float4(Luminance(topLeft.rgb), Luminance(bottomRight.rgb), Luminance(average.rgb), Luminance(color.rgb)); |
| 179 | + float nudge = lerp(6.28318530718, 0.5, saturate(2.0 * history.a)) * max(abs(luma.z - luma.w), abs(luma.x - luma.y)); |
| 180 | + |
| 181 | + minimum = lerp(bottomRight, topLeft, step(luma.x, luma.y)) - nudge; |
| 182 | + maximum = lerp(topLeft, bottomRight, step(luma.x, luma.y)) + nudge; |
| 183 | + } |
| 184 | + else |
| 185 | + { |
| 186 | + float2 luma = float2(Luminance(average.rgb), Luminance(color.rgb)); |
| 187 | + float nudge = 4.0 * abs(luma.x - luma.y); |
| 188 | + |
| 189 | + minimum = min(bottomRight, topLeft) - nudge; |
| 190 | + maximum = max(topLeft, bottomRight) + nudge; |
| 191 | + } |
181 | 192 |
|
182 | 193 | history = FastToneMap(history);
|
183 | 194 |
|
|
0 commit comments