@@ -106,6 +106,7 @@ Shader "Hidden/Post FX/Uber Shader"
106106 half3 color = (0.0 ).xxx;
107107 #if DEPTH_OF_FIELD && CHROMATIC_ABERRATION
108108 half4 dof = (0.0 ).xxxx;
109+ half ffa = 0.0 ; // far field alpha
109110 #endif
110111
111112 //
@@ -135,6 +136,7 @@ Shader "Hidden/Post FX/Uber Shader"
135136 dofPos.y = 1.0 - dofPos.y;
136137 }
137138 half4 dofSum = (0.0 ).xxxx;
139+ half ffaSum = 0.0 ;
138140 #endif
139141
140142 for (int i = 0 ; i < samples; i++)
@@ -148,15 +150,20 @@ Shader "Hidden/Post FX/Uber Shader"
148150 pos += delta;
149151
150152 #if DEPTH_OF_FIELD
151- half4 sdof = tex2Dlod (_DepthOfFieldTex, float4 (UnityStereoScreenSpaceUVAdjust (dofPos, _MainTex_ST), 0 , 0 )).rgba;
153+ float4 uvDof = float4 (UnityStereoScreenSpaceUVAdjust (dofPos, _MainTex_ST), 0 , 0 );
154+ half4 sdof = tex2Dlod (_DepthOfFieldTex, uvDof).rgba;
155+ half scoc = tex2Dlod (_DepthOfFieldCoCTex, uvDof).r;
156+ scoc = (scoc - 0.5 ) * 2 * _DepthOfFieldParams.z;
152157 dofSum += sdof * half4 (filter, 1 );
158+ ffaSum += smoothstep (_MainTex_TexelSize.y * 2 , _MainTex_TexelSize.y * 4 , scoc);
153159 dofPos += dofDelta;
154160 #endif
155161 }
156162
157163 color = sum / filterSum;
158164 #if DEPTH_OF_FIELD
159165 dof = dofSum / half4 (filterSum, samples);
166+ ffa = ffaSum / samples;
160167 #endif
161168 }
162169 #else
@@ -204,13 +211,13 @@ Shader "Hidden/Post FX/Uber Shader"
204211 {
205212 #if !CHROMATIC_ABERRATION
206213 half4 dof = tex2D (_DepthOfFieldTex, i.uvFlippedSPR);
207- #endif
208- // Far field alpha.
209214 half coc = tex2D (_DepthOfFieldCoCTex, i.uvFlippedSPR);
210215 coc = (coc - 0.5 ) * 2 * _DepthOfFieldParams.z;
211- float alpha = smoothstep (_MainTex_TexelSize.y * 2 , _MainTex_TexelSize.y * 4 , coc);
212- // lerp(lerp(color, dof, alpha), dof, dof.a)
213- color = lerp (color, dof.rgb * autoExposure, alpha + dof.a - alpha * dof.a);
216+ // Convert CoC to far field alpha value.
217+ float ffa = smoothstep (_MainTex_TexelSize.y * 2 , _MainTex_TexelSize.y * 4 , coc);
218+ #endif
219+ // lerp(lerp(color, dof, ffa), dof, dof.a)
220+ color = lerp (color, dof.rgb * autoExposure, ffa + dof.a - ffa * dof.a);
214221 }
215222 #endif
216223
0 commit comments