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

Commit 79af5dc

Browse files
committed
xR fixes & optimizations
1 parent 52d9afe commit 79af5dc

9 files changed

Lines changed: 40 additions & 48 deletions

File tree

PostProcessing/Runtime/PostProcessDebug.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void OnDisable()
3535
#endif
3636

3737
if (m_CurrentCamera != null)
38-
m_CurrentCamera.RemoveCommandBuffer(CameraEvent.AfterEverything, m_CmdAfterEverything);
38+
m_CurrentCamera.RemoveCommandBuffer(CameraEvent.AfterImageEffects, m_CmdAfterEverything);
3939

4040
m_CurrentCamera = null;
4141
m_PreviousPostProcessLayer = null;
@@ -60,7 +60,7 @@ void UpdateStates()
6060
// Remove cmdbuffer from previously set camera
6161
if (m_CurrentCamera != null)
6262
{
63-
m_CurrentCamera.RemoveCommandBuffer(CameraEvent.AfterEverything, m_CmdAfterEverything);
63+
m_CurrentCamera.RemoveCommandBuffer(CameraEvent.AfterImageEffects, m_CmdAfterEverything);
6464
m_CurrentCamera = null;
6565
}
6666

@@ -70,7 +70,7 @@ void UpdateStates()
7070
if (postProcessLayer != null)
7171
{
7272
m_CurrentCamera = postProcessLayer.GetComponent<Camera>();
73-
m_CurrentCamera.AddCommandBuffer(CameraEvent.AfterEverything, m_CmdAfterEverything);
73+
m_CurrentCamera.AddCommandBuffer(CameraEvent.AfterImageEffects, m_CmdAfterEverything);
7474
}
7575
}
7676

PostProcessing/Shaders/Builtins/DeferredFog.shader

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ Shader "Hidden/PostProcessing/DeferredFog"
1313

1414
float4 Frag(VaryingsDefault i) : SV_Target
1515
{
16-
float2 uv = UnityStereoTransformScreenSpaceTex(i.texcoord);
17-
half4 color = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv);
16+
half4 color = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoordStereo);
1817

19-
float depth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, uv);
18+
float depth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, i.texcoordStereo);
2019
depth = Linear01Depth(depth);
2120
float dist = ComputeFogDistance(depth);
2221
half fog = 1.0 - ComputeFog(dist);
@@ -26,10 +25,9 @@ Shader "Hidden/PostProcessing/DeferredFog"
2625

2726
float4 FragExcludeSkybox(VaryingsDefault i) : SV_Target
2827
{
29-
float2 uv = UnityStereoTransformScreenSpaceTex(i.texcoord);
30-
half4 color = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv);
28+
half4 color = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoordStereo);
3129

32-
float depth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, uv);
30+
float depth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, i.texcoordStereo);
3331
depth = Linear01Depth(depth);
3432
float skybox = depth < SKYBOX_THREASHOLD_VALUE;
3533
float dist = ComputeFogDistance(depth);

PostProcessing/Shaders/Builtins/DepthOfField.hlsl

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ half3 _TaaParams; // Jitter.x, Jitter.y, Blending
2727
// CoC calculation
2828
half4 FragCoC(VaryingsDefault i) : SV_Target
2929
{
30-
float depth = LinearEyeDepth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, UnityStereoTransformScreenSpaceTex(i.texcoord)));
30+
float depth = LinearEyeDepth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, i.texcoordStereo));
3131
half coc = (depth - _Distance) * _LensCoeff / max(depth, 1e-5);
3232
return saturate(coc * 0.5 * _RcpMaxCoC + 0.5);
3333
}
@@ -84,18 +84,17 @@ half4 FragPrefilter(VaryingsDefault i) : SV_Target
8484
#if UNITY_GATHER_SUPPORTED
8585

