@@ -14,17 +14,13 @@ Shader "Hidden/PostProcessing/TemporalAntialiasing"
1414
1515 TEXTURE2D_SAMPLER2D (_MainTex, _MainTexSampler);
1616 float4 _MainTex_TexelSize;
17- float4 _MainTex_ST;
1817
1918 TEXTURE2D_SAMPLER2D (_HistoryTex, sampler_HistoryTex);
20- float4 _HistoryTex_ST;
2119
2220 TEXTURE2D_SAMPLER2D (_CameraDepthTexture, sampler_CameraDepthTexture);
2321 float4 _CameraDepthTexture_TexelSize;
24- float4 _CameraDepthTexture_ST;
2522
2623 TEXTURE2D_SAMPLER2D (_CameraMotionVectorsTexture, sampler_CameraMotionVectorsTexture);
27- float4 _CameraMotionVectorsTexture_ST;
2824
2925 float2 _Jitter;
3026 float4 _FinalBlendParameters; // x: static, y: dynamic, z: motion amplification
@@ -33,14 +29,12 @@ Shader "Hidden/PostProcessing/TemporalAntialiasing"
3329 float2 GetClosestFragment (float2 uv)
3430 {
3531 const float2 k = _CameraDepthTexture_TexelSize.xy;
36- // TODO: All the neighborhood sample addresses need to run through UnityStereoClamp
37- // probably do something like UnityStereoClamp(bleh, unity_StereoScaleOffset[unity_StereoEyeIndex])
38- // or UnityStereoClamp(bleh, _CameraDepthTexture_ST);
32+
3933 const float4 neighborhood = float4 (
40- SAMPLE_DEPTH_TEXTURE (_CameraDepthTexture, sampler_CameraDepthTexture, uv - k),
41- SAMPLE_DEPTH_TEXTURE (_CameraDepthTexture, sampler_CameraDepthTexture, uv + float2 (k.x, -k.y)),
42- SAMPLE_DEPTH_TEXTURE (_CameraDepthTexture, sampler_CameraDepthTexture, uv + float2 (-k.x, k.y)),
43- SAMPLE_DEPTH_TEXTURE (_CameraDepthTexture, sampler_CameraDepthTexture, uv + k)
34+ SAMPLE_DEPTH_TEXTURE (_CameraDepthTexture, sampler_CameraDepthTexture, UnityStereoClamp ( uv - k) ),
35+ SAMPLE_DEPTH_TEXTURE (_CameraDepthTexture, sampler_CameraDepthTexture, UnityStereoClamp ( uv + float2 (k.x, -k.y) )),
36+ SAMPLE_DEPTH_TEXTURE (_CameraDepthTexture, sampler_CameraDepthTexture, UnityStereoClamp ( uv + float2 (-k.x, k.y) )),
37+ SAMPLE_DEPTH_TEXTURE (_CameraDepthTexture, sampler_CameraDepthTexture, UnityStereoClamp ( uv + k) )
4438 );
4539
4640 #if defined (UNITY_REVERSED_Z )
@@ -55,7 +49,6 @@ Shader "Hidden/PostProcessing/TemporalAntialiasing"
5549 result = lerp (result, float3 (-1.0 , 1.0 , neighborhood.z), COMPARE_DEPTH (neighborhood.z, result.z));
5650 result = lerp (result, float3 ( 1.0 , 1.0 , neighborhood.w), COMPARE_DEPTH (neighborhood.w, result.z));
5751
58- // TODO: do I need to clamp this? Should be lerping between clamped coords...
5952 return (uv + result.xy * k);
6053 }
6154
@@ -83,13 +76,12 @@ Shader "Hidden/PostProcessing/TemporalAntialiasing"
8376 OutputSolver Solve (float2 motion, float2 texcoord)
8477 {
8578 const float2 k = _MainTex_TexelSize.xy;
86- float2 uv = texcoord - _Jitter;
79+ float2 uv = UnityStereoClamp ( texcoord - _Jitter) ;
8780
8881 float4 color = SAMPLE_TEXTURE2D (_MainTex, _MainTexSampler, uv);
8982
90- // TODO: clamp the coords here
91- float4 topLeft = SAMPLE_TEXTURE2D (_MainTex, _MainTexSampler, uv - k * 0.5 );
92- float4 bottomRight = SAMPLE_TEXTURE2D (_MainTex, _MainTexSampler, uv + k * 0.5 );
83+ float4 topLeft = SAMPLE_TEXTURE2D (_MainTex, _MainTexSampler, UnityStereoClamp (uv - k * 0.5 ));
84+ float4 bottomRight = SAMPLE_TEXTURE2D (_MainTex, _MainTexSampler, UnityStereoClamp (uv + k * 0.5 ));
9385
9486 float4 corners = 4.0 * (topLeft + bottomRight) - 2.0 * color;
9587
@@ -105,8 +97,7 @@ Shader "Hidden/PostProcessing/TemporalAntialiasing"
10597
10698 color = FastTonemap (color);
10799
108- // TODO: clamp the coords here
109- float4 history = SAMPLE_TEXTURE2D (_HistoryTex, sampler_HistoryTex, texcoord - motion);
100+ float4 history = SAMPLE_TEXTURE2D (_HistoryTex, sampler_HistoryTex, UnityStereoClamp (texcoord - motion));
110101
111102 float motionLength = length (motion);
112103 float2 luma = float2 (Luminance (average), Luminance (color));
@@ -139,15 +130,8 @@ Shader "Hidden/PostProcessing/TemporalAntialiasing"
139130 {
140131 float2 adjustedTexCoord = UnityStereoTransformScreenSpaceTex (i.texcoord);
141132
142- // TODO: either use TRANSFORM_TEX or UnityStereoTransformScreenSpaceTex on i.texcoord
143- //float2 closest = GetClosestFragment(i.texcoord);
144133 float2 closest = GetClosestFragment (adjustedTexCoord);
145-
146- // TODO: since closest is based off the transformed tex coord, we should be ok
147134 float2 motion = SAMPLE_TEXTURE2D (_CameraMotionVectorsTexture, sampler_CameraMotionVectorsTexture, closest).xy;
148-
149- // TODO: again, either use TRANSFORM_TEX or UnityStereoTransformScreenSpaceTex on i.texcoord
150- //return Solve(motion, i.texcoord);
151135 return Solve (motion, adjustedTexCoord);
152136 }
153137
@@ -156,12 +140,6 @@ Shader "Hidden/PostProcessing/TemporalAntialiasing"
156140 float2 adjustedTexCoord = UnityStereoTransformScreenSpaceTex (i.texcoord);
157141
158142 // Don't dilate in ortho !
159- // TODO: either use TRANSFORM_TEX or UnityStereoTransformScreenSpaceTex on i.texcoord
160- //float2 motion = SAMPLE_TEXTURE2D(_CameraMotionVectorsTexture, sampler_CameraMotionVectorsTexture, i.texcoord).xy;
161-
162- // TODO: again, either use TRANSFORM_TEX or UnityStereoTransformScreenSpaceTex on i.texcoord
163- //return Solve(motion, i.texcoord);
164-
165143 float2 motion = SAMPLE_TEXTURE2D (_CameraMotionVectorsTexture, sampler_CameraMotionVectorsTexture, adjustedTexCoord).xy;
166144 return Solve (motion, adjustedTexCoord);
167145 }
0 commit comments