Skip to content

Commit f9152cf

Browse files
committed
adding fb fetch to Gbuffer decals and some other depth related fixes for decals
1 parent 159580e commit f9152cf

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

com.unity.render-pipelines.universal/Editor/Decal/DecalPass.template

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ Pass
6363
#ifdef SCENEPICKINGPASS
6464
float4 _SelectionID;
6565
#endif
66-
66+
#if _RENDER_PASS_ENABLED
67+
#define DEPTH_COPY 0
68+
FRAMEBUFFER_INPUT_FLOAT(DEPTH_COPY);
69+
#endif
6770
// Includes
6871
$splice(PreGraphIncludes)
6972

com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPassDecal.hlsl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,20 @@ void Frag(PackedVaryings packedInput,
181181

182182
#if defined(DECAL_PROJECTOR)
183183
#if UNITY_REVERSED_Z
184+
#if _RENDER_PASS_ENABLED
185+
float depth = LOAD_FRAMEBUFFER_INPUT(DEPTH_COPY, input.positionCS.xy);
186+
#else
184187
float depth = LoadSceneDepth(input.positionCS.xy);
188+
#endif
189+
#else
190+
#if _RENDER_PASS_ENABLED
191+
float depth = lerp(UNITY_NEAR_CLIP_VALUE, 1, LOAD_FRAMEBUFFER_INPUT(DEPTH_COPY, input.positionCS.xy));
185192
#else
186193
// Adjust z to match NDC for OpenGL
187194
float depth = lerp(UNITY_NEAR_CLIP_VALUE, 1, LoadSceneDepth(input.positionCS.xy));
188195
#endif
189196
#endif
197+
#endif
190198

191199
#if defined(DECAL_RECONSTRUCT_NORMAL)
192200
#if defined(_DECAL_NORMAL_BLEND_HIGH)

com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalDecalSubTarget.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,7 @@ static class Descriptors
977977
{ CoreKeywordDescriptors.MixedLightingSubtractive },
978978
{ Descriptors.DecalsNormalBlend },
979979
{ CoreKeywordDescriptors.GBufferNormalsOct },
980+
{ CoreKeywordDescriptors.RenderPassEnabled },
980981
{ Descriptors.LodCrossFade, new FieldCondition(Fields.LodCrossFade, true) },
981982
};
982983

@@ -986,6 +987,7 @@ static class Descriptors
986987
{ CoreKeywordDescriptors.ShadowsSoft },
987988
{ Descriptors.DecalsNormalBlend },
988989
{ CoreKeywordDescriptors.GBufferNormalsOct },
990+
{ CoreKeywordDescriptors.RenderPassEnabled },
989991
};
990992
}
991993
#endregion

com.unity.render-pipelines.universal/Runtime/Decal/ScreenSpace/DecalGBufferRenderPass.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ internal class DecalGBufferRenderPass : ScriptableRenderPass
1717
private DecalDrawGBufferSystem m_DrawSystem;
1818
private DecalScreenSpaceSettings m_Settings;
1919
private DeferredLights m_DeferredLights;
20+
private RenderTargetIdentifier[] m_GbufferAttachments;
2021

2122
public DecalGBufferRenderPass(DecalScreenSpaceSettings settings, DecalDrawGBufferSystem drawSystem)
2223
{
@@ -41,7 +42,14 @@ internal void Setup(DeferredLights deferredLights)
4142

4243
public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
4344
{
44-
ConfigureTarget(m_DeferredLights.GbufferAttachmentIdentifiers, m_DeferredLights.DepthAttachmentIdentifier);
45+
if (m_GbufferAttachments == null)
46+
m_GbufferAttachments = new RenderTargetIdentifier[] { m_DeferredLights.GbufferAttachmentIdentifiers[0], m_DeferredLights.GbufferAttachmentIdentifiers[1],
47+
m_DeferredLights.GbufferAttachmentIdentifiers[2], m_DeferredLights.GbufferAttachmentIdentifiers[3] };
48+
49+
ConfigureTarget(m_GbufferAttachments, m_DeferredLights.DepthAttachmentIdentifier, m_DeferredLights.GbufferFormats);
50+
if (m_DeferredLights.UseRenderPass)
51+
ConfigureInputAttachments(m_DeferredLights.DepthCopyTextureIdentifier, false);
52+
4553
}
4654

4755
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)

com.unity.render-pipelines.universal/Runtime/RendererFeatures/DecalRendererFeature.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,9 +476,10 @@ public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingD
476476
new RenderTargetHandle(m_DBufferRenderPass.cameraDepthTextureIndentifier),
477477
new RenderTargetHandle(m_DBufferRenderPass.dBufferDepthIndentifier)
478478
);
479+
480+
m_CopyDepthPass.CopyToDepth = true;
479481
}
480482
m_CopyDepthPass.MssaSamples = 1;
481-
m_CopyDepthPass.CopyToDepth = true;
482483

483484
renderer.EnqueuePass(m_CopyDepthPass);
484485
renderer.EnqueuePass(m_DBufferRenderPass);

0 commit comments

Comments
 (0)