Skip to content

Commit a2e4eb6

Browse files
committed
switching _CameraDepthTexture to R32Float and accommodating some stuff for that
1 parent 76549fd commit a2e4eb6

File tree

9 files changed

+29
-13
lines changed

9 files changed

+29
-13
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ internal void Setup(DeferredLights deferredLights)
4141

4242
public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
4343
{
44-
ConfigureTarget(m_DeferredLights.GbufferAttachmentIdentifiers, m_DeferredLights.DepthAttachmentIdentifier);
44+
ConfigureTarget(new RenderTargetIdentifier[] {m_DeferredLights.GbufferAttachmentIdentifiers[0], m_DeferredLights.GbufferAttachmentIdentifiers[1], m_DeferredLights.GbufferAttachmentIdentifiers[2], m_DeferredLights.GbufferAttachmentIdentifiers[3] }, m_DeferredLights.DepthAttachmentIdentifier);
4545
}
4646

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

com.unity.render-pipelines.universal/Runtime/DeferredLights.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ struct DrawCall
245245
"_GBuffer1",
246246
"_GBuffer2",
247247
"_GBuffer3",
248-
"_GBuffer4",
248+
"_CameraDepthTexture",
249249
"_GBuffer5",
250250
"_GBuffer6"
251251
};

com.unity.render-pipelines.universal/Runtime/NativeRenderPass.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,9 +509,15 @@ internal void SetupInputAttachmentIndices(ScriptableRenderPass pass)
509509
continue;
510510
}
511511

512+
m_ActiveColorAttachmentDescriptors[pass.m_InputAttachmentIndices[i]].loadAction = RenderBufferLoadAction.DontCare;
513+
514+
// If the attachment doesn't require store - it should be transient
515+
if (i >= 3)
516+
{
517+
return;
518+
}
512519
// Assume input attachment has to be transient as ScriptableRenderPass currently has only setters for StoreAction
513520
// We also change the target of the descriptor for it to be initialized engine-side as a transient resource.
514-
m_ActiveColorAttachmentDescriptors[pass.m_InputAttachmentIndices[i]].loadAction = RenderBufferLoadAction.DontCare;
515521
m_ActiveColorAttachmentDescriptors[pass.m_InputAttachmentIndices[i]].storeAction = RenderBufferStoreAction.DontCare;
516522
m_ActiveColorAttachmentDescriptors[pass.m_InputAttachmentIndices[i]].loadStoreTarget = BuiltinRenderTextureType.None;
517523
}

com.unity.render-pipelines.universal/Runtime/Passes/CopyDepthPass.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,15 @@ public void Setup(RenderTargetHandle source, RenderTargetHandle destination)
4343
public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
4444
{
4545
var descriptor = renderingData.cameraData.cameraTargetDescriptor;
46-
descriptor.colorFormat = RenderTextureFormat.Depth;
47-
descriptor.depthBufferBits = 32; //TODO: do we really need this. double check;
46+
// descriptor.colorFormat = RenderTextureFormat.Depth;
47+
descriptor.graphicsFormat = GraphicsFormat.R32_SFloat;
48+
descriptor.depthBufferBits = 0; //TODO: do we really need this. double check;
4849
descriptor.msaaSamples = 1;
4950
if (this.AllocateRT)
5051
cmd.GetTemporaryRT(destination.id, descriptor, FilterMode.Point);
5152

5253
// On Metal iOS, prevent camera attachments to be bound and cleared during this pass.
53-
ConfigureTarget(new RenderTargetIdentifier(destination.Identifier(), 0, CubemapFace.Unknown, -1), GraphicsFormat.DepthAuto, descriptor.width, descriptor.height, descriptor.msaaSamples, true);
54+
ConfigureTarget(new RenderTargetIdentifier(destination.Identifier(), 0, CubemapFace.Unknown, -1), GraphicsFormat.R32_SFloat, descriptor.width, descriptor.height, descriptor.msaaSamples, false);
5455
ConfigureClear(ClearFlag.None, Color.black);
5556
}
5657

com.unity.render-pipelines.universal/Runtime/Passes/GBufferPass.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,15 @@ public override void Configure(CommandBuffer cmd, RenderTextureDescriptor camera
7070
continue;
7171

7272
// No need to setup temporaryRTs if we are using input attachments as they will be Memoryless
73-
if (m_DeferredLights.UseRenderPass && i != m_DeferredLights.GBufferShadowMask && i != m_DeferredLights.GBufferRenderingLayers)
73+
if (m_DeferredLights.UseRenderPass && i != m_DeferredLights.GBufferShadowMask && i != m_DeferredLights.GBufferRenderingLayers && i != m_DeferredLights.GbufferDepthIndex)
7474
continue;
7575

7676
RenderTextureDescriptor gbufferSlice = cameraTextureDescriptor;
7777
gbufferSlice.depthBufferBits = 0; // make sure no depth surface is actually created
7878
gbufferSlice.stencilFormat = GraphicsFormat.None;
7979
gbufferSlice.graphicsFormat = m_DeferredLights.GetGBufferFormat(i);
80-
cmd.GetTemporaryRT(m_DeferredLights.GbufferAttachments[i].id, gbufferSlice);
80+
81+
cmd.GetTemporaryRT(m_DeferredLights.GbufferAttachments[i].id, gbufferSlice, FilterMode.Point);
8182
}
8283
}
8384