8686
// Sample source colors
87-
i.texcoord = UnityStereoTransformScreenSpaceTex(i.texcoord);
88-
half4 c_r = GATHER_RED_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord);
89-
half4 c_g = GATHER_GREEN_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord);
90-
half4 c_b = GATHER_BLUE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord);
87+
half4 c_r = GATHER_RED_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoordStereo);
88+
half4 c_g = GATHER_GREEN_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoordStereo);
89+
half4 c_b = GATHER_BLUE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoordStereo);
9190

9291
half3 c0 = half3(c_r.x, c_g.x, c_b.x);
9392
half3 c1 = half3(c_r.y, c_g.y, c_b.y);
9493
half3 c2 = half3(c_r.z, c_g.z, c_b.z);
9594
half3 c3 = half3(c_r.w, c_g.w, c_b.w);
9695

9796
// Sample CoCs
98-
half4 cocs = GATHER_TEXTURE2D(_CoCTex, sampler_CoCTex, i.texcoord) * 2.0 - 1.0;
97+
half4 cocs = GATHER_TEXTURE2D(_CoCTex, sampler_CoCTex, i.texcoordStereo) * 2.0 - 1.0;
9998
half coc0 = cocs.x;
10099
half coc1 = cocs.y;
101100
half coc2 = cocs.z;
@@ -151,7 +150,7 @@ half4 FragPrefilter(VaryingsDefault i) : SV_Target
151150
// Bokeh filter with disk-shaped kernels
152151
half4 FragBlur(VaryingsDefault i) : SV_Target
153152
{
154-
half4 samp0 = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, UnityStereoTransformScreenSpaceTex(i.texcoord));
153+
half4 samp0 = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoordStereo);
155154

156155
half4 bgAcc = 0.0; // Background: far field bokeh
157156
half4 fgAcc = 0.0; // Foreground: near field bokeh
@@ -218,15 +217,14 @@ half4 FragPostBlur(VaryingsDefault i) : SV_Target
218217
// Combine with source
219218
half4 FragCombine(VaryingsDefault i) : SV_Target
220219
{
221-
i.texcoord = UnityStereoTransformScreenSpaceTex(i.texcoord);
222-
half4 dof = SAMPLE_TEXTURE2D(_DepthOfFieldTex, sampler_DepthOfFieldTex, i.texcoord);
223-
half coc = SAMPLE_TEXTURE2D(_CoCTex, sampler_CoCTex, i.texcoord).r;
220+
half4 dof = SAMPLE_TEXTURE2D(_DepthOfFieldTex, sampler_DepthOfFieldTex, i.texcoordStereo);
221+
half coc = SAMPLE_TEXTURE2D(_CoCTex, sampler_CoCTex, i.texcoordStereo).r;
224222
coc = (coc - 0.5) * 2.0 * _MaxCoC;
225223

226224
// Convert CoC to far field alpha value.
227225
float ffa = smoothstep(_MainTex_TexelSize.y * 2.0, _MainTex_TexelSize.y * 4.0, coc);
228226

229-
half4 color = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord);
227+
half4 color = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoordStereo);
230228

231229
#if defined(UNITY_COLORSPACE_GAMMA)
232230
color = SRGBToLinear(color);
@@ -247,12 +245,11 @@ half4 FragCombine(VaryingsDefault i) : SV_Target
247245
// Debug overlay
248246
half4 FragDebugOverlay(VaryingsDefault i) : SV_Target
249247
{
250-
i.texcoord = UnityStereoTransformScreenSpaceTex(i.texcoord);
251-
half3 color = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord).rgb;
248+
half3 color = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoordStereo).rgb;
252249

253250
// Calculate the radiuses of CoC.
254-
half4 src = SAMPLE_TEXTURE2D(_DepthOfFieldTex, sampler_DepthOfFieldTex, i.texcoord);
255-
float depth = LinearEyeDepth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, i.texcoord));
251+
half4 src = SAMPLE_TEXTURE2D(_DepthOfFieldTex, sampler_DepthOfFieldTex, i.texcoordStereo);
252+
float depth = LinearEyeDepth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, i.texcoordStereo));
256253
float coc = (depth - _Distance) * _LensCoeff / depth;
257254
coc *= 80;
258255

