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

Commit 08caa8e

Browse files
committed
Improved focus plane debug view
1 parent f2e7118 commit 08caa8e

2 files changed

Lines changed: 36 additions & 10 deletions

File tree

PostProcessing/Resources/Shaders/Uber.shader

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ Shader "Hidden/Post FX/Uber Shader"
4040
sampler2D _ChromaticAberration_Spectrum;
4141

4242
// Depth of field
43+
sampler2D_float _CameraDepthTexture;
4344
sampler2D _DepthOfFieldTex;
4445
float4 _DepthOfFieldTex_TexelSize;
45-
float _MaxCoC;
46+
float2 _DepthOfFieldParams; // x: distance, y: f^2 / (N * (S1 - f) * film_width * 2)
4647

4748
// Bloom
4849
sampler2D _BloomTex;
@@ -188,6 +189,29 @@ Shader "Hidden/Post FX/Uber Shader"
188189
}
189190
#elif DEPTH_OF_FIELD_COC_VIEW
190191
{
192+
// Calculate the radiuses of CoC.
193+
half4 src = tex2D(_DepthOfFieldTex, uv);
194+
float depth = LinearEyeDepth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, i.uvFlippedSPR));
195+
float coc = (depth - _DepthOfFieldParams.x) * _DepthOfFieldParams.y / depth;
196+
coc *= 80;
197+
198+
// Visualize CoC (gray -> red -> white)
199+
half3 rgb = lerp(half3(1, 0, 0), half3(0.5, 0.5, 0.5), saturate(-coc));
200+
rgb = lerp(rgb, half3(1, 1, 1), saturate(coc));
201+
202+
// Black and white image overlay
203+
rgb *= AcesLuminance(color) + 0.5;
204+
205+
// Gamma correction
206+
#if !UNITY_COLORSPACE_GAMMA
207+
{
208+
rgb = GammaToLinearSpace(rgb);
209+
}
210+
#endif
211+
212+
color = rgb;
213+
214+
/*
191215
// CoC radius
192216
half4 src = tex2D(_DepthOfFieldTex, uv);
193217
half coc = src.a / _MaxCoC;
@@ -207,6 +231,7 @@ Shader "Hidden/Post FX/Uber Shader"
207231
#endif
208232
209233
color = rgb;
234+
*/
210235
}
211236
#endif
212237

PostProcessing/Runtime/Components/DepthOfFieldComponent.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ public sealed class DepthOfFieldComponent : PostProcessingComponentRenderTexture
88
{
99
static class Uniforms
1010
{
11-
internal static readonly int _DepthOfFieldTex = Shader.PropertyToID("_DepthOfFieldTex");
12-
internal static readonly int _Distance = Shader.PropertyToID("_Distance");
13-
internal static readonly int _LensCoeff = Shader.PropertyToID("_LensCoeff");
14-
internal static readonly int _MaxCoC = Shader.PropertyToID("_MaxCoC");
15-
internal static readonly int _RcpMaxCoC = Shader.PropertyToID("_RcpMaxCoC");
16-
internal static readonly int _RcpAspect = Shader.PropertyToID("_RcpAspect");
17-
internal static readonly int _MainTex = Shader.PropertyToID("_MainTex");
18-
internal static readonly int _HistoryCoC = Shader.PropertyToID("_HistoryCoC");
11+
internal static readonly int _DepthOfFieldTex = Shader.PropertyToID("_DepthOfFieldTex");
12+
internal static readonly int _Distance = Shader.PropertyToID("_Distance");
13+
internal static readonly int _LensCoeff = Shader.PropertyToID("_LensCoeff");
14+
internal static readonly int _MaxCoC = Shader.PropertyToID("_MaxCoC");
15+
internal static readonly int _RcpMaxCoC = Shader.PropertyToID("_RcpMaxCoC");
16+
internal static readonly int _RcpAspect = Shader.PropertyToID("_RcpAspect");
17+
internal static readonly int _MainTex = Shader.PropertyToID("_MainTex");
18+
internal static readonly int _HistoryCoC = Shader.PropertyToID("_HistoryCoC");
19+
internal static readonly int _DepthOfFieldParams = Shader.PropertyToID("_DepthOfFieldParams");
1920
}
2021

2122
const string k_ShaderString = "Hidden/Post FX/Depth Of Field";
@@ -129,7 +130,7 @@ public void Prepare(RenderTexture source, Material uberMaterial, bool antialiasC
129130
if (context.profile.debugViews.IsModeActive(DebugMode.FocusPlane))
130131
{
131132
uberMaterial.SetTexture(Uniforms._DepthOfFieldTex, rt1);
132-
uberMaterial.SetFloat(Uniforms._MaxCoC, maxCoC);
133+
uberMaterial.SetVector(Uniforms._DepthOfFieldParams, new Vector2(s1, coeff));
133134
uberMaterial.EnableKeyword("DEPTH_OF_FIELD_COC_VIEW");
134135
context.Interrupt();
135136
}

0 commit comments

Comments
 (0)