Skip to content

Commit 9badf08

Browse files
committed
Universal/depth copy as color #5987
commit 70ad6ee Author: Jonas Sideravičius <jonass@unity3d.com> Date: Thu Oct 14 15:04:53 2021 +0300 adding some editor-specific code to avoid a bug with editor setting incorrect depth buffer while on game view commit 850428a Author: Jonas Sideravičius <jonass@unity3d.com> Date: Wed Oct 13 12:28:57 2021 +0300 null exception fix commit 427e0cb Author: Jonas Sideravičius <jonass@unity3d.com> Date: Wed Oct 13 10:02:30 2021 +0300 another DeferredLights null check commit fcb7d7f Author: Jonas Sideravičius <jonass@unity3d.com> Date: Tue Oct 12 15:31:42 2021 +0300 fix for RTIs non render pass platforms commit 62ca66d Author: Jonas Sideravicius <jonass@unity3d.com> Date: Tue Oct 12 13:14:55 2021 +0300 fixing shader compilation error and renaming define for fb fetch idx commit b5a042f Merge: 4deded8 f9152cf Author: Jonas Sideravicius <jonass@unity3d.com> Date: Tue Oct 12 12:11:44 2021 +0300 Merge branch 'universal/depth-copy-as-color' of ssh://github.com/Unity-Technologies/Graphics into universal/depth-copy-as-color commit f9152cf Author: Jonas Sideravičius <jonass@unity3d.com> Date: Tue Oct 12 12:07:03 2021 +0300 adding fb fetch to Gbuffer decals and some other depth related fixes for decals commit 159580e Author: Jonas Sideravičius <jonass@unity3d.com> Date: Mon Oct 11 17:37:35 2021 +0300 fixing DBuffer Decals CopyDepth pass not copying the depth and failing rendering commit f95fafb Merge: c4ddd12 e718a8e Author: Jonas Sideravičius <jonass@unity3d.com> Date: Mon Oct 11 13:45:13 2021 +0300 Merge branch 'master' into universal/depth-copy-as-color commit 4deded8 Merge: c4ddd12 1ede825 Author: Jonas Sideravicius <jonass@unity3d.com> Date: Wed Oct 6 16:30:14 2021 +0300 Merge branch 'master' into universal/depth-copy-as-color commit c4ddd12 Author: Jonas Sideravicius <jonass@unity3d.com> Date: Wed Aug 25 13:40:27 2021 +0300 changing the semantic for outDepthColor in VFXPasses.template commit 5dec840 Author: Jonas Sideravicius <jonass@unity3d.com> Date: Tue Aug 24 11:53:11 2021 +0300 adding depth output for VFXGraph depth only passes commit 2510a18 Merge: fd4df44 a938468 Author: Jonas Sideravicius <jonass@unity3d.com> Date: Mon Aug 23 12:00:52 2021 +0300 Merge branch 'master' into universal/depth-copy-as-color commit fd4df44 Author: Jonas Sideravicius <jonass@unity3d.com> Date: Thu Aug 19 15:47:23 2021 +0300 adding _OUTPUT_DEPTH keyword to CopyDepthPass to select correct output buffer in shader commit 165f4d5 Author: Jonas Sideravicius <jonass@unity3d.com> Date: Tue Aug 17 17:26:19 2021 +0300 some cleanup and refactoring and enabling Renderpass for SS forward decals commit 4f9cbd7 Author: Jonas Sideravicius <jonass@unity3d.com> Date: Tue Aug 17 16:02:04 2021 +0300 adding depth copy for renderpass as well and changing how fake depth is handled commit 68d3938 Author: Jonas Sideravicius <jonass@unity3d.com> Date: Tue Aug 17 10:33:59 2021 +0300 terrain shader passes depthonly pass fix to output clippos commit 399ee75 Author: Jonas Sideravicius <jonass@unity3d.com> Date: Mon Aug 16 16:30:48 2021 +0300 formatting fixes commit ee6e7d4 Author: Jonas Sideravicius <jonass@unity3d.com> Date: Mon Aug 16 11:48:25 2021 +0300 enabling depthbuffer for depth copy and adding additional override for ConfigureTarget commit 6accb1c Author: Jonas Sideravicius <jonass@unity3d.com> Date: Fri Aug 13 16:42:23 2021 +0300 merge fix - change descriptor for DepthOnly configureTarget to the correct one commit d887392 Author: Jonas Sideravicius <jonass@unity3d.com> Date: Fri Aug 13 16:10:30 2021 +0300 fix after updating trunk commit 624f0a1 Merge: 933f089 8ee37d5 Author: Jonas Sideravicius <jonass@unity3d.com> Date: Thu Aug 12 16:53:11 2021 +0300 Merge branch 'master' into universal/depth-copy-as-color commit 933f089 Author: Jonas Sideravicius <jonass@unity3d.com> Date: Thu Aug 12 16:43:25 2021 +0300 making depthOnly pass compatible to render color texture and changing shaders to accommodate that commit c149ec9 Author: Jonas Sideravicius <jonass@unity3d.com> Date: Thu Aug 5 14:40:21 2021 +0300 adding IsTransientAttachment to ScriptableRenderPass/NativeRenderPass code commit d39e96d Author: Jonas Sideravicius <jonass@unity3d.com> Date: Tue Aug 3 11:59:28 2021 +0300 disable fbfetch on DbufferDeferred decals commit d1cef12 Author: Jonas Sideravicius <jonass@unity3d.com> Date: Thu Jul 29 11:57:25 2021 +0300 Revert "some changes to the Foundation Project for Repro project (to be reverted later on)" This reverts commit 80af9be. commit 80af9be Author: Jonas Sideravicius <jonass@unity3d.com> Date: Thu Jul 29 11:21:14 2021 +0300 some changes to the Foundation Project for Repro project (to be reverted later on) commit a2e4eb6 Author: Jonas Sideravicius <jonass@unity3d.com> Date: Thu Jul 29 11:02:07 2021 +0300 switching _CameraDepthTexture to R32Float and accommodating some stuff for that
1 parent 6462029 commit 9badf08

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+198
-62
lines changed