PostProcessing/Shaders/Builtins/FinalPass.shader

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ Shader "Hidden/PostProcessing/FinalPass"
4040
float4 Frag(VaryingsDefault i) : SV_Target
4141
{
4242
half4 color = 0.0;
43-
float2 uvSPR = UnityStereoTransformScreenSpaceTex(i.texcoord);
4443

4544
// Fast Approximate Anti-aliasing
4645
#if FXAA || FXAA_LOW
@@ -74,13 +73,13 @@ Shader "Hidden/PostProcessing/FinalPass"
7473

7574
#if FXAA_KEEP_ALPHA
7675
{
77-
color.a = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uvSPR).a;
76+
color.a = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoordStereo).a;
7877
}
7978
#endif
8079
}
8180
#else
8281
{
83-
color = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uvSPR);
82+
color = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoordStereo);
8483
}
8584
#endif
8685

PostProcessing/Shaders/Builtins/MultiScaleVO.shader

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ Shader "Hidden/PostProcessing/MultiScaleVO"
113113

114114
float4 Frag(VaryingsDefault i) : SV_Target
115115
{
116-
float2 texcoord = TransformStereoScreenSpaceTex(i.texcoord, 1);
117-
half ao = SAMPLE_TEXTURE2D(_MSVOcclusionTexture, sampler_MSVOcclusionTexture, texcoord).r;
116+
half ao = SAMPLE_TEXTURE2D(_MSVOcclusionTexture, sampler_MSVOcclusionTexture, i.texcoord).r;
118117
return float4(ao.rrr, 1.0);
119118
}
120119

PostProcessing/Shaders/Builtins/ScalableAO.hlsl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ float4 FragAO(VaryingsDefault i) : SV_Target
248248

249249
// Apply fog when enabled (forward-only)
250250
#if (APPLY_FORWARD_FOG)
251-
float d = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, UnityStereoTransformScreenSpaceTex(uv)));
251+
float d = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, i.texcoordStereo));
252252
d = ComputeFogDistance(d);
253253
ao *= ComputeFog(d);
254254
#endif
@@ -269,13 +269,11 @@ float4 FragBlur(VaryingsDefault i) : SV_Target
269269
float2 delta = float2(0.0, _MainTex_TexelSize.y / DOWNSAMPLE * 2.0);
270270
#endif
271271

272-
float2 uvSpr = UnityStereoTransformScreenSpaceTex(i.texcoord);
273-
274272
#if defined(BLUR_HIGH_QUALITY)
275273

276274
// High quality 7-tap Gaussian with adaptive sampling
277275

278-
half4 p0 = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uvSpr);
276+
half4 p0 = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoordStereo);
279277
half4 p1a = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, UnityStereoTransformScreenSpaceTex(i.texcoord - delta));
280278
half4 p1b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, UnityStereoTransformScreenSpaceTex(i.texcoord + delta));
281279
half4 p2a = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, UnityStereoTransformScreenSpaceTex(i.texcoord - delta * 2.0));
@@ -284,7 +282,7 @@ float4 FragBlur(VaryingsDefault i) : SV_Target
284282
half4 p3b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, UnityStereoTransformScreenSpaceTex(i.texcoord + delta * 3.2307692308));
285283

286284
#if defined(BLUR_SAMPLE_CENTER_NORMAL)
287-
half3 n0 = SampleNormal(uvSpr);
285+
half3 n0 = SampleNormal(i.texcoordStereo);
288286
#else
289287
half3 n0 = GetPackedNormal(p0);
290288
#endif
@@ -311,14 +309,14 @@ float4 FragBlur(VaryingsDefault i) : SV_Target
311309
#else
312310

