From abc28100b620aa02e17d3a89f11b7d07ed280a1b Mon Sep 17 00:00:00 2001 From: Julien Ignace Date: Wed, 13 Jan 2021 14:01:39 +0100 Subject: [PATCH 1/6] Removed backplate from rendering of lighting cubemap as it did not really work conceptually and caused artefacts. --- .../Runtime/Sky/HDRISky/HDRISky.shader | 39 ------------------- .../Runtime/Sky/HDRISky/HDRISkyRenderer.cs | 34 +++++++--------- .../Runtime/Sky/SkyManager.cs | 2 - .../Runtime/Sky/SkyRenderer.cs | 13 ++++++- 4 files changed, 27 insertions(+), 61 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISky.shader b/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISky.shader index 6920dd77836..48f79b2a2a3 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISky.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISky.shader @@ -310,11 +310,6 @@ Shader "Hidden/HDRP/Sky/HDRISky" return results; } - float4 FragBakingBackplate(Varyings input) : SV_Target - { - return RenderBackplate(input, 1.0); - } - float4 FragRenderBackplate(Varyings input) : SV_Target { UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input); @@ -338,12 +333,6 @@ Shader "Hidden/HDRP/Sky/HDRISky" return depth; } - float FragBakingBackplateDepth(Varyings input) : SV_Depth - { - UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input); - return GetDepthWithBackplate(input); - } - float4 FragRenderBackplateDepth(Varyings input, out float depth : SV_Depth) : SV_Target0 { UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input); @@ -392,20 +381,6 @@ Shader "Hidden/HDRP/Sky/HDRISky" ENDHLSL } - // HDRI Sky with Backplate - // For cubemap with Backplate - Pass - { - ZWrite Off - ZTest Always - Blend Off - Cull Off - - HLSLPROGRAM - #pragma fragment FragBakingBackplate - ENDHLSL - } - // For fullscreen Sky with Backplate Pass { @@ -419,20 +394,6 @@ Shader "Hidden/HDRP/Sky/HDRISky" ENDHLSL } - // HDRI Sky with Backplate for PreRenderSky (Depth Only Pass) - // DepthOnly For cubemap with Backplate - Pass - { - ZWrite On - ZTest LEqual - Blend Off - Cull Off - - HLSLPROGRAM - #pragma fragment FragBakingBackplateDepth - ENDHLSL - } - // DepthOnly For fullscreen Sky with Backplate Pass { diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISkyRenderer.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISkyRenderer.cs index db4cca4e8b9..67dd376d628 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISkyRenderer.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISkyRenderer.cs @@ -13,10 +13,8 @@ class HDRISkyRenderer : SkyRenderer private static int m_RenderCubemapID = 0; // FragBaking private static int m_RenderFullscreenSkyID = 1; // FragRender - private static int m_RenderCubemapWithBackplateID = 2; // FragBakingBackplate - private static int m_RenderFullscreenSkyWithBackplateID = 3; // FragRenderBackplate - private static int m_RenderDepthOnlyCubemapWithBackplateID = 4; // FragBakingBackplateDepth - private static int m_RenderDepthOnlyFullscreenSkyWithBackplateID = 5; // FragRenderBackplateDepth + private static int m_RenderFullscreenSkyWithBackplateID = 2; // FragRenderBackplate + private static int m_RenderDepthOnlyFullscreenSkyWithBackplateID = 3; // FragRenderBackplateDepth public HDRISkyRenderer() { @@ -92,16 +90,10 @@ public override bool RequiresPreRenderSky(BuiltinSkyParameters builtinParams) return hdriSky.enableBackplate.value; } - public override void PreRenderSky(BuiltinSkyParameters builtinParams, bool renderForCubemap, bool renderSunDisk) + public override void PreRenderSky(BuiltinSkyParameters builtinParams) { var hdriSky = builtinParams.skySettings as HDRISky; - int passID; - if (renderForCubemap) - passID = m_RenderDepthOnlyCubemapWithBackplateID; - else - passID = m_RenderDepthOnlyFullscreenSkyWithBackplateID; - float intensity, phi, backplatePhi; GetParameters(out intensity, out phi, out backplatePhi, builtinParams, hdriSky); @@ -113,7 +105,7 @@ public override void PreRenderSky(BuiltinSkyParameters builtinParams, bool rende m_PropertyBlock.SetMatrix(HDShaderIDs._PixelCoordToViewDirWS, builtinParams.pixelCoordToViewDirMatrix); - CoreUtils.DrawFullScreen(builtinParams.commandBuffer, m_SkyHDRIMaterial, m_PropertyBlock, passID); + CoreUtils.DrawFullScreen(builtinParams.commandBuffer, m_SkyHDRIMaterial, m_PropertyBlock, m_RenderDepthOnlyFullscreenSkyWithBackplateID); } } @@ -123,19 +115,20 @@ public override void RenderSky(BuiltinSkyParameters builtinParams, bool renderFo float intensity, phi, backplatePhi; GetParameters(out intensity, out phi, out backplatePhi, builtinParams, hdriSky); int passID; - if (hdriSky.enableBackplate.value == false) + if (renderForCubemap) { - if (renderForCubemap) - passID = m_RenderCubemapID; - else - passID = m_RenderFullscreenSkyID; + passID = m_RenderCubemapID; } else { - if (renderForCubemap) - passID = m_RenderCubemapWithBackplateID; + if (hdriSky.enableBackplate.value == false) + { + passID = m_RenderFullscreenSkyID; + } else + { passID = m_RenderFullscreenSkyWithBackplateID; + } } if (hdriSky.enableDistortion.value == true) @@ -182,8 +175,11 @@ public override void RenderSky(BuiltinSkyParameters builtinParams, bool renderFo shadowFilter |= unchecked((uint)LightFeatureFlags.Area); m_SkyHDRIMaterial.SetInt(HDShaderIDs._BackplateShadowFilter, unchecked((int)shadowFilter)); + + var cubeProj = Matrix4x4.Perspective(90.0f, 1.0f, 0.01f, 1.0f); // This matrix needs to be updated at the draw call frequency. m_PropertyBlock.SetMatrix(HDShaderIDs._PixelCoordToViewDirWS, builtinParams.pixelCoordToViewDirMatrix); + m_PropertyBlock.SetMatrix("_CubeFaceViewProjection", cubeProj * builtinParams.viewMatrix); CoreUtils.DrawFullScreen(builtinParams.commandBuffer, m_SkyHDRIMaterial, m_PropertyBlock, passID); } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs index d66cca43514..f93a28a3cd4 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs @@ -325,8 +325,6 @@ public void Build(HDRenderPipelineAsset hdAsset, RenderPipelineResources default m_SkyboxBSDFCubemapIntermediate = RTHandles.Alloc(resolution, resolution, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, dimension: TextureDimension.Cube, useMipMap: true, autoGenerateMips: false, filterMode: FilterMode.Trilinear, name: "SkyboxBSDFIntermediate"); m_CubemapScreenSize = new Vector4((float)resolution, (float)resolution, 1.0f / (float)resolution, 1.0f / (float)resolution); - var cubeProj = Matrix4x4.Perspective(90.0f, 1.0f, 0.01f, 1.0f); - for (int i = 0; i < 6; ++i) { var lookAt = Matrix4x4.LookAt(Vector3.zero, CoreUtils.lookAtList[i], CoreUtils.upVectorList[i]); diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyRenderer.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyRenderer.cs index d7592eef990..2e7d3fb760a 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyRenderer.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyRenderer.cs @@ -33,7 +33,18 @@ public abstract class SkyRenderer /// Engine parameters that you can use to render the sky. /// Pass in true if you want to render the sky into a cubemap for lighting. This is useful when the sky renderer needs a different implementation in this case. /// If the sky renderer supports the rendering of a sun disk, it must not render it if this is set to false. - public virtual void PreRenderSky(BuiltinSkyParameters builtinParams, bool renderForCubemap, bool renderSunDisk) {} + [System.Obsolete("Please override PreRenderSky(BuiltinSkyParameters) instead.")] + public virtual void PreRenderSky(BuiltinSkyParameters builtinParams, bool renderForCubemap, bool renderSunDisk) + { + PreRenderSky(builtinParams); + } + + /// + /// Preprocess for rendering the sky. Called before the DepthPrePass operations + /// + /// Engine parameters that you can use to render the sky. + public virtual void PreRenderSky(BuiltinSkyParameters builtinParams) {} + /// /// Whether the PreRenderSky step is required. From d3b2a4fbf470ba709f09bf28538832ec8e5ddbf2 Mon Sep 17 00:00:00 2001 From: Julien Ignace Date: Wed, 13 Jan 2021 14:02:39 +0100 Subject: [PATCH 2/6] Update changelog --- com.unity.render-pipelines.high-definition/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 14f9d78aef5..d9cd68709ee 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -76,6 +76,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Changed the clamping approach for RTR and RTGI (in both perf and quality) to improve visual quality. - Changed the warning message for ray traced area shadows (case 1303410). - Disabled specular occlusion for what we consider medium and larger scale ao > 1.25 with a 25cm falloff interval. +- Removed backplate from rendering of lighting cubemap as it did not really work conceptually and caused artefacts. ## [10.3.0] - 2020-12-01 From 841a31c444019e387ecd26f7086d89a5aee4f353 Mon Sep 17 00:00:00 2001 From: Julien Ignace Date: Wed, 13 Jan 2021 14:08:30 +0100 Subject: [PATCH 3/6] Remove useless code --- .../Runtime/Sky/HDRISky/HDRISkyRenderer.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISkyRenderer.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISkyRenderer.cs index 67dd376d628..809f64f1102 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISkyRenderer.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISkyRenderer.cs @@ -176,10 +176,8 @@ public override void RenderSky(BuiltinSkyParameters builtinParams, bool renderFo m_SkyHDRIMaterial.SetInt(HDShaderIDs._BackplateShadowFilter, unchecked((int)shadowFilter)); - var cubeProj = Matrix4x4.Perspective(90.0f, 1.0f, 0.01f, 1.0f); // This matrix needs to be updated at the draw call frequency. m_PropertyBlock.SetMatrix(HDShaderIDs._PixelCoordToViewDirWS, builtinParams.pixelCoordToViewDirMatrix); - m_PropertyBlock.SetMatrix("_CubeFaceViewProjection", cubeProj * builtinParams.viewMatrix); CoreUtils.DrawFullScreen(builtinParams.commandBuffer, m_SkyHDRIMaterial, m_PropertyBlock, passID); } } From afde3f23b6bf105fa474cb71194b5e66ddf692d5 Mon Sep 17 00:00:00 2001 From: Julien Ignace Date: Wed, 13 Jan 2021 14:22:23 +0100 Subject: [PATCH 4/6] Compilation fix. --- .../Runtime/Sky/SkyManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs index f93a28a3cd4..9be57947a74 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs @@ -960,7 +960,7 @@ public void PreRenderSky(HDCamera hdCamera, Light sunLight, RTHandle colorBuffer } if (preRenderSky) - skyContext.skyRenderer.PreRenderSky(m_BuiltinParameters, false, hdCamera.camera.cameraType != CameraType.Reflection || skyContext.skySettings.includeSunInBaking.value); + skyContext.skyRenderer.PreRenderSky(m_BuiltinParameters); if (skyContext.HasClouds() && skyContext.cloudRenderer.RequiresPreRenderClouds(m_BuiltinParameters)) { From 34525ed5dcf4e3653814b028353031a78477bce1 Mon Sep 17 00:00:00 2001 From: Julien Ignace Date: Mon, 18 Jan 2021 14:50:46 +0100 Subject: [PATCH 5/6] Update doc --- .../Documentation~/Override-HDRI-Sky.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.high-definition/Documentation~/Override-HDRI-Sky.md b/com.unity.render-pipelines.high-definition/Documentation~/Override-HDRI-Sky.md index 2d3683706f1..4c902e85a27 100644 --- a/com.unity.render-pipelines.high-definition/Documentation~/Override-HDRI-Sky.md +++ b/com.unity.render-pipelines.high-definition/Documentation~/Override-HDRI-Sky.md @@ -65,4 +65,4 @@ These properties only appear if you enable [more options](More-Options.md). | -**Shadow Tint** | Specifies the color to tint shadows cast onto the backplate. | | - **Reset Color** | Resets the saved **Shadow Tint** for the shadow. HDRP calculates a new default shadow tint when the HDRI changes. | -**Note**: To use ambient occlusion in the backplate, increase the value of the **Direct Lighting Strength** property on the [Ambient Occlusion](Override-Ambient-Occlusion.md) component override. As the backplate does not have global illumination, it can only get ambient occlusion from direct lighting. \ No newline at end of file +**Note**: To use ambient occlusion in the backplate, increase the value of the **Direct Lighting Strength** property on the [Ambient Occlusion](Override-Ambient-Occlusion.md) component override. As the backplate does not have global illumination, it can only get ambient occlusion from direct lighting. Also, note that for technical reasons, the backplate will never appear in the default sky reflection, only in local reflection probes. \ No newline at end of file From 7c14eb55e57afa050d77dc7b1326a6b637093183 Mon Sep 17 00:00:00 2001 From: sebastienlagarde Date: Mon, 18 Jan 2021 15:07:09 +0100 Subject: [PATCH 6/6] Update Override-HDRI-Sky.md --- .../Documentation~/Override-HDRI-Sky.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.high-definition/Documentation~/Override-HDRI-Sky.md b/com.unity.render-pipelines.high-definition/Documentation~/Override-HDRI-Sky.md index 4c902e85a27..dfe0e97852a 100644 --- a/com.unity.render-pipelines.high-definition/Documentation~/Override-HDRI-Sky.md +++ b/com.unity.render-pipelines.high-definition/Documentation~/Override-HDRI-Sky.md @@ -65,4 +65,6 @@ These properties only appear if you enable [more options](More-Options.md). | -**Shadow Tint** | Specifies the color to tint shadows cast onto the backplate. | | - **Reset Color** | Resets the saved **Shadow Tint** for the shadow. HDRP calculates a new default shadow tint when the HDRI changes. | -**Note**: To use ambient occlusion in the backplate, increase the value of the **Direct Lighting Strength** property on the [Ambient Occlusion](Override-Ambient-Occlusion.md) component override. As the backplate does not have global illumination, it can only get ambient occlusion from direct lighting. Also, note that for technical reasons, the backplate will never appear in the default sky reflection, only in local reflection probes. \ No newline at end of file +**Note**: To use ambient occlusion in the backplate, increase the value of the **Direct Lighting Strength** property on the [Ambient Occlusion](Override-Ambient-Occlusion.md) component override. As the backplate does not have global illumination, it can only get ambient occlusion from direct lighting. + +**Limitation**: The backplate don't affect the Sky lighting (Sky Reflection / Ligthmaps / LightProbes / Ambient Probe). It will not appear with the default sky reflection but only in local reflection probes.