TestProjects/UniversalGraphicsTest_Foundation/Assets/Scenes/230_Decals/Materials/Brick.mat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Material:
1313
m_LightmapFlags: 4
1414
m_EnableInstancingVariants: 0
1515
m_DoubleSidedGI: 0
16-
m_CustomRenderQueue: 2000
16+
m_CustomRenderQueue: 1999
1717
stringTagMap:
1818
RenderType: Opaque
1919
disabledShaderPasses: []
@@ -95,7 +95,7 @@ Material:
9595
- _Metallic: 0
9696
- _OcclusionStrength: 0.387
9797
- _Parallax: 0.0477
98-
- _QueueOffset: 0
98+
- _QueueOffset: -1
9999
- _ReceiveShadows: 1
100100
- _Smoothness: 0.742
101101
- _SmoothnessTextureChannel: 0

com.unity.render-pipelines.core/ShaderLibrary/API/Metal.hlsl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@
150150
#define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2)
151151
#define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2)
152152
#define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2)
153-
154-
#if defined(SHADER_API_MOBILE)
153+
#if defined(UNITY_FRAMEBUFFER_FETCH_AVAILABLE)
155154
#define PLATFORM_SUPPORTS_NATIVE_RENDERPASS
156155
#endif

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 GBUFFER3 0
68+
FRAMEBUFFER_INPUT_HALF(GBUFFER3);
69+
#endif
6770
// Includes
6871
$splice(PreGraphIncludes)
6972

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ half4 frag(PackedVaryings packedInput) : SV_TARGET
2121
clip(surfaceDescription.Alpha - surfaceDescription.AlphaClipThreshold);
2222
#endif
2323

24-
return 0;
24+
return packedInput.positionCS.z;
2525
}
2626