313311
// Fater 5-tap Gaussian with linear sampling
314-
half4 p0 = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uvSpr);
312+
half4 p0 = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoordStereo);
315313
half4 p1a = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, UnityStereoTransformScreenSpaceTex(i.texcoord - delta * 1.3846153846));
316314
half4 p1b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, UnityStereoTransformScreenSpaceTex(i.texcoord + delta * 1.3846153846));
317315
half4 p2a = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, UnityStereoTransformScreenSpaceTex(i.texcoord - delta * 3.2307692308));
318316
half4 p2b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, UnityStereoTransformScreenSpaceTex(i.texcoord + delta * 3.2307692308));
319317

320318
#if defined(BLUR_SAMPLE_CENTER_NORMAL)
321-
half3 n0 = SampleNormal(uvSpr);
319+
half3 n0 = SampleNormal(i.texcoordStereo);
322320
#else
323321
half3 n0 = GetPackedNormal(p0);
324322
#endif

PostProcessing/Shaders/Builtins/Uber.shader

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ Shader "Hidden/PostProcessing/Uber"
7171
half4 FragUber(VaryingsDefault i) : SV_Target
7272
{
7373
float2 uv = i.texcoord;
74-
float2 uvSPR = UnityStereoTransformScreenSpaceTex(i.texcoord);
7574
half autoExposure = SAMPLE_TEXTURE2D(_AutoExposureTex, sampler_AutoExposureTex, uv).r;
7675
half4 color = (0.0).xxxx;
7776

@@ -127,7 +126,7 @@ Shader "Hidden/PostProcessing/Uber"
127126
}
128127
#else
129128
{
130-
color = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uvSPR);
129+
color = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoordStereo);
131130
}
132131
#endif
133132

@@ -142,7 +141,7 @@ Shader "Hidden/PostProcessing/Uber"
142141

