@@ -5,6 +5,7 @@ Shader "Hidden/PostProcessing/Uber"
55 #pragma target 3.0
66
77 #pragma multi_compile __ UNITY_COLORSPACE_GAMMA
8+ #pragma multi_compile __ DISTORT
89 #pragma multi_compile __ CHROMATIC_ABERRATION CHROMATIC_ABERRATION_LOW
910 #pragma multi_compile __ BLOOM
1011 #pragma multi_compile __ COLOR_GRADING_LDR_2D COLOR_GRADING_HDR_2D COLOR_GRADING_HDR_3D
@@ -15,6 +16,7 @@ Shader "Hidden/PostProcessing/Uber"
1516 #include "../StdLib.hlsl"
1617 #include "../Colors.hlsl"
1718 #include "../Sampling.hlsl"
19+ #include "Distortion.hlsl"
1820 #include "Dithering.hlsl"
1921
2022 #define MAX_CHROMATIC_SAMPLES 16
@@ -71,6 +73,12 @@ Shader "Hidden/PostProcessing/Uber"
7173 half4 FragUber (VaryingsDefault i) : SV_Target
7274 {
7375 float2 uv = i.texcoord;
76+
77+ //>>> Automatically skipped by the shader optimizer when not used
78+ float2 uvDistorted = Distort (i.texcoord);
79+ float2 uvStereoDistorted = Distort (i.texcoordStereo);
80+ //<<<
81+
7482 half autoExposure = SAMPLE_TEXTURE2D (_AutoExposureTex, sampler_AutoExposureTex, uv).r;
7583 half4 color = (0.0 ).xxxx;
7684
@@ -90,7 +98,7 @@ Shader "Hidden/PostProcessing/Uber"
9098 for (int i = 0 ; i < samples; i++)
9199 {
92100 half t = (i + 0.5 ) / samples;
93- half4 s = SAMPLE_TEXTURE2D_LOD (_MainTex, sampler_MainTex, UnityStereoTransformScreenSpaceTex (pos), 0 );
101+ half4 s = SAMPLE_TEXTURE2D_LOD (_MainTex, sampler_MainTex, UnityStereoTransformScreenSpaceTex (Distort ( pos) ), 0 );
94102 half4 filter = half4 (SAMPLE_TEXTURE2D_LOD (_ChromaticAberration_SpectralLut, sampler_ChromaticAberration_SpectralLut, float2 (t, 0.0 ), 0 ).rgb, 1.0 );
95103
96104 sum += s * filter;
@@ -110,17 +118,17 @@ Shader "Hidden/PostProcessing/Uber"
110118 half4 filterB = half4 (SAMPLE_TEXTURE2D_LOD (_ChromaticAberration_SpectralLut, sampler_ChromaticAberration_SpectralLut, float2 (1.5 / 3 , 0.0 ), 0 ).rgb, 1.0 );
111119 half4 filterC = half4 (SAMPLE_TEXTURE2D_LOD (_ChromaticAberration_SpectralLut, sampler_ChromaticAberration_SpectralLut, float2 (2.5 / 3 , 0.0 ), 0 ).rgb, 1.0 );
112120
113- half4 texelA = SAMPLE_TEXTURE2D_LOD (_MainTex, sampler_MainTex, UnityStereoTransformScreenSpaceTex (uv ), 0 );
114- half4 texelB = SAMPLE_TEXTURE2D_LOD (_MainTex, sampler_MainTex, UnityStereoTransformScreenSpaceTex (delta + uv), 0 );
115- half4 texelC = SAMPLE_TEXTURE2D_LOD (_MainTex, sampler_MainTex, UnityStereoTransformScreenSpaceTex (delta * 2.0 + uv), 0 );
121+ half4 texelA = SAMPLE_TEXTURE2D_LOD (_MainTex, sampler_MainTex, UnityStereoTransformScreenSpaceTex (Distort (uv) ), 0 );
122+ half4 texelB = SAMPLE_TEXTURE2D_LOD (_MainTex, sampler_MainTex, UnityStereoTransformScreenSpaceTex (Distort ( delta + uv) ), 0 );
123+ half4 texelC = SAMPLE_TEXTURE2D_LOD (_MainTex, sampler_MainTex, UnityStereoTransformScreenSpaceTex (Distort ( delta * 2.0 + uv) ), 0 );
116124
117125 half4 sum = texelA * filterA + texelB * filterB + texelC * filterC;
118126 half4 filterSum = filterA + filterB + filterC;
119127 color = sum / filterSum;
120128 }
121129 #else
122130 {
123- color = SAMPLE_TEXTURE2D (_MainTex, sampler_MainTex, i.texcoordStereo );
131+ color = SAMPLE_TEXTURE2D (_MainTex, sampler_MainTex, uvStereoDistorted );
124132 }
125133 #endif
126134
@@ -135,8 +143,13 @@ Shader "Hidden/PostProcessing/Uber"
135143
136144 #if BLOOM
137145 {
138- half4 bloom = UpsampleTent (TEXTURE2D_PARAM (_BloomTex, sampler_BloomTex), i.texcoord, _BloomTex_TexelSize.xy, _Bloom_Settings.x);
139- half4 dirt = half4 (SAMPLE_TEXTURE2D (_Bloom_DirtTex, sampler_Bloom_DirtTex, i.texcoord * _Bloom_DirtTileOffset.xy + _Bloom_DirtTileOffset.zw).rgb, 0.0 );
146+ half4 bloom = UpsampleTent (TEXTURE2D_PARAM (_BloomTex, sampler_BloomTex), uvDistorted, _BloomTex_TexelSize.xy, _Bloom_Settings.x);
147+
148+ // UVs should be Distort(uv * _Bloom_DirtTileOffset.xy + _Bloom_DirtTileOffset.zw)
149+ // but considering we use a cover-style scale on the dirt texture the difference
150+ // isn't massive so we chose to save a few ALUs here instead in case lens distortion
151+ // is active
152+ half4 dirt = half4 (SAMPLE_TEXTURE2D (_Bloom_DirtTex, sampler_Bloom_DirtTex, uvDistorted * _Bloom_DirtTileOffset.xy + _Bloom_DirtTileOffset.zw).rgb, 0.0 );
140153
141154 // Additive bloom (artist friendly)
142155 bloom *= _Bloom_Settings.y;
@@ -151,7 +164,7 @@ Shader "Hidden/PostProcessing/Uber"
151164 UNITY_BRANCH
152165 if (_Vignette_Mode < 0.5 )
153166 {
154- half2 d = abs (uv - _Vignette_Center) * _Vignette_Settings.x;
167+ half2 d = abs (uvDistorted - _Vignette_Center) * _Vignette_Settings.x;
155168 d.x *= lerp (1.0 , _ScreenParams .x / _ScreenParams .y, _Vignette_Settings.w);
156169 d = pow (saturate (d), _Vignette_Settings.z); // Roundness
157170 half vfactor = pow (saturate (1.0 - dot (d, d)), _Vignette_Settings.y);
@@ -160,7 +173,7 @@ Shader "Hidden/PostProcessing/Uber"
160173 }
161174 else
162175 {
163- half vfactor = SAMPLE_TEXTURE2D (_Vignette_Mask, sampler_Vignette_Mask, uv ).a;
176+ half vfactor = SAMPLE_TEXTURE2D (_Vignette_Mask, sampler_Vignette_Mask, uvDistorted ).a;
164177
165178 #if !UNITY_COLORSPACE_GAMMA
166179 {
0 commit comments