2727
#endif

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(GBUFFER3, 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(GBUFFER3, 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/Editor/ShaderGraph/Targets/UniversalTarget.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,7 @@ public static RenderStateCollection DepthOnly(UniversalTarget target)
12421242
{ RenderState.ZTest(ZTest.LEqual) },
12431243
{ RenderState.ZWrite(ZWrite.On) },
12441244
{ UberSwitchedCullRenderState(target) },
1245-
{ RenderState.ColorMask("ColorMask 0") },
1245+
{ RenderState.ColorMask("ColorMask R") },
12461246
};
12471247

12481248
return result;

com.unity.render-pipelines.universal/Editor/VFXGraph/Shaders/VFXPasses.template

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ void frag(ps_input i
8686
#if VFX_PASSDEPTH == VFX_PASSDEPTH_ACTUAL
8787
#if defined(WRITE_NORMAL_BUFFER)
8888
, out float4 outNormalBuffer : SV_Target0
89+
, out float4 outDepthColor : SV_Target1
90+
#else
91+
, out float4 outDepthColor : SV_Target0
8992
#endif
9093
#elif VFX_PASSDEPTH == VFX_PASSDEPTH_SELECTION
9194
, out float4 outColor : SV_Target0
@@ -130,7 +133,7 @@ void frag(ps_input i
130133
// We use depth prepass for scene selection in the editor, this code allow to output the outline correctly
131134
outColor = float4(_ObjectId, _PassValue, 1.0, 1.0);
132135
#elif VFX_PASSDEPTH == VFX_PASSDEPTH_ACTUAL
133-
//void
136+
outDepthColor = float4(i.VFX_VARYING_POSCS.z, 0,0,0);
134137
#elif VFX_PASSDEPTH == VFX_PASSDEPTH_SHADOW
135138
//void
136139
#else

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

Lines changed: 15 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,20 @@ 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_DeferredLights != null && m_DeferredLights.UseRenderPass)
46+
{
47+
if (m_GbufferAttachments == null)
48+
m_GbufferAttachments = new RenderTargetIdentifier[]
49+
{
50+
m_DeferredLights.GbufferAttachmentIdentifiers[0], m_DeferredLights.GbufferAttachmentIdentifiers[1],
51+
m_DeferredLights.GbufferAttachmentIdentifiers[2], m_DeferredLights.GbufferAttachmentIdentifiers[3]
52+
};
53+
ConfigureInputAttachments(m_DeferredLights.DepthCopyTextureIdentifier, false);
54+
}
55+
else
56+
m_GbufferAttachments = m_DeferredLights.GbufferAttachmentIdentifiers;
57+
58+
ConfigureTarget(m_GbufferAttachments, m_DeferredLights.DepthAttachmentIdentifier);
4559
}
4660

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

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ internal bool AccurateGbufferNormals
188188
// Output lighting result.
189189
internal RenderTargetHandle[] GbufferAttachments { get; set; }
190190
internal RenderTargetIdentifier[] DeferredInputAttachments { get; set; }
191+
internal bool[] DeferredInputIsTransient { get; set; }
191192
// Input depth texture, also bound as read-only RT
192193
internal RenderTargetHandle DepthAttachment { get; set; }
193194
//
@@ -402,12 +403,17 @@ public void Setup(ref RenderingData renderingData,
402403
this.GbufferAttachmentIdentifiers[i] = this.GbufferAttachments[i].Identifier();
403404
this.GbufferFormats[i] = this.GetGBufferFormat(i);
404405
}
405-
if (this.DeferredInputAttachments == null && this.UseRenderPass && this.GbufferAttachments.Length >= 5)
406+
if (this.DeferredInputAttachments == null && this.UseRenderPass && this.GbufferAttachments.Length >= 3)
406407
{
407408
this.DeferredInputAttachments = new RenderTargetIdentifier[4]
408409
{
409410
this.GbufferAttachmentIdentifiers[0], this.GbufferAttachmentIdentifiers[1],
410-
this.GbufferAttachmentIdentifiers[2], this.GbufferAttachmentIdentifiers[4]
411+
this.GbufferAttachmentIdentifiers[2], this.DepthCopyTextureIdentifier
412+
};
413+
414+
this.DeferredInputIsTransient = new bool[4]
415+
{
416+
true, true, true, false
411417
};
412418
}
413419
this.DepthAttachmentIdentifier = depthAttachment.Identifier();

0 commit comments

Comments
 (0)