diff --git a/TestProjects/UniversalGraphicsTest_Foundation/Assets/Scenes/230_Decals/Materials/Brick.mat b/TestProjects/UniversalGraphicsTest_Foundation/Assets/Scenes/230_Decals/Materials/Brick.mat index c0fdc5848a0..02249ca0b3c 100644 --- a/TestProjects/UniversalGraphicsTest_Foundation/Assets/Scenes/230_Decals/Materials/Brick.mat +++ b/TestProjects/UniversalGraphicsTest_Foundation/Assets/Scenes/230_Decals/Materials/Brick.mat @@ -13,7 +13,7 @@ Material: m_LightmapFlags: 4 m_EnableInstancingVariants: 0 m_DoubleSidedGI: 0 - m_CustomRenderQueue: 2000 + m_CustomRenderQueue: 1999 stringTagMap: RenderType: Opaque disabledShaderPasses: [] @@ -95,7 +95,7 @@ Material: - _Metallic: 0 - _OcclusionStrength: 0.387 - _Parallax: 0.0477 - - _QueueOffset: 0 + - _QueueOffset: -1 - _ReceiveShadows: 1 - _Smoothness: 0.742 - _SmoothnessTextureChannel: 0 diff --git a/com.unity.render-pipelines.core/ShaderLibrary/API/Metal.hlsl b/com.unity.render-pipelines.core/ShaderLibrary/API/Metal.hlsl index 295f1567367..648b20b4cf8 100644 --- a/com.unity.render-pipelines.core/ShaderLibrary/API/Metal.hlsl +++ b/com.unity.render-pipelines.core/ShaderLibrary/API/Metal.hlsl @@ -150,7 +150,6 @@ #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) - -#if defined(SHADER_API_MOBILE) +#if defined(UNITY_FRAMEBUFFER_FETCH_AVAILABLE) #define PLATFORM_SUPPORTS_NATIVE_RENDERPASS #endif diff --git a/com.unity.render-pipelines.universal/Editor/Decal/DecalPass.template b/com.unity.render-pipelines.universal/Editor/Decal/DecalPass.template index a2f5629f52d..f7e020aaa62 100644 --- a/com.unity.render-pipelines.universal/Editor/Decal/DecalPass.template +++ b/com.unity.render-pipelines.universal/Editor/Decal/DecalPass.template @@ -63,7 +63,10 @@ Pass #ifdef SCENEPICKINGPASS float4 _SelectionID; #endif - + #if _RENDER_PASS_ENABLED + #define GBUFFER3 0 + FRAMEBUFFER_INPUT_HALF(GBUFFER3); + #endif // Includes $splice(PreGraphIncludes) diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/DepthOnlyPass.hlsl b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/DepthOnlyPass.hlsl index 26e80370a59..996ecb1f75a 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/DepthOnlyPass.hlsl +++ b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/DepthOnlyPass.hlsl @@ -21,7 +21,7 @@ half4 frag(PackedVaryings packedInput) : SV_TARGET clip(surfaceDescription.Alpha - surfaceDescription.AlphaClipThreshold); #endif - return 0; + return packedInput.positionCS.z; } #endif diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPassDecal.hlsl b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPassDecal.hlsl index f32803419a1..4dc1d7ddb05 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPassDecal.hlsl +++ b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPassDecal.hlsl @@ -181,12 +181,20 @@ void Frag(PackedVaryings packedInput, #if defined(DECAL_PROJECTOR) #if UNITY_REVERSED_Z +#if _RENDER_PASS_ENABLED + float depth = LOAD_FRAMEBUFFER_INPUT(GBUFFER3, input.positionCS.xy); +#else float depth = LoadSceneDepth(input.positionCS.xy); +#endif +#else +#if _RENDER_PASS_ENABLED + float depth = lerp(UNITY_NEAR_CLIP_VALUE, 1, LOAD_FRAMEBUFFER_INPUT(GBUFFER3, input.positionCS.xy)); #else // Adjust z to match NDC for OpenGL float depth = lerp(UNITY_NEAR_CLIP_VALUE, 1, LoadSceneDepth(input.positionCS.xy)); #endif #endif +#endif #if defined(DECAL_RECONSTRUCT_NORMAL) #if defined(_DECAL_NORMAL_BLEND_HIGH) diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalDecalSubTarget.cs b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalDecalSubTarget.cs index 50ed2eacf84..11adb01cbd6 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalDecalSubTarget.cs +++ b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalDecalSubTarget.cs @@ -977,6 +977,7 @@ static class Descriptors { CoreKeywordDescriptors.MixedLightingSubtractive }, { Descriptors.DecalsNormalBlend }, { CoreKeywordDescriptors.GBufferNormalsOct }, + { CoreKeywordDescriptors.RenderPassEnabled }, { Descriptors.LodCrossFade, new FieldCondition(Fields.LodCrossFade, true) }, }; @@ -986,6 +987,7 @@ static class Descriptors { CoreKeywordDescriptors.ShadowsSoft }, { Descriptors.DecalsNormalBlend }, { CoreKeywordDescriptors.GBufferNormalsOct }, + { CoreKeywordDescriptors.RenderPassEnabled }, }; } #endregion diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalTarget.cs b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalTarget.cs index 9fc4dfa43f4..d23387eaadd 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalTarget.cs +++ b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalTarget.cs @@ -1242,7 +1242,7 @@ public static RenderStateCollection DepthOnly(UniversalTarget target) { RenderState.ZTest(ZTest.LEqual) }, { RenderState.ZWrite(ZWrite.On) }, { UberSwitchedCullRenderState(target) }, - { RenderState.ColorMask("ColorMask 0") }, + { RenderState.ColorMask("ColorMask R") }, }; return result; diff --git a/com.unity.render-pipelines.universal/Editor/VFXGraph/Shaders/VFXPasses.template b/com.unity.render-pipelines.universal/Editor/VFXGraph/Shaders/VFXPasses.template index 0515d737096..ab6d76d401a 100644 --- a/com.unity.render-pipelines.universal/Editor/VFXGraph/Shaders/VFXPasses.template +++ b/com.unity.render-pipelines.universal/Editor/VFXGraph/Shaders/VFXPasses.template @@ -86,6 +86,9 @@ void frag(ps_input i #if VFX_PASSDEPTH == VFX_PASSDEPTH_ACTUAL #if defined(WRITE_NORMAL_BUFFER) , out float4 outNormalBuffer : SV_Target0 + , out float4 outDepthColor : SV_Target1 + #else + , out float4 outDepthColor : SV_Target0 #endif #elif VFX_PASSDEPTH == VFX_PASSDEPTH_SELECTION , out float4 outColor : SV_Target0 @@ -130,7 +133,7 @@ void frag(ps_input i // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); #elif VFX_PASSDEPTH == VFX_PASSDEPTH_ACTUAL - //void + outDepthColor = float4(i.VFX_VARYING_POSCS.z, 0,0,0); #elif VFX_PASSDEPTH == VFX_PASSDEPTH_SHADOW //void #else diff --git a/com.unity.render-pipelines.universal/Runtime/Decal/ScreenSpace/DecalGBufferRenderPass.cs b/com.unity.render-pipelines.universal/Runtime/Decal/ScreenSpace/DecalGBufferRenderPass.cs index 50d65c9dccd..d87ae624318 100644 --- a/com.unity.render-pipelines.universal/Runtime/Decal/ScreenSpace/DecalGBufferRenderPass.cs +++ b/com.unity.render-pipelines.universal/Runtime/Decal/ScreenSpace/DecalGBufferRenderPass.cs @@ -17,6 +17,7 @@ internal class DecalGBufferRenderPass : ScriptableRenderPass private DecalDrawGBufferSystem m_DrawSystem; private DecalScreenSpaceSettings m_Settings; private DeferredLights m_DeferredLights; + private RenderTargetIdentifier[] m_GbufferAttachments; public DecalGBufferRenderPass(DecalScreenSpaceSettings settings, DecalDrawGBufferSystem drawSystem) { @@ -41,7 +42,20 @@ internal void Setup(DeferredLights deferredLights) public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData) { - ConfigureTarget(m_DeferredLights.GbufferAttachmentIdentifiers, m_DeferredLights.DepthAttachmentIdentifier); + if (m_DeferredLights != null && m_DeferredLights.UseRenderPass) + { + if (m_GbufferAttachments == null) + m_GbufferAttachments = new RenderTargetIdentifier[] + { + m_DeferredLights.GbufferAttachmentIdentifiers[0], m_DeferredLights.GbufferAttachmentIdentifiers[1], + m_DeferredLights.GbufferAttachmentIdentifiers[2], m_DeferredLights.GbufferAttachmentIdentifiers[3] + }; + ConfigureInputAttachments(m_DeferredLights.DepthCopyTextureIdentifier, false); + } + else + m_GbufferAttachments = m_DeferredLights.GbufferAttachmentIdentifiers; + + ConfigureTarget(m_GbufferAttachments, m_DeferredLights.DepthAttachmentIdentifier); } public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) diff --git a/com.unity.render-pipelines.universal/Runtime/DeferredLights.cs b/com.unity.render-pipelines.universal/Runtime/DeferredLights.cs index 7ea78e2d28f..1888441f080 100644 --- a/com.unity.render-pipelines.universal/Runtime/DeferredLights.cs +++ b/com.unity.render-pipelines.universal/Runtime/DeferredLights.cs @@ -188,6 +188,7 @@ internal bool AccurateGbufferNormals // Output lighting result. internal RenderTargetHandle[] GbufferAttachments { get; set; } internal RenderTargetIdentifier[] DeferredInputAttachments { get; set; } + internal bool[] DeferredInputIsTransient { get; set; } // Input depth texture, also bound as read-only RT internal RenderTargetHandle DepthAttachment { get; set; } // @@ -402,12 +403,17 @@ public void Setup(ref RenderingData renderingData, this.GbufferAttachmentIdentifiers[i] = this.GbufferAttachments[i].Identifier(); this.GbufferFormats[i] = this.GetGBufferFormat(i); } - if (this.DeferredInputAttachments == null && this.UseRenderPass && this.GbufferAttachments.Length >= 5) + if (this.DeferredInputAttachments == null && this.UseRenderPass && this.GbufferAttachments.Length >= 3) { this.DeferredInputAttachments = new RenderTargetIdentifier[4] { this.GbufferAttachmentIdentifiers[0], this.GbufferAttachmentIdentifiers[1], - this.GbufferAttachmentIdentifiers[2], this.GbufferAttachmentIdentifiers[4] + this.GbufferAttachmentIdentifiers[2], this.DepthCopyTextureIdentifier + }; + + this.DeferredInputIsTransient = new bool[4] + { + true, true, true, false }; } this.DepthAttachmentIdentifier = depthAttachment.Identifier(); diff --git a/com.unity.render-pipelines.universal/Runtime/NativeRenderPass.cs b/com.unity.render-pipelines.universal/Runtime/NativeRenderPass.cs index 4a117d6b681..2dc8e24140c 100644 --- a/com.unity.render-pipelines.universal/Runtime/NativeRenderPass.cs +++ b/com.unity.render-pipelines.universal/Runtime/NativeRenderPass.cs @@ -29,6 +29,11 @@ public partial class ScriptableRenderer }; AttachmentDescriptor m_ActiveDepthAttachmentDescriptor; + bool[] m_IsActiveColorAttachmentTransient = new bool[] + { + false, false, false, false, false, false, false, false + }; + internal RenderBufferStoreAction[] m_FinalColorStoreAction = new RenderBufferStoreAction[] { RenderBufferStoreAction.Store, RenderBufferStoreAction.Store, RenderBufferStoreAction.Store, RenderBufferStoreAction.Store, @@ -200,6 +205,7 @@ internal void SetNativeRenderPassMRTAttachmentList(ScriptableRenderPass renderPa UpdateFinalStoreActions(currentMergeablePasses, cameraData); int currentAttachmentIdx = 0; + bool hasInput = false; foreach (var passIdx in currentMergeablePasses) { if (passIdx == -1) @@ -248,7 +254,10 @@ internal void SetNativeRenderPassMRTAttachmentList(ScriptableRenderPass renderPa } if (PassHasInputAttachments(pass)) + { + hasInput = true; SetupInputAttachmentIndices(pass); + } // TODO: this is redundant and is being setup for each attachment. Needs to be done only once per mergeable pass list (we need to make sure mergeable passes use the same depth!) m_ActiveDepthAttachmentDescriptor = new AttachmentDescriptor(SystemInfo.GetGraphicsFormat(DefaultFormat.DepthStencil)); @@ -260,6 +269,9 @@ internal void SetNativeRenderPassMRTAttachmentList(ScriptableRenderPass renderPa if (m_UseOptimizedStoreActions) m_ActiveDepthAttachmentDescriptor.storeAction = m_FinalDepthStoreAction; } + + if (hasInput) + SetupTransientInputAttachments(m_RenderPassesAttachmentCount[currentPassHash]); } } @@ -504,6 +516,7 @@ internal void ExecuteNativeRenderPass(ScriptableRenderContext context, Scriptabl for (int i = 0; i < m_ActiveColorAttachmentDescriptors.Length; ++i) { m_ActiveColorAttachmentDescriptors[i] = RenderingUtils.emptyAttachment; + m_IsActiveColorAttachmentTransient[i] = false; } m_ActiveDepthAttachmentDescriptor = RenderingUtils.emptyAttachment; @@ -523,11 +536,25 @@ internal void SetupInputAttachmentIndices(ScriptableRenderPass pass) continue; } - // Assume input attachment has to be transient as ScriptableRenderPass currently has only setters for StoreAction - // We also change the target of the descriptor for it to be initialized engine-side as a transient resource. - m_ActiveColorAttachmentDescriptors[pass.m_InputAttachmentIndices[i]].loadAction = RenderBufferLoadAction.DontCare; - m_ActiveColorAttachmentDescriptors[pass.m_InputAttachmentIndices[i]].storeAction = RenderBufferStoreAction.DontCare; - m_ActiveColorAttachmentDescriptors[pass.m_InputAttachmentIndices[i]].loadStoreTarget = BuiltinRenderTextureType.None; + // Only update it as long as it has default value - if it was changed once, we assume it'll be memoryless in the whole RenderPass + if (!m_IsActiveColorAttachmentTransient[pass.m_InputAttachmentIndices[i]]) + { + m_IsActiveColorAttachmentTransient[pass.m_InputAttachmentIndices[i]] = pass.IsInputAttachmentTransient(i); + } + } + } + + internal void SetupTransientInputAttachments(int attachmentCount) + { + for (int i = 0; i < attachmentCount; ++i) + { + if (!m_IsActiveColorAttachmentTransient[i]) + continue; + + m_ActiveColorAttachmentDescriptors[i].loadAction = RenderBufferLoadAction.DontCare; + m_ActiveColorAttachmentDescriptors[i].storeAction = RenderBufferStoreAction.DontCare; + // We change the target of the descriptor for it to be initialized engine-side as a transient resource. + m_ActiveColorAttachmentDescriptors[i].loadStoreTarget = BuiltinRenderTextureType.None; } } diff --git a/com.unity.render-pipelines.universal/Runtime/Passes/CopyDepthPass.cs b/com.unity.render-pipelines.universal/Runtime/Passes/CopyDepthPass.cs index 55ece56250b..e469b0256b2 100644 --- a/com.unity.render-pipelines.universal/Runtime/Passes/CopyDepthPass.cs +++ b/com.unity.render-pipelines.universal/Runtime/Passes/CopyDepthPass.cs @@ -18,6 +18,9 @@ public class CopyDepthPass : ScriptableRenderPass private RenderTargetHandle destination { get; set; } internal bool AllocateRT { get; set; } internal int MssaSamples { get; set; } + // In some cases (Scene view, XR and etc.) we actually want to output to depth buffer + // So this variable needs to be set to true to enable the correct copy shader semantic + internal bool CopyToDepth { get; set; } Material m_CopyDepthMaterial; internal bool m_CopyResolvedDepth; @@ -26,6 +29,7 @@ public CopyDepthPass(RenderPassEvent evt, Material copyDepthMaterial) { base.profilingSampler = new ProfilingSampler(nameof(CopyDepthPass)); AllocateRT = true; + CopyToDepth = false; m_CopyDepthMaterial = copyDepthMaterial; renderPassEvent = evt; m_CopyResolvedDepth = false; @@ -47,14 +51,25 @@ public void Setup(RenderTargetHandle source, RenderTargetHandle destination) public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData) { var descriptor = renderingData.cameraData.cameraTargetDescriptor; - descriptor.colorFormat = RenderTextureFormat.Depth; - descriptor.depthBufferBits = 32; //TODO: do we really need this. double check; + descriptor.graphicsFormat = GraphicsFormat.R32_SFloat; +#if UNITY_EDITOR + descriptor.depthBufferBits = 16; + +#else + descriptor.depthBufferBits = 0; + +#endif descriptor.msaaSamples = 1; if (this.AllocateRT) cmd.GetTemporaryRT(destination.id, descriptor, FilterMode.Point); + var target = new RenderTargetIdentifier(destination.Identifier(), 0, CubemapFace.Unknown, -1); +#if UNITY_EDITOR + ConfigureTarget(target, target, GraphicsFormat.R32_SFloat, descriptor.width, descriptor.height, descriptor.msaaSamples); +#else // On Metal iOS, prevent camera attachments to be bound and cleared during this pass. - ConfigureTarget(new RenderTargetIdentifier(destination.Identifier(), 0, CubemapFace.Unknown, -1), descriptor.depthStencilFormat, descriptor.width, descriptor.height, descriptor.msaaSamples, true); + ConfigureTarget(target, GraphicsFormat.R32_SFloat, descriptor.width, descriptor.height, descriptor.msaaSamples, false); +#endif ConfigureClear(ClearFlag.None, Color.black); } @@ -112,6 +127,11 @@ public override void Execute(ScriptableRenderContext context, ref RenderingData break; } + if (CopyToDepth) + cmd.EnableShaderKeyword("_OUTPUT_DEPTH"); + else + cmd.DisableShaderKeyword("_OUTPUT_DEPTH"); + cmd.SetGlobalTexture("_CameraDepthAttachment", source.Identifier()); diff --git a/com.unity.render-pipelines.universal/Runtime/Passes/DeferredPass.cs b/com.unity.render-pipelines.universal/Runtime/Passes/DeferredPass.cs index bdcb7f891a0..a78ddccedb9 100644 --- a/com.unity.render-pipelines.universal/Runtime/Passes/DeferredPass.cs +++ b/com.unity.render-pipelines.universal/Runtime/Passes/DeferredPass.cs @@ -29,7 +29,7 @@ public override void Configure(CommandBuffer cmd, RenderTextureDescriptor camera RenderTargetIdentifier lightingAttachmentId = m_DeferredLights.GbufferAttachmentIdentifiers[m_DeferredLights.GBufferLightingIndex]; RenderTargetIdentifier depthAttachmentId = m_DeferredLights.DepthAttachmentIdentifier; if (m_DeferredLights.UseRenderPass) - ConfigureInputAttachments(m_DeferredLights.DeferredInputAttachments); + ConfigureInputAttachments(m_DeferredLights.DeferredInputAttachments, m_DeferredLights.DeferredInputIsTransient); // TODO: change to m_DeferredLights.GetGBufferFormat(m_DeferredLights.GBufferLightingIndex) when it's not GraphicsFormat.None // TODO: Cannot currently bind depth texture as read-only! diff --git a/com.unity.render-pipelines.universal/Runtime/Passes/DepthOnlyPass.cs b/com.unity.render-pipelines.universal/Runtime/Passes/DepthOnlyPass.cs index 00b3a1aa512..a20015a5356 100644 --- a/com.unity.render-pipelines.universal/Runtime/Passes/DepthOnlyPass.cs +++ b/com.unity.render-pipelines.universal/Runtime/Passes/DepthOnlyPass.cs @@ -31,6 +31,7 @@ public DepthOnlyPass(RenderPassEvent evt, RenderQueueRange renderQueueRange, Lay base.profilingSampler = new ProfilingSampler(nameof(DepthOnlyPass)); m_FilteringSettings = new FilteringSettings(renderQueueRange, layerMask); renderPassEvent = evt; + useNativeRenderPass = false; } /// @@ -41,7 +42,8 @@ public void Setup( RenderTargetHandle depthAttachmentHandle) { this.depthAttachmentHandle = depthAttachmentHandle; - baseDescriptor.colorFormat = RenderTextureFormat.Depth; + baseDescriptor.graphicsFormat = GraphicsFormat.R32_SFloat; + // Even though this texture is going to be a color texture, we need depth buffer to correctly render it (ZTest and all) baseDescriptor.depthBufferBits = k_DepthBufferBits; // Depth-Only pass don't use MSAA @@ -61,16 +63,18 @@ public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderin // When depth priming is in use the camera target should not be overridden so the Camera's MSAA depth attachment is used. if (renderingData.cameraData.renderer.useDepthPriming && (renderingData.cameraData.renderType == CameraRenderType.Base || renderingData.cameraData.clearDepth)) { - ConfigureTarget(renderingData.cameraData.renderer.cameraDepthTarget, descriptor.depthStencilFormat, desc.width, desc.height, 1, true); + ConfigureTarget(renderingData.cameraData.renderer.cameraDepthTarget, desc.depthStencilFormat, desc.width, desc.height, 1, true); + // Only clear depth here so we don't clear any bound color target. It might be unused by this pass but that doesn't mean we can just clear it. (e.g. in case of overlay cameras + depth priming) + ConfigureClear(ClearFlag.Depth, Color.black); } // When not using depth priming the camera target should be set to our non MSAA depth target. else { - ConfigureTarget(new RenderTargetIdentifier(depthAttachmentHandle.Identifier(), 0, CubemapFace.Unknown, -1), descriptor.depthStencilFormat, desc.width, desc.height, 1, true); + useNativeRenderPass = true; + var target = new RenderTargetIdentifier(depthAttachmentHandle.Identifier(), 0, CubemapFace.Unknown, -1); + ConfigureTarget(target, target, GraphicsFormat.R32_SFloat, desc.width, desc.height, 1); + ConfigureClear(ClearFlag.All, Color.black); } - - // Only clear depth here so we don't clear any bound color target. It might be unused by this pass but that doesn't mean we can just clear it. (e.g. in case of overlay cameras + depth priming) - ConfigureClear(ClearFlag.Depth, Color.black); } /// diff --git a/com.unity.render-pipelines.universal/Runtime/Passes/FinalBlitPass.cs b/com.unity.render-pipelines.universal/Runtime/Passes/FinalBlitPass.cs index 3b1f0cfb827..6dcd1926258 100644 --- a/com.unity.render-pipelines.universal/Runtime/Passes/FinalBlitPass.cs +++ b/com.unity.render-pipelines.universal/Runtime/Passes/FinalBlitPass.cs @@ -109,7 +109,7 @@ public override void Execute(ScriptableRenderContext context, ref RenderingData cameraTarget, RenderBufferLoadAction.Load, RenderBufferStoreAction.Store, - ClearFlag.None, + ClearFlag.Depth, Color.black); Camera camera = cameraData.camera; diff --git a/com.unity.render-pipelines.universal/Runtime/Passes/GBufferPass.cs b/com.unity.render-pipelines.universal/Runtime/Passes/GBufferPass.cs index 9eb4cfd3649..7e9992d20a3 100644 --- a/com.unity.render-pipelines.universal/Runtime/Passes/GBufferPass.cs +++ b/com.unity.render-pipelines.universal/Runtime/Passes/GBufferPass.cs @@ -57,6 +57,11 @@ public override void Configure(CommandBuffer cmd, RenderTextureDescriptor camera if (cmd != null) { + if (m_DeferredLights.UseRenderPass) + { + m_DeferredLights.GbufferAttachments[m_DeferredLights.GbufferDepthIndex] = m_DeferredLights.DepthCopyTexture; + m_DeferredLights.GbufferAttachmentIdentifiers[m_DeferredLights.GbufferDepthIndex] = m_DeferredLights.DepthCopyTextureIdentifier; + } // Create and declare the render targets used in the pass for (int i = 0; i < gbufferAttachments.Length; ++i) { @@ -70,14 +75,15 @@ public override void Configure(CommandBuffer cmd, RenderTextureDescriptor camera continue; // No need to setup temporaryRTs if we are using input attachments as they will be Memoryless - if (m_DeferredLights.UseRenderPass && i != m_DeferredLights.GBufferShadowMask && i != m_DeferredLights.GBufferRenderingLayers) + if (m_DeferredLights.UseRenderPass && i != m_DeferredLights.GBufferShadowMask && i != m_DeferredLights.GBufferRenderingLayers && (i != m_DeferredLights.GbufferDepthIndex && !m_DeferredLights.HasDepthPrepass)) continue; RenderTextureDescriptor gbufferSlice = cameraTextureDescriptor; gbufferSlice.depthBufferBits = 0; // make sure no depth surface is actually created gbufferSlice.stencilFormat = GraphicsFormat.None; gbufferSlice.graphicsFormat = m_DeferredLights.GetGBufferFormat(i); - cmd.GetTemporaryRT(m_DeferredLights.GbufferAttachments[i].id, gbufferSlice); + + cmd.GetTemporaryRT(m_DeferredLights.GbufferAttachments[i].id, gbufferSlice, FilterMode.Point); } } diff --git a/com.unity.render-pipelines.universal/Runtime/Passes/ScriptableRenderPass.cs b/com.unity.render-pipelines.universal/Runtime/Passes/ScriptableRenderPass.cs index 2c2fd432499..2cd48776f3f 100644 --- a/com.unity.render-pipelines.universal/Runtime/Passes/ScriptableRenderPass.cs +++ b/com.unity.render-pipelines.universal/Runtime/Passes/ScriptableRenderPass.cs @@ -227,6 +227,7 @@ public Color clearColor internal GraphicsFormat[] renderTargetFormat { get; set; } RenderTargetIdentifier[] m_ColorAttachments = new RenderTargetIdentifier[] { BuiltinRenderTextureType.CameraTarget }; internal RenderTargetIdentifier[] m_InputAttachments = new RenderTargetIdentifier[8]; + internal bool[] m_InputAttachmentIsTransient = new bool[8]; RenderTargetIdentifier m_DepthAttachment = BuiltinRenderTextureType.CameraTarget; ScriptableRenderPassInput m_Input = ScriptableRenderPassInput.None; ClearFlag m_ClearFlag = ClearFlag.None; @@ -245,6 +246,7 @@ public ScriptableRenderPass() renderPassEvent = RenderPassEvent.AfterRenderingOpaques; m_ColorAttachments = new RenderTargetIdentifier[] { BuiltinRenderTextureType.CameraTarget, 0, 0, 0, 0, 0, 0, 0 }; m_InputAttachments = new RenderTargetIdentifier[] { -1, -1, -1, -1, -1, -1, -1, -1 }; + m_InputAttachmentIsTransient = new bool[] { false, false, false, false, false, false, false, false }; m_DepthAttachment = BuiltinRenderTextureType.CameraTarget; m_ColorStoreActions = new RenderBufferStoreAction[] { RenderBufferStoreAction.Store, 0, 0, 0, 0, 0, 0, 0 }; m_DepthStoreAction = RenderBufferStoreAction.Store; @@ -314,9 +316,10 @@ public void ConfigureDepthStoreAction(RenderBufferStoreAction storeAction) m_OverriddenDepthStoreAction = true; } - internal void ConfigureInputAttachments(RenderTargetIdentifier input) + internal void ConfigureInputAttachments(RenderTargetIdentifier input, bool isTransient = false) { m_InputAttachments[0] = input; + m_InputAttachmentIsTransient[0] = isTransient; } internal void ConfigureInputAttachments(RenderTargetIdentifier[] inputs) @@ -324,6 +327,22 @@ internal void ConfigureInputAttachments(RenderTargetIdentifier[] inputs) m_InputAttachments = inputs; } + internal void ConfigureInputAttachments(RenderTargetIdentifier[] inputs, bool[] isTransient) + { + ConfigureInputAttachments(inputs); + m_InputAttachmentIsTransient = isTransient; + } + + internal void SetInputAttachmentTransient(int idx, bool isTransient) + { + m_InputAttachmentIsTransient[idx] = isTransient; + } + + internal bool IsInputAttachmentTransient(int idx) + { + return m_InputAttachmentIsTransient[idx]; + } + /// /// Configures render targets for this render pass. Call this instead of CommandBuffer.SetRenderTarget. /// This method should be called inside Configure. @@ -402,6 +421,12 @@ internal void ConfigureTarget(RenderTargetIdentifier colorAttachment, GraphicsFo renderTargetFormat[0] = format; } + internal void ConfigureTarget(RenderTargetIdentifier colorAttachment, RenderTargetIdentifier depthAttachment, GraphicsFormat format, int width, int height, int sampleCount) + { + m_DepthAttachment = depthAttachment; + ConfigureTarget(colorAttachment, format, width, height, sampleCount); + } + /// /// Configures render targets for this render pass. Call this instead of CommandBuffer.SetRenderTarget. /// This method should be called inside Configure. diff --git a/com.unity.render-pipelines.universal/Runtime/RendererFeatures/DecalRendererFeature.cs b/com.unity.render-pipelines.universal/Runtime/RendererFeatures/DecalRendererFeature.cs index 7dd94364e29..2b6174b66a6 100644 --- a/com.unity.render-pipelines.universal/Runtime/RendererFeatures/DecalRendererFeature.cs +++ b/com.unity.render-pipelines.universal/Runtime/RendererFeatures/DecalRendererFeature.cs @@ -392,7 +392,10 @@ private void RecreateSystemsIfNeeded(ScriptableRenderer renderer, in CameraData m_ForwardEmissivePass = new DecalForwardEmissivePass(m_DecalDrawForwardEmissiveSystem); if (universalRenderer.actualRenderingMode == RenderingMode.Deferred) + { m_DBufferRenderPass.deferredLights = universalRenderer.deferredLights; + m_DBufferRenderPass.deferredLights.DisableFramebufferFetchInput(); + } break; } @@ -473,6 +476,8 @@ public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingD new RenderTargetHandle(m_DBufferRenderPass.cameraDepthTextureIndentifier), new RenderTargetHandle(m_DBufferRenderPass.dBufferDepthIndentifier) ); + + m_CopyDepthPass.CopyToDepth = true; } m_CopyDepthPass.MssaSamples = 1; @@ -483,6 +488,11 @@ public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingD } } + internal override bool SupportsNativeRenderPass() + { + return m_Technique == DecalTechnique.GBuffer || m_Technique == DecalTechnique.ScreenSpace; + } + protected override void Dispose(bool disposing) { CoreUtils.Destroy(m_CopyDepthMaterial); diff --git a/com.unity.render-pipelines.universal/Runtime/UniversalRenderer.cs b/com.unity.render-pipelines.universal/Runtime/UniversalRenderer.cs index b3b0496438f..d1a478df934 100644 --- a/com.unity.render-pipelines.universal/Runtime/UniversalRenderer.cs +++ b/com.unity.render-pipelines.universal/Runtime/UniversalRenderer.cs @@ -711,7 +711,9 @@ public override void Setup(ScriptableRenderContext context, ref RenderingData re } // If a depth texture was created we necessarily need to copy it, otherwise we could have render it to a renderbuffer. - if (requiresDepthCopyPass) + // Also skip if Deferred+RenderPass as CameraDepthTexture is used and filled by the GBufferPass + // however we might need the depth texture with Forward-only pass rendered to it, so enable the copy depth in that case + if (requiresDepthCopyPass && !(this.actualRenderingMode == RenderingMode.Deferred && useRenderPassEnabled && !renderPassInputs.requiresDepthTexture)) { m_CopyDepthPass.Setup(m_ActiveCameraDepthAttachment, m_DepthTexture); @@ -841,6 +843,7 @@ public override void Setup(ScriptableRenderContext context, ref RenderingData re if (!depthTargetResolved && cameraData.xr.copyDepth) { m_XRCopyDepthPass.Setup(m_ActiveCameraDepthAttachment, RenderTargetHandle.GetCameraTarget(cameraData.xr)); + m_XRCopyDepthPass.CopyToDepth = true; EnqueuePass(m_XRCopyDepthPass); } } @@ -859,6 +862,7 @@ public override void Setup(ScriptableRenderContext context, ref RenderingData re // Scene view camera should always resolve target (not stacked) Assertions.Assert.IsTrue(lastCameraInTheStack, "Editor camera must resolve target upon finish rendering."); m_FinalDepthCopyPass.Setup(m_DepthTexture, RenderTargetHandle.CameraTarget); + m_FinalDepthCopyPass.CopyToDepth = true; m_FinalDepthCopyPass.MssaSamples = 0; EnqueuePass(m_FinalDepthCopyPass); } diff --git a/com.unity.render-pipelines.universal/Shaders/BakedLit.shader b/com.unity.render-pipelines.universal/Shaders/BakedLit.shader index 9cbef2157a8..7c1f1a1fb84 100644 --- a/com.unity.render-pipelines.universal/Shaders/BakedLit.shader +++ b/com.unity.render-pipelines.universal/Shaders/BakedLit.shader @@ -82,7 +82,7 @@ Shader "Universal Render Pipeline/Baked Lit" Tags{"LightMode" = "DepthOnly"} ZWrite On - ColorMask 0 + ColorMask R HLSLPROGRAM #pragma exclude_renderers gles gles3 glcore @@ -280,7 +280,7 @@ Shader "Universal Render Pipeline/Baked Lit" Tags{"LightMode" = "DepthOnly"} ZWrite On - ColorMask 0 + ColorMask R HLSLPROGRAM #pragma only_renderers gles gles3 glcore d3d11 diff --git a/com.unity.render-pipelines.universal/Shaders/ComplexLit.shader b/com.unity.render-pipelines.universal/Shaders/ComplexLit.shader index 7ebfcbf20e8..75d11157f9a 100644 --- a/com.unity.render-pipelines.universal/Shaders/ComplexLit.shader +++ b/com.unity.render-pipelines.universal/Shaders/ComplexLit.shader @@ -191,7 +191,7 @@ Shader "Universal Render Pipeline/Complex Lit" Tags{"LightMode" = "DepthOnly"} ZWrite On - ColorMask 0 + ColorMask R Cull[_Cull] HLSLPROGRAM @@ -420,7 +420,7 @@ Shader "Universal Render Pipeline/Complex Lit" Tags{"LightMode" = "DepthOnly"} ZWrite On - ColorMask 0 + ColorMask R Cull[_Cull] HLSLPROGRAM diff --git a/com.unity.render-pipelines.universal/Shaders/DepthOnlyPass.hlsl b/com.unity.render-pipelines.universal/Shaders/DepthOnlyPass.hlsl index 7c00bd3d336..d7d12c64e5d 100644 --- a/com.unity.render-pipelines.universal/Shaders/DepthOnlyPass.hlsl +++ b/com.unity.render-pipelines.universal/Shaders/DepthOnlyPass.hlsl @@ -29,11 +29,11 @@ Varyings DepthOnlyVertex(Attributes input) return output; } -half4 DepthOnlyFragment(Varyings input) : SV_TARGET +half DepthOnlyFragment(Varyings input) : SV_TARGET { UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input); Alpha(SampleAlbedoAlpha(input.uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap)).a, _BaseColor, _Cutoff); - return 0; + return input.positionCS.z; } #endif diff --git a/com.unity.render-pipelines.universal/Shaders/Lit.shader b/com.unity.render-pipelines.universal/Shaders/Lit.shader index fb085b39a26..da4ea8dc5da 100644 --- a/com.unity.render-pipelines.universal/Shaders/Lit.shader +++ b/com.unity.render-pipelines.universal/Shaders/Lit.shader @@ -260,7 +260,7 @@ Shader "Universal Render Pipeline/Lit" Tags{"LightMode" = "DepthOnly"} ZWrite On - ColorMask 0 + ColorMask R Cull[_Cull] HLSLPROGRAM @@ -495,7 +495,7 @@ Shader "Universal Render Pipeline/Lit" Tags{"LightMode" = "DepthOnly"} ZWrite On - ColorMask 0 + ColorMask R Cull[_Cull] HLSLPROGRAM diff --git a/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree7.shader b/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree7.shader index b719ebe8896..a3a9e0164fc 100644 --- a/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree7.shader +++ b/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree7.shader @@ -168,7 +168,7 @@ Shader "Universal Render Pipeline/Nature/SpeedTree7" Name "DepthOnly" Tags{"LightMode" = "DepthOnly"} - ColorMask 0 + ColorMask R HLSLPROGRAM diff --git a/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree7Billboard.shader b/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree7Billboard.shader index a2a1e8ec143..349ad68e1a1 100644 --- a/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree7Billboard.shader +++ b/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree7Billboard.shader @@ -116,7 +116,7 @@ Shader "Universal Render Pipeline/Nature/SpeedTree7 Billboard" Name "DepthOnly" Tags{"LightMode" = "DepthOnly"} - ColorMask 0 + ColorMask R HLSLPROGRAM diff --git a/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree7CommonPasses.hlsl b/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree7CommonPasses.hlsl index 8d09d387219..24b06077f78 100644 --- a/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree7CommonPasses.hlsl +++ b/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree7CommonPasses.hlsl @@ -243,7 +243,7 @@ half4 SpeedTree7FragDepth(SpeedTreeVertexDepthOutput input) : SV_Target // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly return half4(_ObjectId, _PassValue, 1.0, 1.0); #else - return half4(0, 0, 0, 0); + return half4(input.clipPos.z, 0, 0, 0); #endif } diff --git a/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree8.shader b/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree8.shader index 47c24003005..3e768e0b56b 100644 --- a/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree8.shader +++ b/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree8.shader @@ -197,7 +197,7 @@ Shader "Universal Render Pipeline/Nature/SpeedTree8" Tags{"LightMode" = "DepthOnly"} ZWrite On - ColorMask 0 + ColorMask R HLSLPROGRAM diff --git a/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree8Passes.hlsl b/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree8Passes.hlsl index 20e664e417c..c80cf5372e2 100644 --- a/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree8Passes.hlsl +++ b/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree8Passes.hlsl @@ -512,7 +512,7 @@ half4 SpeedTree8FragDepth(SpeedTreeVertexDepthOutput input) : SV_Target // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly return half4(_ObjectId, _PassValue, 1.0, 1.0); #else - return half4(0, 0, 0, 0); + return half4(input.clipPos.z, 0, 0, 0); #endif } diff --git a/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesDepthOnlyPass.hlsl b/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesDepthOnlyPass.hlsl index 548e095990c..517e7414e4e 100644 --- a/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesDepthOnlyPass.hlsl +++ b/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesDepthOnlyPass.hlsl @@ -30,7 +30,7 @@ VaryingsDepthOnlyParticle DepthOnlyVertex(AttributesDepthOnlyParticle input) return output; } -half4 DepthOnlyFragment(VaryingsDepthOnlyParticle input) : SV_TARGET +half DepthOnlyFragment(VaryingsDepthOnlyParticle input) : SV_TARGET { UNITY_SETUP_INSTANCE_ID(input); UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input); @@ -57,7 +57,7 @@ half4 DepthOnlyFragment(VaryingsDepthOnlyParticle input) : SV_TARGET AlphaDiscard(albedo.a, _Cutoff); #endif - return 0; + return input.clipPos.z; } #endif // UNIVERSAL_PARTICLES_LIT_DEPTH_ONLY_PASS_INCLUDED diff --git a/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesLit.shader b/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesLit.shader index 59dd8a3af5e..f5480d1bb5c 100644 --- a/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesLit.shader +++ b/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesLit.shader @@ -211,7 +211,7 @@ Shader "Universal Render Pipeline/Particles/Lit" Tags{"LightMode" = "DepthOnly"} ZWrite On - ColorMask 0 + ColorMask R Cull[_Cull] HLSLPROGRAM diff --git a/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesSimpleLit.shader b/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesSimpleLit.shader index 6873d0b9b0d..8065ce63dd9 100644 --- a/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesSimpleLit.shader +++ b/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesSimpleLit.shader @@ -204,7 +204,7 @@ Shader "Universal Render Pipeline/Particles/Simple Lit" Tags{"LightMode" = "DepthOnly"} ZWrite On - ColorMask 0 + ColorMask R Cull[_Cull] HLSLPROGRAM diff --git a/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesUnlit.shader b/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesUnlit.shader index c43b3e776bd..aeb87df6ed8 100644 --- a/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesUnlit.shader +++ b/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesUnlit.shader @@ -115,7 +115,7 @@ Shader "Universal Render Pipeline/Particles/Unlit" Tags{"LightMode" = "DepthOnly"} ZWrite On - ColorMask 0 + ColorMask R Cull[_Cull] HLSLPROGRAM diff --git a/com.unity.render-pipelines.universal/Shaders/SimpleLit.shader b/com.unity.render-pipelines.universal/Shaders/SimpleLit.shader index 96f8516e45b..38f827ac723 100644 --- a/com.unity.render-pipelines.universal/Shaders/SimpleLit.shader +++ b/com.unity.render-pipelines.universal/Shaders/SimpleLit.shader @@ -214,7 +214,7 @@ Shader "Universal Render Pipeline/Simple Lit" Tags{"LightMode" = "DepthOnly"} ZWrite On - ColorMask 0 + ColorMask R Cull[_Cull] HLSLPROGRAM @@ -417,7 +417,7 @@ Shader "Universal Render Pipeline/Simple Lit" Tags{"LightMode" = "DepthOnly"} ZWrite On - ColorMask 0 + ColorMask R Cull[_Cull] HLSLPROGRAM diff --git a/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainDetailLit.shader b/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainDetailLit.shader index 9c2d7d2f2b4..1bbfce5ef73 100644 --- a/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainDetailLit.shader +++ b/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainDetailLit.shader @@ -175,7 +175,7 @@ Shader "Hidden/TerrainEngine/Details/UniversalPipeline/Vertexlit" Tags{"LightMode" = "DepthOnly"} ZWrite On - ColorMask 0 + ColorMask R HLSLPROGRAM #pragma target 2.0 diff --git a/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLit.shader b/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLit.shader index e7149778059..13186d2dac3 100644 --- a/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLit.shader +++ b/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLit.shader @@ -182,7 +182,7 @@ Shader "Universal Render Pipeline/Terrain/Lit" Tags{"LightMode" = "DepthOnly"} ZWrite On - ColorMask 0 + ColorMask R HLSLPROGRAM #pragma target 2.0 diff --git a/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitBase.shader b/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitBase.shader index 4b8a96e510b..36a42ebc5df 100644 --- a/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitBase.shader +++ b/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitBase.shader @@ -152,7 +152,7 @@ Shader "Hidden/Universal Render Pipeline/Terrain/Lit (Base Pass)" Tags{"LightMode" = "DepthOnly"} ZWrite On - ColorMask 0 + ColorMask R HLSLPROGRAM #pragma target 2.0 diff --git a/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitPasses.hlsl b/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitPasses.hlsl index e581f71cfce..890fcf65cfe 100644 --- a/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitPasses.hlsl +++ b/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitPasses.hlsl @@ -507,7 +507,7 @@ half4 DepthOnlyFragment(VaryingsLean IN) : SV_TARGET // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly return half4(_ObjectId, _PassValue, 1.0, 1.0); #endif - return 0; + return IN.clipPos.z; } #endif diff --git a/com.unity.render-pipelines.universal/Shaders/Terrain/WavingGrass.shader b/com.unity.render-pipelines.universal/Shaders/Terrain/WavingGrass.shader index 4870e7f3206..00a26314eac 100644 --- a/com.unity.render-pipelines.universal/Shaders/Terrain/WavingGrass.shader +++ b/com.unity.render-pipelines.universal/Shaders/Terrain/WavingGrass.shader @@ -60,7 +60,7 @@ Shader "Hidden/TerrainEngine/Details/UniversalPipeline/WavingDoublePass" Tags{"LightMode" = "DepthOnly"} ZWrite On - ColorMask 0 + ColorMask R Cull Off HLSLPROGRAM diff --git a/com.unity.render-pipelines.universal/Shaders/Terrain/WavingGrassBillboard.shader b/com.unity.render-pipelines.universal/Shaders/Terrain/WavingGrassBillboard.shader index 3a447789a35..c29646ab149 100644 --- a/com.unity.render-pipelines.universal/Shaders/Terrain/WavingGrassBillboard.shader +++ b/com.unity.render-pipelines.universal/Shaders/Terrain/WavingGrassBillboard.shader @@ -55,7 +55,7 @@ Shader "Hidden/TerrainEngine/Details/UniversalPipeline/BillboardWavingDoublePass Tags{"LightMode" = "DepthOnly"} ZWrite On - ColorMask 0 + ColorMask R Cull Off HLSLPROGRAM diff --git a/com.unity.render-pipelines.universal/Shaders/Terrain/WavingGrassPasses.hlsl b/com.unity.render-pipelines.universal/Shaders/Terrain/WavingGrassPasses.hlsl index 8ecf5cfa9ae..196fcc08131 100644 --- a/com.unity.render-pipelines.universal/Shaders/Terrain/WavingGrassPasses.hlsl +++ b/com.unity.render-pipelines.universal/Shaders/Terrain/WavingGrassPasses.hlsl @@ -267,6 +267,6 @@ GrassVertexDepthOnlyOutput DepthOnlyVertex(GrassVertexDepthOnlyInput v) half4 DepthOnlyFragment(GrassVertexDepthOnlyOutput input) : SV_TARGET { Alpha(SampleAlbedoAlpha(input.uv, TEXTURE2D_ARGS(_MainTex, sampler_MainTex)).a, input.color, _Cutoff); - return 0; + return input.clipPos.z; } #endif diff --git a/com.unity.render-pipelines.universal/Shaders/Unlit.shader b/com.unity.render-pipelines.universal/Shaders/Unlit.shader index 6913ce7d09c..2be70754509 100644 --- a/com.unity.render-pipelines.universal/Shaders/Unlit.shader +++ b/com.unity.render-pipelines.universal/Shaders/Unlit.shader @@ -69,7 +69,7 @@ Shader "Universal Render Pipeline/Unlit" Tags{"LightMode" = "DepthOnly"} ZWrite On - ColorMask 0 + ColorMask R HLSLPROGRAM #pragma exclude_renderers gles gles3 glcore @@ -188,7 +188,7 @@ Shader "Universal Render Pipeline/Unlit" Tags{"LightMode" = "DepthOnly"} ZWrite On - ColorMask 0 + ColorMask R HLSLPROGRAM #pragma only_renderers gles gles3 glcore d3d11 diff --git a/com.unity.render-pipelines.universal/Shaders/Utils/CopyDepth.shader b/com.unity.render-pipelines.universal/Shaders/Utils/CopyDepth.shader index 89b7fe022ab..cb21d0b9e5f 100644 --- a/com.unity.render-pipelines.universal/Shaders/Utils/CopyDepth.shader +++ b/com.unity.render-pipelines.universal/Shaders/Utils/CopyDepth.shader @@ -7,7 +7,7 @@ Shader "Hidden/Universal Render Pipeline/CopyDepth" Pass { Name "CopyDepth" - ZTest Always ZWrite On ColorMask 0 + ZTest Always ZWrite On ColorMask R Cull Off HLSLPROGRAM @@ -16,6 +16,7 @@ Shader "Hidden/Universal Render Pipeline/CopyDepth" #pragma multi_compile _ _DEPTH_MSAA_2 _DEPTH_MSAA_4 _DEPTH_MSAA_8 #pragma multi_compile _ _USE_DRAW_PROCEDURAL + #pragma multi_compile _ _OUTPUT_DEPTH #include "Packages/com.unity.render-pipelines.universal/Shaders/Utils/CopyDepthPass.hlsl" diff --git a/com.unity.render-pipelines.universal/Shaders/Utils/CopyDepthPass.hlsl b/com.unity.render-pipelines.universal/Shaders/Utils/CopyDepthPass.hlsl index e2686609b08..b1beca642cf 100644 --- a/com.unity.render-pipelines.universal/Shaders/Utils/CopyDepthPass.hlsl +++ b/com.unity.render-pipelines.universal/Shaders/Utils/CopyDepthPass.hlsl @@ -106,7 +106,11 @@ float SampleDepth(float2 uv) #endif } +#if defined(_OUTPUT_DEPTH) float frag(Varyings input) : SV_Depth +#else +float frag(Varyings input) : SV_Target +#endif { UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input); return SampleDepth(input.uv); diff --git a/com.unity.visualeffectgraph/Shaders/VFXParticleCommon.template b/com.unity.visualeffectgraph/Shaders/VFXParticleCommon.template index 7689e95a914..cfc888e4ef2 100644 --- a/com.unity.visualeffectgraph/Shaders/VFXParticleCommon.template +++ b/com.unity.visualeffectgraph/Shaders/VFXParticleCommon.template @@ -284,7 +284,7 @@ void frag(ps_input i outSelection = float4(_ObjectId, _PassValue, 1.0, 1.0); #elif VFX_PASSDEPTH == VFX_PASSDEPTH_ACTUAL #ifndef WRITE_MSAA_DEPTH - dummy = (float4)0; + dummy = float4(i.VFX_VARYING_POSCS.z, 0,0,0); #endif #elif VFX_PASSDEPTH == VFX_PASSDEPTH_SHADOW dummy = (float4)0;