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

Commit 976b23b

Browse files
committed
Added focus plane debug view
1 parent 8925f06 commit 976b23b

3 files changed

Lines changed: 40 additions & 5 deletions

File tree

PostProcessing/Resources/Shaders/Uber.shader

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Shader "Hidden/Post FX/Uber Shader"
4242
// Depth of field
4343
sampler2D _DepthOfFieldTex;
4444
float4 _DepthOfFieldTex_TexelSize;
45+
float _MaxCoC;
4546

4647
// Bloom
4748
sampler2D _BloomTex;
@@ -185,6 +186,28 @@ Shader "Hidden/Post FX/Uber Shader"
185186
// Composite
186187
color = color * acc.a + acc.rgb * autoExposure;
187188
}
189+
#elif DEPTH_OF_FIELD_COC_VIEW
190+
{
191+
// CoC radius
192+
half4 src = tex2D(_DepthOfFieldTex, uv);
193+
half coc = src.a / _MaxCoC;
194+
195+
// Visualize CoC (blue -> red -> green)
196+
half3 rgb = lerp(half3(1.0, 0.0, 0.0), half3(0.8, 0.8, 1.0), max(0.0, -coc));
197+
rgb = lerp(rgb, half3(0.8, 1.0, 0.8), max(0.0, coc));
198+
199+
// Black and white image overlay
200+
rgb *= dot(src.rgb, 0.5 / 3.0) + 0.5;
201+
202+
// Gamma correction
203+
#if !UNITY_COLORSPACE_GAMMA
204+
{
205+
rgb = GammaToLinearSpace(rgb);
206+
}
207+
#endif
208+
209+
color = rgb;
210+
}
188211
#endif
189212

190213
// HDR Bloom

PostProcessing/Runtime/Components/DepthOfFieldComponent.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace UnityEngine.PostProcessing
44
{
5+
using DebugMode = BuiltinDebugViewsModel.Mode;
6+
57
public sealed class DepthOfFieldComponent : PostProcessingComponentRenderTexture<DepthOfFieldModel>
68
{
79
static class Uniforms
@@ -124,13 +126,23 @@ public void Prepare(RenderTexture source, Material uberMaterial, bool antialiasC
124126
// Pass #3 - Bokeh simulation
125127
Graphics.Blit(pass, rt2, material, 1 + (int)settings.kernelSize);
126128

127-
context.renderTextureFactory.Release(rt1);
128-
129129
if (antialiasCoC)
130130
context.renderTextureFactory.Release(pass);
131131

132-
uberMaterial.SetTexture(Uniforms._DepthOfFieldTex, rt2);
133-
uberMaterial.EnableKeyword("DEPTH_OF_FIELD");
132+
if (context.profile.debugViews.IsModeActive(DebugMode.FocusPlane))
133+
{
134+
uberMaterial.SetTexture(Uniforms._DepthOfFieldTex, rt1);
135+
uberMaterial.SetFloat(Uniforms._MaxCoC, maxCoC);
136+
uberMaterial.EnableKeyword("DEPTH_OF_FIELD_COC_VIEW");
137+
context.Interrupt();
138+
}
139+
else
140+
{
141+
uberMaterial.SetTexture(Uniforms._DepthOfFieldTex, rt2);
142+
uberMaterial.EnableKeyword("DEPTH_OF_FIELD");
143+
}
144+
145+
context.renderTextureFactory.Release(rt1);
134146
}
135147

136148
public override void OnDisable()

PostProcessing/Runtime/Models/BuiltinDebugViewsModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public enum Mode
7373

7474
AmbientOcclusion,
7575
EyeAdaptation,
76-
FocusPlane, // TODO: Implement focus plane debugging
76+
FocusPlane,
7777
PreGradingLog,
7878
LogLut,
7979
UserLut

0 commit comments

Comments
 (0)