From 576157ede8241f2829ab30eef4b1cf2b49c24012 Mon Sep 17 00:00:00 2001 From: Pavlos Mavridis Date: Wed, 15 Apr 2020 18:35:42 +0200 Subject: [PATCH 1/4] Fix issue with screen_space shadows not enabled with RT off --- .../CHANGELOG.md | 1 + .../Shadow/ScreenSpaceShadowManager.cs | 26 +++++++------------ 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 7199a81536c..9c0880d83c2 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -551,6 +551,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Replaced commands incompatible with async compute in light list build process. - Diffusion Profile and Material references in HDRP materials are now correctly exported to unity packages. Note that the diffusion profile or the material references need to be edited once before this can work properly. - Fixed unneeded cookie texture allocation for cone stop lights. +- Fixed issue with screen-space shadows not enabled properly when RT is disabled (case 1235821) ### Changed - Improve MIP selection for decals on Transparents diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/ScreenSpaceShadowManager.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/ScreenSpaceShadowManager.cs index 8aa98999558..bff4ffa05b7 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/ScreenSpaceShadowManager.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/ScreenSpaceShadowManager.cs @@ -230,27 +230,19 @@ void RenderScreenSpaceShadows(HDCamera hdCamera, CommandBuffer cmd) return; } - if (hdCamera.frameSettings.IsEnabled(FrameSettingsField.RayTracing)) + using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.ScreenSpaceShadows))) { - using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.ScreenSpaceShadows))) - { - // First of all we handle the directional light - RenderDirectionalLightScreenSpaceShadow(cmd, hdCamera); + // First of all we handle the directional light + RenderDirectionalLightScreenSpaceShadow(cmd, hdCamera); - // We handle the other light sources - RenderLightScreenSpaceShadows(hdCamera, cmd); + // We handle the other light sources + RenderLightScreenSpaceShadows(hdCamera, cmd); - // We do render the debug view - EvaluateShadowDebugView(cmd, hdCamera); + // We do render the debug view + EvaluateShadowDebugView(cmd, hdCamera); - // Big the right texture - cmd.SetGlobalTexture(HDShaderIDs._ScreenSpaceShadowsTexture, m_ScreenSpaceShadowTextureArray); - } - } - else - { - // We bind the black texture in this case - BindBlackShadowTexture(cmd); + // Bind the right texture + cmd.SetGlobalTexture(HDShaderIDs._ScreenSpaceShadowsTexture, m_ScreenSpaceShadowTextureArray); } } From 5c28646fa86f449a71551dc1097d731da458b2ef Mon Sep 17 00:00:00 2001 From: Pavlos Mavridis Date: Thu, 16 Apr 2020 11:18:48 +0200 Subject: [PATCH 2/4] Proper fix: only keep directional screen space shadows with RT off --- .../Lighting/Shadow/ScreenSpaceShadowManager.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/ScreenSpaceShadowManager.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/ScreenSpaceShadowManager.cs index bff4ffa05b7..512c8b4918d 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/ScreenSpaceShadowManager.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/ScreenSpaceShadowManager.cs @@ -235,12 +235,14 @@ void RenderScreenSpaceShadows(HDCamera hdCamera, CommandBuffer cmd) // First of all we handle the directional light RenderDirectionalLightScreenSpaceShadow(cmd, hdCamera); - // We handle the other light sources - RenderLightScreenSpaceShadows(hdCamera, cmd); - - // We do render the debug view - EvaluateShadowDebugView(cmd, hdCamera); + if (hdCamera.frameSettings.IsEnabled(FrameSettingsField.RayTracing)) + { + // We handle the other light sources + RenderLightScreenSpaceShadows(hdCamera, cmd); + // We do render the debug view + EvaluateShadowDebugView(cmd, hdCamera); + } // Bind the right texture cmd.SetGlobalTexture(HDShaderIDs._ScreenSpaceShadowsTexture, m_ScreenSpaceShadowTextureArray); } From 2b95ae0092d13a7f2846558dd32c81af7cc23f06 Mon Sep 17 00:00:00 2001 From: Pavlos Mavridis Date: Tue, 21 Apr 2020 13:17:17 +0200 Subject: [PATCH 3/4] Fix shadow debug mode --- .../Shadow/ScreenSpaceShadowManager.cs | 60 +++++++++++-------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/ScreenSpaceShadowManager.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/ScreenSpaceShadowManager.cs index 512c8b4918d..9c2344f07e7 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/ScreenSpaceShadowManager.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/ScreenSpaceShadowManager.cs @@ -239,10 +239,11 @@ void RenderScreenSpaceShadows(HDCamera hdCamera, CommandBuffer cmd) { // We handle the other light sources RenderLightScreenSpaceShadows(hdCamera, cmd); - - // We do render the debug view - EvaluateShadowDebugView(cmd, hdCamera); } + + // We do render the debug view + EvaluateShadowDebugView(cmd, hdCamera); + // Bind the right texture cmd.SetGlobalTexture(HDShaderIDs._ScreenSpaceShadowsTexture, m_ScreenSpaceShadowTextureArray); } @@ -889,38 +890,47 @@ void RenderPunctualScreenSpaceShadow(CommandBuffer cmd, HDCamera hdCamera void EvaluateShadowDebugView(CommandBuffer cmd, HDCamera hdCamera) { - ComputeShader shadowFilter = m_Asset.renderPipelineRayTracingResources.shadowFilterCS; - // If this is the right debug mode and the index we are asking for is in the range HDRenderPipeline hdrp = (RenderPipelineManager.currentPipeline as HDRenderPipeline); if (FullScreenDebugMode.ScreenSpaceShadows == hdrp.m_CurrentDebugDisplaySettings.data.fullScreenDebugMode) { - // Texture dimensions - int texWidth = hdCamera.actualWidth; - int texHeight = hdCamera.actualHeight; + if (m_Asset.renderPipelineRayTracingResources) + { + ComputeShader shadowFilter = m_Asset.renderPipelineRayTracingResources.shadowFilterCS; - // Evaluate the dispatch parameters - int areaTileSize = 8; - int numTilesX = (texWidth + (areaTileSize - 1)) / areaTileSize; - int numTilesY = (texHeight + (areaTileSize - 1)) / areaTileSize; + // Texture dimensions + int texWidth = hdCamera.actualWidth; + int texHeight = hdCamera.actualHeight; - RTHandle intermediateBuffer0 = GetRayTracingBuffer(InternalRayTracingBuffers.RGBA0); + // Evaluate the dispatch parameters + int areaTileSize = 8; + int numTilesX = (texWidth + (areaTileSize - 1)) / areaTileSize; + int numTilesY = (texHeight + (areaTileSize - 1)) / areaTileSize; - // Clear the output texture - CoreUtils.SetRenderTarget(cmd, intermediateBuffer0, clearFlag: ClearFlag.Color); + RTHandle intermediateBuffer0 = GetRayTracingBuffer(InternalRayTracingBuffers.RGBA0); - // If the screen space shadows we are asked to deliver is available output it to the intermediate texture - if (m_ScreenSpaceShadowChannelSlot > hdrp.m_CurrentDebugDisplaySettings.data.screenSpaceShadowIndex) - { - int targetKernel = shadowFilter.FindKernel("WriteShadowTextureDebug"); - cmd.SetComputeIntParam(shadowFilter, HDShaderIDs._DenoisingHistorySlot, (int)hdrp.m_CurrentDebugDisplaySettings.data.screenSpaceShadowIndex); - cmd.SetComputeTextureParam(shadowFilter, targetKernel, HDShaderIDs._ScreenSpaceShadowsTextureRW, m_ScreenSpaceShadowTextureArray); - cmd.SetComputeTextureParam(shadowFilter, targetKernel, HDShaderIDs._DenoiseOutputTextureRW, intermediateBuffer0); - cmd.DispatchCompute(shadowFilter, targetKernel, numTilesX, numTilesY, hdCamera.viewCount); + // Clear the output texture + CoreUtils.SetRenderTarget(cmd, intermediateBuffer0, clearFlag: ClearFlag.Color); + + // If the screen space shadows we are asked to deliver is available output it to the intermediate texture + if (m_ScreenSpaceShadowChannelSlot > hdrp.m_CurrentDebugDisplaySettings.data.screenSpaceShadowIndex) + { + int targetKernel = shadowFilter.FindKernel("WriteShadowTextureDebug"); + cmd.SetComputeIntParam(shadowFilter, HDShaderIDs._DenoisingHistorySlot, (int)hdrp.m_CurrentDebugDisplaySettings.data.screenSpaceShadowIndex); + cmd.SetComputeTextureParam(shadowFilter, targetKernel, HDShaderIDs._ScreenSpaceShadowsTextureRW, m_ScreenSpaceShadowTextureArray); + cmd.SetComputeTextureParam(shadowFilter, targetKernel, HDShaderIDs._DenoiseOutputTextureRW, intermediateBuffer0); + cmd.DispatchCompute(shadowFilter, targetKernel, numTilesX, numTilesY, hdCamera.viewCount); + } + + // Push the full screen debug texture + hdrp.PushFullScreenDebugTexture(hdCamera, cmd, intermediateBuffer0, FullScreenDebugMode.ScreenSpaceShadows); } + else + { + // In this case we have not rendered any screenspace shadows, so push a black texture on the debug display + hdrp.PushFullScreenDebugTexture(hdCamera, cmd, TextureXR.GetBlackTextureArray(), FullScreenDebugMode.ScreenSpaceShadows); - // Push the full screen debug texture - hdrp.PushFullScreenDebugTexture(hdCamera, cmd, intermediateBuffer0, FullScreenDebugMode.ScreenSpaceShadows); + } } } } From 15db9b8ca5cfd7579ba23a47ea47d198a2ee87c4 Mon Sep 17 00:00:00 2001 From: Pavlos Mavridis Date: Tue, 21 Apr 2020 15:39:39 +0200 Subject: [PATCH 4/4] cosmetic changes --- .../Shadow/ScreenSpaceShadowManager.cs | 55 +++++++++---------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/ScreenSpaceShadowManager.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/ScreenSpaceShadowManager.cs index 9c2344f07e7..41cc653dc69 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/ScreenSpaceShadowManager.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/ScreenSpaceShadowManager.cs @@ -894,43 +894,42 @@ void EvaluateShadowDebugView(CommandBuffer cmd, HDCamera hdCamera) HDRenderPipeline hdrp = (RenderPipelineManager.currentPipeline as HDRenderPipeline); if (FullScreenDebugMode.ScreenSpaceShadows == hdrp.m_CurrentDebugDisplaySettings.data.fullScreenDebugMode) { - if (m_Asset.renderPipelineRayTracingResources) + if (!hdrp.rayTracingSupported) { - ComputeShader shadowFilter = m_Asset.renderPipelineRayTracingResources.shadowFilterCS; + // In this case we have not rendered any screenspace shadows, so push a black texture on the debug display + hdrp.PushFullScreenDebugTexture(hdCamera, cmd, TextureXR.GetBlackTextureArray(), FullScreenDebugMode.ScreenSpaceShadows); + return; + } - // Texture dimensions - int texWidth = hdCamera.actualWidth; - int texHeight = hdCamera.actualHeight; + // TODO: move the debug kernel outside of the ray tracing resources + ComputeShader shadowFilter = m_Asset.renderPipelineRayTracingResources.shadowFilterCS; - // Evaluate the dispatch parameters - int areaTileSize = 8; - int numTilesX = (texWidth + (areaTileSize - 1)) / areaTileSize; - int numTilesY = (texHeight + (areaTileSize - 1)) / areaTileSize; + // Texture dimensions + int texWidth = hdCamera.actualWidth; + int texHeight = hdCamera.actualHeight; - RTHandle intermediateBuffer0 = GetRayTracingBuffer(InternalRayTracingBuffers.RGBA0); + // Evaluate the dispatch parameters + int areaTileSize = 8; + int numTilesX = (texWidth + (areaTileSize - 1)) / areaTileSize; + int numTilesY = (texHeight + (areaTileSize - 1)) / areaTileSize; - // Clear the output texture - CoreUtils.SetRenderTarget(cmd, intermediateBuffer0, clearFlag: ClearFlag.Color); + RTHandle intermediateBuffer0 = GetRayTracingBuffer(InternalRayTracingBuffers.RGBA0); - // If the screen space shadows we are asked to deliver is available output it to the intermediate texture - if (m_ScreenSpaceShadowChannelSlot > hdrp.m_CurrentDebugDisplaySettings.data.screenSpaceShadowIndex) - { - int targetKernel = shadowFilter.FindKernel("WriteShadowTextureDebug"); - cmd.SetComputeIntParam(shadowFilter, HDShaderIDs._DenoisingHistorySlot, (int)hdrp.m_CurrentDebugDisplaySettings.data.screenSpaceShadowIndex); - cmd.SetComputeTextureParam(shadowFilter, targetKernel, HDShaderIDs._ScreenSpaceShadowsTextureRW, m_ScreenSpaceShadowTextureArray); - cmd.SetComputeTextureParam(shadowFilter, targetKernel, HDShaderIDs._DenoiseOutputTextureRW, intermediateBuffer0); - cmd.DispatchCompute(shadowFilter, targetKernel, numTilesX, numTilesY, hdCamera.viewCount); - } + // Clear the output texture + CoreUtils.SetRenderTarget(cmd, intermediateBuffer0, clearFlag: ClearFlag.Color); - // Push the full screen debug texture - hdrp.PushFullScreenDebugTexture(hdCamera, cmd, intermediateBuffer0, FullScreenDebugMode.ScreenSpaceShadows); - } - else + // If the screen space shadows we are asked to deliver is available output it to the intermediate texture + if (m_ScreenSpaceShadowChannelSlot > hdrp.m_CurrentDebugDisplaySettings.data.screenSpaceShadowIndex) { - // In this case we have not rendered any screenspace shadows, so push a black texture on the debug display - hdrp.PushFullScreenDebugTexture(hdCamera, cmd, TextureXR.GetBlackTextureArray(), FullScreenDebugMode.ScreenSpaceShadows); - + int targetKernel = shadowFilter.FindKernel("WriteShadowTextureDebug"); + cmd.SetComputeIntParam(shadowFilter, HDShaderIDs._DenoisingHistorySlot, (int)hdrp.m_CurrentDebugDisplaySettings.data.screenSpaceShadowIndex); + cmd.SetComputeTextureParam(shadowFilter, targetKernel, HDShaderIDs._ScreenSpaceShadowsTextureRW, m_ScreenSpaceShadowTextureArray); + cmd.SetComputeTextureParam(shadowFilter, targetKernel, HDShaderIDs._DenoiseOutputTextureRW, intermediateBuffer0); + cmd.DispatchCompute(shadowFilter, targetKernel, numTilesX, numTilesY, hdCamera.viewCount); } + + // Push the full screen debug texture + hdrp.PushFullScreenDebugTexture(hdCamera, cmd, intermediateBuffer0, FullScreenDebugMode.ScreenSpaceShadows); } } }