@@ -127,6 +128,7 @@ public override void Execute(ScriptableRenderContext context, ref RenderingData
127128
// Input attachments will only be used when this is not needed so safe to skip in that case
128129
if (!m_DeferredLights.UseRenderPass)
129130
gbufferCommands.SetGlobalTexture(s_CameraNormalsTextureID, m_DeferredLights.GbufferAttachmentIdentifiers[m_DeferredLights.GBufferNormalSmoothnessIndex]);
131+
// gbufferCommands.SetGlobalTexture("_GBuffer4", m_DeferredLights.GbufferAttachmentIdentifiers[4]);
130132
}
131133

132134
context.ExecuteCommandBuffer(gbufferCommands);

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ private void RecreateSystemsIfNeeded(ScriptableRenderer renderer, in CameraData
378378
case DecalTechnique.GBuffer:
379379

380380
m_DeferredLights = universalRenderer.deferredLights;
381+
//m_DeferredLights.DisableFramebufferFetchInput();
381382

382383
m_CopyDepthPass = new CopyDepthPass(RenderPassEvent.AfterRenderingOpaques, m_DBufferClearMaterial);
383384
m_DrawGBufferSystem = new DecalDrawGBufferSystem(m_DecalEntityManager);
@@ -483,6 +484,11 @@ public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingD
483484
}
484485
}
485486

487+
internal override bool SupportsNativeRenderPass()
488+
{
489+
return m_Technique == DecalTechnique.GBuffer;
490+
}
491+
486492
protected override void Dispose(bool disposing)
487493
{
488494
CoreUtils.Destroy(m_CopyDepthMaterial);

com.unity.render-pipelines.universal/Runtime/UniversalRenderer.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -641,8 +641,8 @@ public override void Setup(ScriptableRenderContext context, ref RenderingData re
641641

642642
if (this.actualRenderingMode == RenderingMode.Deferred)
643643
{
644-
if (m_DeferredLights.UseRenderPass && (RenderPassEvent.AfterRenderingGbuffer == renderPassInputs.requiresDepthNormalAtEvent || !useRenderPassEnabled))
645-
m_DeferredLights.DisableFramebufferFetchInput();
644+
// if (m_DeferredLights.UseRenderPass && (RenderPassEvent.AfterRenderingGbuffer == renderPassInputs.requiresDepthNormalAtEvent || !useRenderPassEnabled))
645+
// m_DeferredLights.DisableFramebufferFetchInput();
646646

647647
EnqueueDeferred(ref renderingData, requiresDepthPrepass, renderPassInputs.requiresNormalsTexture, mainLightShadows, additionalLightShadows);
648648
}
@@ -677,7 +677,8 @@ public override void Setup(ScriptableRenderContext context, ref RenderingData re
677677
}
678678

679679
// If a depth texture was created we necessarily need to copy it, otherwise we could have render it to a renderbuffer.
680-
if (requiresDepthCopyPass)
680+
// Also skip if Deferred+RenderPass as CameraDepthTexture is used and filled by the GBufferPass
681+
if (requiresDepthCopyPass && !(this.actualRenderingMode == RenderingMode.Deferred && useRenderPassEnabled))
681682
{
682683
m_CopyDepthPass.Setup(m_ActiveCameraDepthAttachment, m_DepthTexture);
683684

com.unity.render-pipelines.universal/Shaders/Utils/CopyDepth.shader

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Shader "Hidden/Universal Render Pipeline/CopyDepth"
77
Pass
88
{
99
Name "CopyDepth"
10-
ZTest Always ZWrite On ColorMask 0
10+
ZTest Always ZWrite Off ColorMask R
1111
Cull Off
1212

1313
HLSLPROGRAM

com.unity.render-pipelines.universal/Shaders/Utils/CopyDepthPass.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ float SampleDepth(float2 uv)
106106
#endif
107107
}
108108

109-
float frag(Varyings input) : SV_Depth
109+
float frag(Varyings input) : SV_Target
110110
{
111111
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
112112
return SampleDepth(input.uv);

0 commit comments

Comments
 (0)