143142
#if BLOOM
144143
{
145-
half4 bloom = UpsampleTent(TEXTURE2D_PARAM(_BloomTex, sampler_BloomTex), uvSPR, _BloomTex_TexelSize.xy, _Bloom_Settings.x);
144+
half4 bloom = UpsampleTent(TEXTURE2D_PARAM(_BloomTex, sampler_BloomTex), i.texcoordStereo, _BloomTex_TexelSize.xy, _Bloom_Settings.x);
146145
half4 dirt = half4(SAMPLE_TEXTURE2D(_Bloom_DirtTex, sampler_Bloom_DirtTex, i.texcoord * _Bloom_DirtTileOffset.xy + _Bloom_DirtTileOffset.zw).rgb, 0.0);
147146

148147
// Additive bloom (artist friendly)
@@ -183,7 +182,7 @@ Shader "Hidden/PostProcessing/Uber"
183182

184183
#if GRAIN
185184
{
186-
half3 grain = SAMPLE_TEXTURE2D(_GrainTex, sampler_GrainTex, uvSPR * _Grain_Params2.xy + _Grain_Params2.zw).rgb;
185+
half3 grain = SAMPLE_TEXTURE2D(_GrainTex, sampler_GrainTex, i.texcoordStereo * _Grain_Params2.xy + _Grain_Params2.zw).rgb;
187186

188187
// Noisiness response curve based on scene luminance
189188
float lum = 1.0 - sqrt(Luminance(saturate(color)));

PostProcessing/Shaders/Debug/Overlays.shader

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Shader "Hidden/PostProcessing/Debug/Overlays"
2323

2424
float4 FragDepth(VaryingsDefault i) : SV_Target
2525
{
26-
float d = SAMPLE_DEPTH_TEXTURE_LOD(_CameraDepthTexture, sampler_CameraDepthTexture, UnityStereoTransformScreenSpaceTex(i.texcoord), 0);
26+
float d = SAMPLE_DEPTH_TEXTURE_LOD(_CameraDepthTexture, sampler_CameraDepthTexture, i.texcoordStereo, 0);
2727

2828
//#if !UNITY_COLORSPACE_GAMMA
2929
// d = SRGBToLinear(d);
@@ -37,13 +37,11 @@ Shader "Hidden/PostProcessing/Debug/Overlays"
3737

3838
float4 FragNormals(VaryingsDefault i) : SV_Target
3939
{
40-
float2 uv = UnityStereoTransformScreenSpaceTex(i.texcoord);
41-
4240
#if SOURCE_GBUFFER
43-
float3 norm = SAMPLE_TEXTURE2D(_CameraGBufferTexture2, sampler_CameraGBufferTexture2, uv).xyz * 2.0 - 1.0;
41+
float3 norm = SAMPLE_TEXTURE2D(_CameraGBufferTexture2, sampler_CameraGBufferTexture2, i.texcoordStereo).xyz * 2.0 - 1.0;
4442
float3 n = mul((float3x3)unity_WorldToCamera, norm);
4543
#else
46-
float4 cdn = SAMPLE_TEXTURE2D(_CameraDepthNormalsTexture, sampler_CameraDepthNormalsTexture, uv);
44+
float4 cdn = SAMPLE_TEXTURE2D(_CameraDepthNormalsTexture, sampler_CameraDepthNormalsTexture, i.texcoordStereo);
4745
float3 n = DecodeViewNormalStereo(cdn) * float3(1.0, 1.0, -1.0);
4846
#endif
4947

@@ -99,14 +97,14 @@ Shader "Hidden/PostProcessing/Debug/Overlays"
9997

10098
float2 SampleMotionVectors(float2 coords)
10199
{
102-
float2 mv = SAMPLE_TEXTURE2D(_CameraMotionVectorsTexture, sampler_CameraMotionVectorsTexture, coords).xy;
100+
float2 mv = SAMPLE_TEXTURE2D(_CameraMotionVectorsTexture, sampler_CameraMotionVectorsTexture, UnityStereoTransformScreenSpaceTex(coords)).xy;
103101
mv.y *= -1.0;
104102
return mv;
105103
}
106104

107105
float4 FragMotionVectors(VaryingsDefault i) : SV_Target
108106
{
109-
float3 src = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord).rgb;
107+
float3 src = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoordStereo).rgb;
110108
float2 mv = SampleMotionVectors(i.texcoord);
111109

112110
// Background color intensity - keep this low unless you want to make your eyes bleed
@@ -169,7 +167,7 @@ Shader "Hidden/PostProcessing/Debug/Overlays"
169167

170168
float4 FragNANTracker(VaryingsDefault i) : SV_Target
171169
{
172-
float4 color = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord);
170+
float4 color = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoordStereo);
173171

174172
if (any(isnan(color)) || any(isinf(color)))
175173
{

PostProcessing/Shaders/StdLib.hlsl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ struct VaryingsDefault
235235
{
236236
float4 vertex : SV_POSITION;
237237
float2 texcoord : TEXCOORD0;
238+
float2 texcoordStereo : TEXCOORD1;
238239
};
239240

240241
VaryingsDefault VertDefault(AttributesDefault v)
@@ -247,6 +248,8 @@ VaryingsDefault VertDefault(AttributesDefault v)
247248
o.texcoord = o.texcoord * float2(1.0, -1.0) + float2(0.0, 1.0);
248249
#endif
249250

251+
o.texcoordStereo = TransformStereoScreenSpaceTex(o.texcoord, 1.0);
252+
250253
return o;
251254
}
252255

@@ -255,6 +258,7 @@ VaryingsDefault VertDefaultNoFlip(AttributesDefault v)
255258
VaryingsDefault o;
256259
o.vertex = float4(v.vertex.xy, 0.0, 1.0);
257260
o.texcoord = TransformTriangleVertexToUV(v.vertex.xy);
261+
o.texcoordStereo = TransformStereoScreenSpaceTex(o.texcoord, 1.0);
258262
return o;
259263
}
260264

0 commit comments

Comments
 (0)