From 997cfabcb91c390a0387323816edc1b3bdb6b043 Mon Sep 17 00:00:00 2001 From: Anis Date: Fri, 15 May 2020 13:16:32 +0200 Subject: [PATCH] SSGI Implementation --- .../HDRenderPipelineAssetDeferred.asset | 3 +- .../Common/HDRenderPipelineAssetForward.asset | 13 + .../GlobalIlluminationDenoised1.asset | 37 ++ .../GlobalIlluminationDenoised1Half.asset | 37 ++ .../GlobalIlluminationDenoised2.asset | 37 ++ .../GlobalIlluminationFog.asset | 44 +++ .../GlobalIlluminationPerfFull.asset | 37 ++ .../GlobalIlluminationPerfHalf.asset | 37 ++ .../GlobalIlluminationQuality.asset | 37 ++ .../ProjectSettings/EditorBuildSettings.asset | 3 - .../CHANGELOG.md | 1 + .../RenderPipeline/HDRenderPipelineUI.Skin.cs | 1 + .../RenderPipeline/HDRenderPipelineUI.cs | 1 + .../Raytracing/GlobalIlluminationEditor.cs | 74 +++- .../SerializedRenderPipelineSettings.cs | 2 + .../Runtime/Debug/DebugDisplay.cs | 6 +- .../Runtime/Debug/DebugDisplay.cs.hlsl | 2 +- .../Runtime/Debug/DebugFullScreen.shader | 2 +- .../Runtime/Lighting/GlobalIllumination.cs | 110 +++++- .../Runtime/Lighting/LightLoop/LightLoop.cs | 5 + .../Lighting/LightLoop/LightLoop.cs.hlsl | 3 + .../Runtime/Lighting/LightLoop/LightLoop.hlsl | 6 + .../LightLoop/ShaderVariablesLightLoop.hlsl | 7 +- .../BilateralUpsample.compute | 126 +++++++ .../BilateralUpsample.compute.meta | 8 + .../ScreenSpaceLighting/SSGIDenoiser.compute | 268 +++++++++++++ .../SSGIDenoiser.compute.meta | 8 + .../ScreenSpaceLighting/SSGIDenoiser.cs | 168 +++++++++ .../ScreenSpaceLighting/SSGIDenoiser.cs.meta | 11 + .../ScreenSpaceGlobalIllumination.compute | 353 ++++++++++++++++++ ...ScreenSpaceGlobalIllumination.compute.meta | 8 + .../ScreenSpaceGlobalIllumination.cs | 209 +++++++++++ .../ScreenSpaceGlobalIllumination.cs.meta | 11 + .../Runtime/Material/BuiltinUtilities.hlsl | 4 +- .../Runtime/Material/Lit/Lit.hlsl | 1 + .../Runtime/Material/Unlit/Unlit.shader | 2 + .../Camera/HDCameraFrameHistoryType.cs | 2 + .../GlobalLightingQualitySettings.cs | 39 ++ .../Runtime/RenderPipeline/HDProfileId.cs | 1 + .../RenderPipeline/HDRenderPipeline.cs | 50 ++- .../RenderPipeline/HDStringConstants.cs | 17 +- .../Raytracing/HDRaytracingIndirectDiffuse.cs | 62 ++- .../Raytracing/HDRaytracingManager.cs | 249 ++++++++---- .../RenderPipeline/RenderPipelineResources.cs | 9 + .../RenderPipeline/Settings/FrameSettings.cs | 8 +- .../Settings/RenderPipelineSettings.cs | 2 + .../HDRenderPipelineResources.asset | 218 +++++++---- .../CoherentNoise/RankingTile1SPP.png.meta | 31 +- .../CoherentNoise/ScramblingTile1SPP.png.meta | 31 +- .../ShaderLibrary/ShaderVariablesGlobal.cs | 2 +- .../ShaderVariablesGlobal.cs.hlsl | 2 +- 51 files changed, 2163 insertions(+), 242 deletions(-) create mode 100644 com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/BilateralUpsample.compute create mode 100644 com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/BilateralUpsample.compute.meta create mode 100644 com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/SSGIDenoiser.compute create mode 100644 com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/SSGIDenoiser.compute.meta create mode 100644 com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/SSGIDenoiser.cs create mode 100644 com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/SSGIDenoiser.cs.meta create mode 100644 com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/ScreenSpaceGlobalIllumination.compute create mode 100644 com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/ScreenSpaceGlobalIllumination.compute.meta create mode 100644 com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/ScreenSpaceGlobalIllumination.cs create mode 100644 com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/ScreenSpaceGlobalIllumination.cs.meta diff --git a/TestProjects/HDRP_DXR_Tests/Assets/Common/HDRenderPipelineAssetDeferred.asset b/TestProjects/HDRP_DXR_Tests/Assets/Common/HDRenderPipelineAssetDeferred.asset index d5fdfcda5da..f8694bf7b8e 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/Common/HDRenderPipelineAssetDeferred.asset +++ b/TestProjects/HDRP_DXR_Tests/Assets/Common/HDRenderPipelineAssetDeferred.asset @@ -159,7 +159,7 @@ MonoBehaviour: m_RenderingPathDefaultCameraFrameSettings: bitDatas: data1: 136268574097245 - data2: 4539628426469769216 + data2: 4539628428617252864 lodBias: 1 lodBiasMode: 0 lodBiasQualityLevel: 0 @@ -203,6 +203,7 @@ MonoBehaviour: supportSSR: 1 supportSSRTransparent: 1 supportSSAO: 1 + supportSSGI: 1 supportSubsurfaceScattering: 1 sssSampleBudget: m_Values: 140000002800000050000000 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/Common/HDRenderPipelineAssetForward.asset b/TestProjects/HDRP_DXR_Tests/Assets/Common/HDRenderPipelineAssetForward.asset index c6538f8cd5e..c79de898141 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/Common/HDRenderPipelineAssetForward.asset +++ b/TestProjects/HDRP_DXR_Tests/Assets/Common/HDRenderPipelineAssetForward.asset @@ -202,6 +202,7 @@ MonoBehaviour: supportSSR: 1 supportSSRTransparent: 0 supportSSAO: 1 + supportSSGI: 1 supportSubsurfaceScattering: 1 sssSampleBudget: m_Values: 140000002800000050000000 @@ -359,6 +360,18 @@ MonoBehaviour: AODirectionCount: 010000000200000004000000 ContactShadowSampleCount: 060000000a00000010000000 SSRMaxRaySteps: 100000002000000040000000 + SSGIRaySteps: 100000002000000040000000 + SSGIResolution: 000101 + SSGIRadius: + - 2 + - 3 + - 10 + SSGIFullResolution: 000101 + SSGIClampValue: + - 2 + - 2 + - 3 + SSGIFilterRadius: 020000000300000004000000 allowShaderVariantStripping: 1 enableSRPBatcher: 1 shaderVariantLogLevel: 0 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/Scenes/GlobalIlluminationData/GlobalIlluminationDenoised1.asset b/TestProjects/HDRP_DXR_Tests/Assets/Scenes/GlobalIlluminationData/GlobalIlluminationDenoised1.asset index cc0f4fcdb69..bf3d9cf48c6 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/Scenes/GlobalIlluminationData/GlobalIlluminationDenoised1.asset +++ b/TestProjects/HDRP_DXR_Tests/Assets/Scenes/GlobalIlluminationData/GlobalIlluminationDenoised1.asset @@ -20,6 +20,9 @@ MonoBehaviour: skyAmbientMode: m_OverrideState: 0 m_Value: 0 + fogType: + m_OverrideState: 0 + m_Value: 0 --- !u!114 &-602189600455701405 MonoBehaviour: m_ObjectHideFlags: 3 @@ -151,6 +154,40 @@ MonoBehaviour: m_EditorClassIdentifier: active: 1 m_AdvancedMode: 0 + quality: + m_OverrideState: 0 + m_Value: 1 + enable: + m_OverrideState: 1 + m_Value: 1 + depthBufferThickness: + m_OverrideState: 0 + m_Value: 0.01 + min: 0 + max: 1 + m_RaySteps: + m_OverrideState: 0 + m_Value: 24 + min: 16 + max: 128 + m_MaximalRadius: + m_OverrideState: 0 + m_Value: 2 + min: 0.01 + max: 50 + m_FullResolutionSS: + m_OverrideState: 0 + m_Value: 1 + m_ClampValueSS: + m_OverrideState: 0 + m_Value: 2 + min: 0.01 + max: 10 + m_FilterRadius: + m_OverrideState: 0 + m_Value: 2 + min: 2 + max: 4 rayTracing: m_OverrideState: 1 m_Value: 1 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/Scenes/GlobalIlluminationData/GlobalIlluminationDenoised1Half.asset b/TestProjects/HDRP_DXR_Tests/Assets/Scenes/GlobalIlluminationData/GlobalIlluminationDenoised1Half.asset index def64aa4b3a..90a3803ac3d 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/Scenes/GlobalIlluminationData/GlobalIlluminationDenoised1Half.asset +++ b/TestProjects/HDRP_DXR_Tests/Assets/Scenes/GlobalIlluminationData/GlobalIlluminationDenoised1Half.asset @@ -20,6 +20,9 @@ MonoBehaviour: skyAmbientMode: m_OverrideState: 0 m_Value: 0 + fogType: + m_OverrideState: 0 + m_Value: 0 --- !u!114 &-602189600455701405 MonoBehaviour: m_ObjectHideFlags: 3 @@ -151,6 +154,40 @@ MonoBehaviour: m_EditorClassIdentifier: active: 1 m_AdvancedMode: 0 + quality: + m_OverrideState: 0 + m_Value: 1 + enable: + m_OverrideState: 1 + m_Value: 1 + depthBufferThickness: + m_OverrideState: 0 + m_Value: 0.01 + min: 0 + max: 1 + m_RaySteps: + m_OverrideState: 0 + m_Value: 24 + min: 16 + max: 128 + m_MaximalRadius: + m_OverrideState: 0 + m_Value: 2 + min: 0.01 + max: 50 + m_FullResolutionSS: + m_OverrideState: 0 + m_Value: 1 + m_ClampValueSS: + m_OverrideState: 0 + m_Value: 2 + min: 0.01 + max: 10 + m_FilterRadius: + m_OverrideState: 0 + m_Value: 2 + min: 2 + max: 4 rayTracing: m_OverrideState: 1 m_Value: 1 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/Scenes/GlobalIlluminationData/GlobalIlluminationDenoised2.asset b/TestProjects/HDRP_DXR_Tests/Assets/Scenes/GlobalIlluminationData/GlobalIlluminationDenoised2.asset index ae36fe3a1ad..591ccfbca3c 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/Scenes/GlobalIlluminationData/GlobalIlluminationDenoised2.asset +++ b/TestProjects/HDRP_DXR_Tests/Assets/Scenes/GlobalIlluminationData/GlobalIlluminationDenoised2.asset @@ -20,6 +20,9 @@ MonoBehaviour: skyAmbientMode: m_OverrideState: 0 m_Value: 0 + fogType: + m_OverrideState: 0 + m_Value: 0 --- !u!114 &-602189600455701405 MonoBehaviour: m_ObjectHideFlags: 3 @@ -151,6 +154,40 @@ MonoBehaviour: m_EditorClassIdentifier: active: 1 m_AdvancedMode: 0 + quality: + m_OverrideState: 0 + m_Value: 1 + enable: + m_OverrideState: 1 + m_Value: 1 + depthBufferThickness: + m_OverrideState: 0 + m_Value: 0.01 + min: 0 + max: 1 + m_RaySteps: + m_OverrideState: 0 + m_Value: 24 + min: 16 + max: 128 + m_MaximalRadius: + m_OverrideState: 0 + m_Value: 2 + min: 0.01 + max: 50 + m_FullResolutionSS: + m_OverrideState: 0 + m_Value: 1 + m_ClampValueSS: + m_OverrideState: 0 + m_Value: 2 + min: 0.01 + max: 10 + m_FilterRadius: + m_OverrideState: 0 + m_Value: 2 + min: 2 + max: 4 rayTracing: m_OverrideState: 1 m_Value: 1 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/Scenes/GlobalIlluminationData/GlobalIlluminationFog.asset b/TestProjects/HDRP_DXR_Tests/Assets/Scenes/GlobalIlluminationData/GlobalIlluminationFog.asset index d816fd9a279..009a1c7443b 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/Scenes/GlobalIlluminationData/GlobalIlluminationFog.asset +++ b/TestProjects/HDRP_DXR_Tests/Assets/Scenes/GlobalIlluminationData/GlobalIlluminationFog.asset @@ -87,6 +87,16 @@ MonoBehaviour: m_Value: 0.75 min: 0 max: 1 + screenResolutionPercentage: + m_OverrideState: 0 + m_Value: 12.5 + min: 6.25 + max: 100 + volumeSliceCount: + m_OverrideState: 0 + m_Value: 64 + min: 1 + max: 1024 filter: m_OverrideState: 0 m_Value: 0 @@ -245,6 +255,40 @@ MonoBehaviour: m_EditorClassIdentifier: active: 1 m_AdvancedMode: 0 + quality: + m_OverrideState: 0 + m_Value: 1 + enable: + m_OverrideState: 1 + m_Value: 1 + depthBufferThickness: + m_OverrideState: 0 + m_Value: 0.01 + min: 0 + max: 1 + m_RaySteps: + m_OverrideState: 0 + m_Value: 24 + min: 16 + max: 128 + m_MaximalRadius: + m_OverrideState: 0 + m_Value: 2 + min: 0.01 + max: 50 + m_FullResolutionSS: + m_OverrideState: 0 + m_Value: 1 + m_ClampValueSS: + m_OverrideState: 0 + m_Value: 2 + min: 0.01 + max: 10 + m_FilterRadius: + m_OverrideState: 0 + m_Value: 2 + min: 2 + max: 8 rayTracing: m_OverrideState: 1 m_Value: 1 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/Scenes/GlobalIlluminationData/GlobalIlluminationPerfFull.asset b/TestProjects/HDRP_DXR_Tests/Assets/Scenes/GlobalIlluminationData/GlobalIlluminationPerfFull.asset index 6fe5c8d287f..19475acf80a 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/Scenes/GlobalIlluminationData/GlobalIlluminationPerfFull.asset +++ b/TestProjects/HDRP_DXR_Tests/Assets/Scenes/GlobalIlluminationData/GlobalIlluminationPerfFull.asset @@ -20,6 +20,9 @@ MonoBehaviour: skyAmbientMode: m_OverrideState: 0 m_Value: 0 + fogType: + m_OverrideState: 0 + m_Value: 0 --- !u!114 &-602189600455701405 MonoBehaviour: m_ObjectHideFlags: 3 @@ -151,6 +154,40 @@ MonoBehaviour: m_EditorClassIdentifier: active: 1 m_AdvancedMode: 0 + quality: + m_OverrideState: 0 + m_Value: 1 + enable: + m_OverrideState: 1 + m_Value: 1 + depthBufferThickness: + m_OverrideState: 0 + m_Value: 0.01 + min: 0 + max: 1 + m_RaySteps: + m_OverrideState: 0 + m_Value: 24 + min: 16 + max: 128 + m_MaximalRadius: + m_OverrideState: 0 + m_Value: 2 + min: 0.01 + max: 50 + m_FullResolutionSS: + m_OverrideState: 0 + m_Value: 1 + m_ClampValueSS: + m_OverrideState: 0 + m_Value: 2 + min: 0.01 + max: 10 + m_FilterRadius: + m_OverrideState: 0 + m_Value: 2 + min: 2 + max: 4 rayTracing: m_OverrideState: 1 m_Value: 1 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/Scenes/GlobalIlluminationData/GlobalIlluminationPerfHalf.asset b/TestProjects/HDRP_DXR_Tests/Assets/Scenes/GlobalIlluminationData/GlobalIlluminationPerfHalf.asset index da4ef52ce17..5b651afb450 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/Scenes/GlobalIlluminationData/GlobalIlluminationPerfHalf.asset +++ b/TestProjects/HDRP_DXR_Tests/Assets/Scenes/GlobalIlluminationData/GlobalIlluminationPerfHalf.asset @@ -20,6 +20,9 @@ MonoBehaviour: skyAmbientMode: m_OverrideState: 0 m_Value: 0 + fogType: + m_OverrideState: 0 + m_Value: 0 --- !u!114 &-602189600455701405 MonoBehaviour: m_ObjectHideFlags: 3 @@ -151,6 +154,40 @@ MonoBehaviour: m_EditorClassIdentifier: active: 1 m_AdvancedMode: 0 + quality: + m_OverrideState: 0 + m_Value: 1 + enable: + m_OverrideState: 1 + m_Value: 1 + depthBufferThickness: + m_OverrideState: 0 + m_Value: 0.01 + min: 0 + max: 1 + m_RaySteps: + m_OverrideState: 0 + m_Value: 24 + min: 16 + max: 128 + m_MaximalRadius: + m_OverrideState: 0 + m_Value: 2 + min: 0.01 + max: 50 + m_FullResolutionSS: + m_OverrideState: 0 + m_Value: 1 + m_ClampValueSS: + m_OverrideState: 0 + m_Value: 2 + min: 0.01 + max: 10 + m_FilterRadius: + m_OverrideState: 0 + m_Value: 2 + min: 2 + max: 4 rayTracing: m_OverrideState: 1 m_Value: 1 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/Scenes/GlobalIlluminationData/GlobalIlluminationQuality.asset b/TestProjects/HDRP_DXR_Tests/Assets/Scenes/GlobalIlluminationData/GlobalIlluminationQuality.asset index 3c91ca601aa..7be7267a0a4 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/Scenes/GlobalIlluminationData/GlobalIlluminationQuality.asset +++ b/TestProjects/HDRP_DXR_Tests/Assets/Scenes/GlobalIlluminationData/GlobalIlluminationQuality.asset @@ -20,6 +20,9 @@ MonoBehaviour: skyAmbientMode: m_OverrideState: 0 m_Value: 0 + fogType: + m_OverrideState: 0 + m_Value: 0 --- !u!114 &-602189600455701405 MonoBehaviour: m_ObjectHideFlags: 3 @@ -151,6 +154,40 @@ MonoBehaviour: m_EditorClassIdentifier: active: 1 m_AdvancedMode: 0 + quality: + m_OverrideState: 0 + m_Value: 1 + enable: + m_OverrideState: 1 + m_Value: 1 + depthBufferThickness: + m_OverrideState: 0 + m_Value: 0.01 + min: 0 + max: 1 + m_RaySteps: + m_OverrideState: 0 + m_Value: 24 + min: 16 + max: 128 + m_MaximalRadius: + m_OverrideState: 0 + m_Value: 2 + min: 0.01 + max: 50 + m_FullResolutionSS: + m_OverrideState: 0 + m_Value: 1 + m_ClampValueSS: + m_OverrideState: 0 + m_Value: 2 + min: 0.01 + max: 10 + m_FilterRadius: + m_OverrideState: 0 + m_Value: 2 + min: 2 + max: 4 rayTracing: m_OverrideState: 1 m_Value: 1 diff --git a/TestProjects/HDRP_DXR_Tests/ProjectSettings/EditorBuildSettings.asset b/TestProjects/HDRP_DXR_Tests/ProjectSettings/EditorBuildSettings.asset index 1dde0f0ac64..1271081ffb9 100644 --- a/TestProjects/HDRP_DXR_Tests/ProjectSettings/EditorBuildSettings.asset +++ b/TestProjects/HDRP_DXR_Tests/ProjectSettings/EditorBuildSettings.asset @@ -155,9 +155,6 @@ EditorBuildSettings: - enabled: 1 path: Assets/Scenes/3002_AreaShadowsForward_Denoiser.unity guid: 22e35301dfb0fdf468a423c8a8390b13 - - enabled: 0 - path: Assets/Scenes/5001_PathTracing.unity - guid: 3666dc8006745714997c368c4375f316 - enabled: 1 path: Assets/Scenes/5002_PathTracing_GI.unity guid: 0ab35aa39f371ab4c8d53b46c225d0a5 diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 1d66f8ffd54..9e148c03b78 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -125,6 +125,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Added a flow map parameter to HDRI Sky - Implemented ray traced reflections for transparent objects. - Add a new parameter to control reflections in recursive rendering. +- Added an initial version of SSGI. ### Fixed - Fix when rescale probe all direction below zero (1219246) diff --git a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineUI.Skin.cs b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineUI.Skin.cs index 9b690087eca..031d4d40558 100644 --- a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineUI.Skin.cs +++ b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineUI.Skin.cs @@ -82,6 +82,7 @@ public class GeneralSection public static readonly GUIContent supportSSRContent = EditorGUIUtility.TrTextContent("Screen Space Reflection", "When enabled, HDRP allocates memory for processing screen space reflection (SSR). This allows you to use SSR in your Unity Project."); public static readonly GUIContent supportSSRTransparentContent = EditorGUIUtility.TrTextContent("Transparent Screen Space Reflection", "When enabled, HDRP executes additional steps to achieve screen space reflection (SSR) on transparent objects."); public static readonly GUIContent supportSSAOContent = EditorGUIUtility.TrTextContent("Screen Space Ambient Occlusion", "When enabled, HDRP allocates memory for processing screen space ambient occlusion (SSAO). This allows you to use SSAO in your Unity Project."); + public static readonly GUIContent supportSSGIContent = EditorGUIUtility.TrTextContent("Screen Space Global Illumination", "When enabled, HDRP allocates memory for processing screen space global illumination (SSGI). This allows you to use SSGI in your Unity Project."); public static readonly GUIContent supportedSSSContent = EditorGUIUtility.TrTextContent("Subsurface Scattering", "When enabled, HDRP allocates memory for processing subsurface scattering (SSS). This allows you to use SSS in your Unity Project."); public static readonly GUIContent sssSampleBudget = EditorGUIUtility.TrTextContent("Sample Budget", "Maximum number of samples the Subsurface Scattering algorithm is allowed to take."); public static readonly GUIContent supportVolumetricContent = EditorGUIUtility.TrTextContent("Volumetrics", "When enabled, HDRP allocates Shader variants and memory for volumetric effects. This allows you to use volumetric lighting and fog in your Unity Project."); diff --git a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineUI.cs b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineUI.cs index 860e10d0bcc..45b8829dc90 100644 --- a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineUI.cs +++ b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineUI.cs @@ -857,6 +857,7 @@ static void Drawer_SectionRenderingUnsorted(SerializedHDRenderPipelineAsset seri static void Drawer_SectionLightingUnsorted(SerializedHDRenderPipelineAsset serialized, Editor owner) { EditorGUILayout.PropertyField(serialized.renderPipelineSettings.supportSSAO, Styles.supportSSAOContent); + EditorGUILayout.PropertyField(serialized.renderPipelineSettings.supportSSGI, Styles.supportSSGIContent); EditorGUILayout.PropertyField(serialized.renderPipelineSettings.supportVolumetrics, Styles.supportVolumetricContent); diff --git a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Raytracing/GlobalIlluminationEditor.cs b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Raytracing/GlobalIlluminationEditor.cs index 0c739f690d0..7a1981a2f8d 100644 --- a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Raytracing/GlobalIlluminationEditor.cs +++ b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Raytracing/GlobalIlluminationEditor.cs @@ -1,15 +1,28 @@ -using UnityEditor.Rendering; -using UnityEngine.Rendering.HighDefinition; +using UnityEngine; using UnityEngine.Rendering; +using UnityEngine.Rendering.HighDefinition; + namespace UnityEditor.Rendering.HighDefinition { [CanEditMultipleObjects] [VolumeComponentEditor(typeof(GlobalIllumination))] - class GlobalIlluminatorEditor : VolumeComponentEditor + class GlobalIlluminatorEditor : VolumeComponentWithQualityEditor { - SerializedDataParameter m_LayerMask; + // Shared rasterization / ray tracing parameter + SerializedDataParameter m_Enable; + + // Screen space global illumination parameters + SerializedDataParameter m_FullResolutionSS; + SerializedDataParameter m_DepthBufferThickness; + SerializedDataParameter m_RaySteps; + SerializedDataParameter m_MaximalRadius; + SerializedDataParameter m_ClampValueSS; + SerializedDataParameter m_FilterRadius; + + // Ray tracing generic attributes SerializedDataParameter m_RayTracing; + SerializedDataParameter m_LayerMask; SerializedDataParameter m_RayLength; SerializedDataParameter m_ClampValue; SerializedDataParameter m_Mode; @@ -29,12 +42,27 @@ class GlobalIlluminatorEditor : VolumeComponentEditor SerializedDataParameter m_SecondDenoiserPass; SerializedDataParameter m_SecondDenoiserRadius; + public override bool hasAdvancedMode => true; + public override void OnEnable() { + base.OnEnable(); + var o = new PropertyFetcher(serializedObject); - m_LayerMask = Unpack(o.Find(x => x.layerMask)); + m_Enable = Unpack(o.Find(x => x.enable)); + + // SSGI Parameters + m_FullResolutionSS = Unpack(o.Find(x => x.fullResolutionSS)); + m_DepthBufferThickness = Unpack(o.Find(x => x.depthBufferThickness)); + m_RaySteps = Unpack(o.Find(x => x.raySteps)); + m_MaximalRadius = Unpack(o.Find(x => x.maximalRadius)); + m_ClampValueSS = Unpack(o.Find(x => x.clampValueSS)); + m_FilterRadius = Unpack(o.Find(x => x.filterRadius)); + + // Ray Tracing shared parameters m_RayTracing = Unpack(o.Find(x => x.rayTracing)); + m_LayerMask = Unpack(o.Find(x => x.layerMask)); m_RayLength = Unpack(o.Find(x => x.rayLength)); m_ClampValue = Unpack(o.Find(x => x.clampValue)); m_Mode = Unpack(o.Find(x => x.mode)); @@ -57,26 +85,35 @@ public override void OnEnable() public override void OnInspectorGUI() { + HDRenderPipelineAsset currentAsset = HDRenderPipeline.currentAsset; - if (!currentAsset?.currentPlatformRenderPipelineSettings.supportRayTracing ?? false) + if (!currentAsset?.currentPlatformRenderPipelineSettings.supportSSGI ?? false) { EditorGUILayout.Space(); - EditorGUILayout.HelpBox("The current HDRP Asset does not support Ray Tracing.", MessageType.Error, wide: true); + EditorGUILayout.HelpBox("The current HDRP Asset does not support Screen Space Global illumination.", MessageType.Error, wide: true); return; } + PropertyField(m_Enable); + // If ray tracing is supported display the content of the volume component if (HDRenderPipeline.pipelineSupportsRayTracing) { PropertyField(m_RayTracing); + } + // Flag to track if the ray tracing parameters were displayed + bool rayTracingSettingsDisplayed = false; + + EditorGUI.indentLevel++; + if (HDRenderPipeline.pipelineSupportsRayTracing) + { if (m_RayTracing.overrideState.boolValue && m_RayTracing.value.boolValue) { - EditorGUI.indentLevel++; + rayTracingSettingsDisplayed = true; PropertyField(m_LayerMask); PropertyField(m_RayLength); PropertyField(m_ClampValue); - if (currentAsset.currentPlatformRenderPipelineSettings.supportedRayTracingMode == RenderPipelineSettings.SupportedRayTracingMode.Both) { PropertyField(m_Mode); @@ -118,9 +155,26 @@ public override void OnInspectorGUI() PropertyField(m_SecondDenoiserRadius); EditorGUI.indentLevel--; } - EditorGUI.indentLevel--; } } + + // If we dit not display the ray tracing parameter, we display the ssgi ones + if (!rayTracingSettingsDisplayed) + { + base.OnInspectorGUI(); // Quality Setting + EditorGUI.indentLevel++; + GUI.enabled = useCustomValue; + PropertyField(m_FullResolutionSS, EditorGUIUtility.TrTextContent("Full Resolution", "Enables full resolution mode.")); + PropertyField(m_RaySteps); + PropertyField(m_MaximalRadius); + PropertyField(m_ClampValueSS, EditorGUIUtility.TrTextContent("Clamp Value", "Clamps the exposed intensity.")); + PropertyField(m_FilterRadius); + GUI.enabled = true; + EditorGUI.indentLevel--; + PropertyField(m_DepthBufferThickness); + } + + EditorGUI.indentLevel--; } } } diff --git a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Settings/SerializedRenderPipelineSettings.cs b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Settings/SerializedRenderPipelineSettings.cs index e5cef881cb6..1910f5b14eb 100644 --- a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Settings/SerializedRenderPipelineSettings.cs +++ b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Settings/SerializedRenderPipelineSettings.cs @@ -22,6 +22,7 @@ class SerializedRenderPipelineSettings public SerializedProperty supportSSR; public SerializedProperty supportSSRTransparent; public SerializedProperty supportSSAO; + public SerializedProperty supportSSGI; public SerializedProperty supportSubsurfaceScattering; public SerializedScalableSetting sssSampleBudget; [FormerlySerializedAs("supportVolumetric")] @@ -84,6 +85,7 @@ public SerializedRenderPipelineSettings(SerializedProperty root) supportSSR = root.Find((RenderPipelineSettings s) => s.supportSSR); supportSSRTransparent = root.Find((RenderPipelineSettings s) => s.supportSSRTransparent); supportSSAO = root.Find((RenderPipelineSettings s) => s.supportSSAO); + supportSSGI = root.Find((RenderPipelineSettings s) => s.supportSSGI); supportSubsurfaceScattering = root.Find((RenderPipelineSettings s) => s.supportSubsurfaceScattering); sssSampleBudget = new SerializedScalableSetting(root.Find((RenderPipelineSettings s) => s.sssSampleBudget)); supportVolumetrics = root.Find((RenderPipelineSettings s) => s.supportVolumetrics); diff --git a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs index 7a3e7461d07..cc057ec6d07 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs @@ -77,8 +77,8 @@ public enum FullScreenDebugMode // Raytracing Only /// Display ray tracing light cluster. LightCluster, - /// Display ray tracing global illumination. - RayTracedGlobalIllumination, + /// Display screen space global illumination. + ScreenSpaceGlobalIllumination, /// Display recursive ray tracing. RecursiveRayTracing, /// Display ray-traced sub-surface scattering. @@ -1606,7 +1606,7 @@ internal bool DebugNeedsExposure() debugLighting == DebugLightingMode.DiffuseLighting || debugLighting == DebugLightingMode.SpecularLighting || debugLighting == DebugLightingMode.VisualizeCascade) || (data.lightingDebugSettings.overrideAlbedo || data.lightingDebugSettings.overrideNormal || data.lightingDebugSettings.overrideSmoothness || data.lightingDebugSettings.overrideSpecularColor || data.lightingDebugSettings.overrideEmissiveColor || data.lightingDebugSettings.overrideAmbientOcclusion) || (debugGBuffer == DebugViewGbuffer.BakeDiffuseLightingWithAlbedoPlusEmissive) || (data.lightingDebugSettings.debugLightFilterMode != DebugLightFilterMode.None) || - (data.fullScreenDebugMode == FullScreenDebugMode.PreRefractionColorPyramid || data.fullScreenDebugMode == FullScreenDebugMode.FinalColorPyramid || data.fullScreenDebugMode == FullScreenDebugMode.ScreenSpaceReflections || data.fullScreenDebugMode == FullScreenDebugMode.LightCluster || data.fullScreenDebugMode == FullScreenDebugMode.ScreenSpaceShadows || data.fullScreenDebugMode == FullScreenDebugMode.NanTracker || data.fullScreenDebugMode == FullScreenDebugMode.ColorLog) || data.fullScreenDebugMode == FullScreenDebugMode.RayTracedGlobalIllumination || + (data.fullScreenDebugMode == FullScreenDebugMode.PreRefractionColorPyramid || data.fullScreenDebugMode == FullScreenDebugMode.FinalColorPyramid || data.fullScreenDebugMode == FullScreenDebugMode.ScreenSpaceReflections || data.fullScreenDebugMode == FullScreenDebugMode.LightCluster || data.fullScreenDebugMode == FullScreenDebugMode.ScreenSpaceShadows || data.fullScreenDebugMode == FullScreenDebugMode.NanTracker || data.fullScreenDebugMode == FullScreenDebugMode.ColorLog) || data.fullScreenDebugMode == FullScreenDebugMode.ScreenSpaceGlobalIllumination || (debugLighting == DebugLightingMode.ProbeVolume || debugProbeVolume == ProbeVolumeDebugMode.VisualizeAtlas); } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs.hlsl index f619aa2f7ce..e88e3525524 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs.hlsl @@ -19,7 +19,7 @@ #define FULLSCREENDEBUGMODE_DEPTH_PYRAMID (9) #define FULLSCREENDEBUGMODE_FINAL_COLOR_PYRAMID (10) #define FULLSCREENDEBUGMODE_LIGHT_CLUSTER (11) -#define FULLSCREENDEBUGMODE_RAY_TRACED_GLOBAL_ILLUMINATION (12) +#define FULLSCREENDEBUGMODE_SCREEN_SPACE_GLOBAL_ILLUMINATION (12) #define FULLSCREENDEBUGMODE_RECURSIVE_RAY_TRACING (13) #define FULLSCREENDEBUGMODE_RAY_TRACED_SUB_SURFACE (14) #define FULLSCREENDEBUGMODE_MAX_LIGHTING_FULL_SCREEN_DEBUG (15) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugFullScreen.shader b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugFullScreen.shader index 7d16243a47c..47598b7c9ca 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugFullScreen.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugFullScreen.shader @@ -165,7 +165,7 @@ Shader "Hidden/HDRP/DebugFullScreen" float4 color = SAMPLE_TEXTURE2D_X(_DebugFullScreenTexture, s_point_clamp_sampler, input.texcoord); return color; } - if( _FullScreenDebugMode == FULLSCREENDEBUGMODE_RAY_TRACED_GLOBAL_ILLUMINATION) + if( _FullScreenDebugMode == FULLSCREENDEBUGMODE_SCREEN_SPACE_GLOBAL_ILLUMINATION) { float4 color = SAMPLE_TEXTURE2D_X(_DebugFullScreenTexture, s_point_clamp_sampler, input.texcoord); return color; diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/GlobalIllumination.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/GlobalIllumination.cs index bc4f19b104d..ae46f065fc4 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/GlobalIllumination.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/GlobalIllumination.cs @@ -3,15 +3,115 @@ namespace UnityEngine.Rendering.HighDefinition { /// - /// A volume component that holds settings for the ray traced global illumination. + /// A volume component that holds settings for the global illumination (screen space and ray traced). /// - [Serializable, VolumeComponentMenu("Ray Tracing/Global Illumination (Preview)")] - public sealed class GlobalIllumination : VolumeComponent + [Serializable, VolumeComponentMenu("Lighting/Global Illumination")] + public sealed class GlobalIllumination : VolumeComponentWithQuality { /// - /// Enable ray traced global illumination. + /// Enable screen space global illumination. /// - [Tooltip("Enable ray traced global illumination.")] + [Tooltip("Enable screen space global illumination.")] + public BoolParameter enable = new BoolParameter(false); + + /// + /// The thickness of the depth buffer value used for the ray marching step + /// + [Tooltip("Controls the thickness of the depth buffer used for ray marching.")] + public ClampedFloatParameter depthBufferThickness = new ClampedFloatParameter(0.01f, 0, 1.0f); + + /// + /// The number of steps that should be used during the ray marching pass. + /// + public int raySteps + { + get + { + if (!UsesQualitySettings()) + return m_RaySteps.value; + else + return GetLightingQualitySettings().SSGIRaySteps[(int)quality.value]; + } + set { m_RaySteps.value = value; } + } + [SerializeField] + [Tooltip("Controls the number of steps used for ray marching.")] + public ClampedIntParameter m_RaySteps = new ClampedIntParameter(24, 16, 128); + + /// + /// The maximal world space radius from which we should get indirect lighting contribution. + /// + public float maximalRadius + { + get + { + if (!UsesQualitySettings()) + return m_MaximalRadius.value; + else + return GetLightingQualitySettings().SSGIRadius[(int)quality.value]; + } + set { m_MaximalRadius.value = value; } + } + [SerializeField] + [Tooltip("Controls the maximal world space radius from which we should get indirect lighting contribution.")] + public ClampedFloatParameter m_MaximalRadius = new ClampedFloatParameter(2.0f, 0.01f, 50.0f); + + /// + /// Defines if the effect should be evaluated at full resolution. + /// + public bool fullResolutionSS + { + get + { + if (!UsesQualitySettings()) + return m_FullResolutionSS.value; + else + return GetLightingQualitySettings().SSGIFullResolution[(int)quality.value]; + } + set { m_FullResolutionSS.value = value; } + } + [SerializeField] + public BoolParameter m_FullResolutionSS = new BoolParameter(true); + + /// + /// Defines if the effect should be evaluated at full resolution. + /// + public float clampValueSS + { + get + { + if (!UsesQualitySettings()) + return m_ClampValueSS.value; + else + return GetLightingQualitySettings().SSGIClampValue[(int)quality.value]; + } + set { m_ClampValueSS.value = value; } + } + [SerializeField] + public ClampedFloatParameter m_ClampValueSS = new ClampedFloatParameter(2.0f, 0.01f, 10.0f); + + /// + /// Defines the radius for the spatial filter + /// + public int filterRadius + { + get + { + if (!UsesQualitySettings()) + return m_FilterRadius.value; + else + return GetLightingQualitySettings().SSGIFilterRadius[(int)quality.value]; + } + set { m_FilterRadius.value = value; } + } + [Tooltip("Filter Radius")] + [SerializeField] + public ClampedIntParameter m_FilterRadius = new ClampedIntParameter(2, 2, 8); + + /// + /// Toggles ray traced global illumination. + /// + [Tooltip("Toggles ray traced global illumination.")] public BoolParameter rayTracing = new BoolParameter(false); /// diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs index 644fcd0d80c..a502c37133c 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs @@ -121,6 +121,11 @@ class LightDefinitions public static uint s_ScreenSpaceColorShadowFlag = 0x100; public static uint s_InvalidScreenSpaceShadow = 0xff; public static uint s_ScreenSpaceShadowIndexMask = 0xff; + + // Indirect diffuse flags + public static int k_IndirectDiffuseFlagOff = 0x00; + public static int k_ScreenSpaceIndirectDiffuseFlag = 0x01; + public static int k_RayTracedIndirectDiffuseFlag = 0x02; } [GenerateHLSL] diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs.hlsl index b13cb8c12e9..63b4a6b8c86 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs.hlsl @@ -59,6 +59,9 @@ #define SCREEN_SPACE_COLOR_SHADOW_FLAG (256) #define INVALID_SCREEN_SPACE_SHADOW (255) #define SCREEN_SPACE_SHADOW_INDEX_MASK (255) +#define INDIRECT_DIFFUSE_FLAG_OFF (0) +#define SCREEN_SPACE_INDIRECT_DIFFUSE_FLAG (1) +#define RAY_TRACED_INDIRECT_DIFFUSE_FLAG (2) // Generated from UnityEngine.Rendering.HighDefinition.SFiniteLightBound // PackingRules = Exact diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.hlsl index c9b3f261ab0..242a44f0fa4 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.hlsl @@ -531,6 +531,12 @@ void LightLoop( float3 V, PositionInputs posInput, PreLightData preLightData, BS #endif +#if !defined(_SURFACE_TYPE_TRANSPARENT) + // Only use the texture ssgi if the use indirect diffuse flag matches + if (_UseIndirectDiffuse == SCREEN_SPACE_INDIRECT_DIFFUSE_FLAG) + builtinData.bakeDiffuseLighting += LOAD_TEXTURE2D_X(_IndirectDiffuseTexture, posInput.positionSS).xyz * GetInverseCurrentExposureMultiplier(); +#endif + ApplyDebugToLighting(context, builtinData, aggregateLighting); // Also Apply indiret diffuse (GI) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/ShaderVariablesLightLoop.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/ShaderVariablesLightLoop.hlsl index 4298ff62652..3f45edd1510 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/ShaderVariablesLightLoop.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/ShaderVariablesLightLoop.hlsl @@ -31,8 +31,5 @@ TEXTURE2D_X_UINT(_ContactShadowTexture); // Screen space shadows TEXTURE2D_ARRAY(_ScreenSpaceShadowsTexture); -#if RAYTRACING_ENABLED - // Indirect Diffuse Texture - TEXTURE2D_X(_IndirectDiffuseTexture); -#endif - +// Indirect Diffuse Texture +TEXTURE2D_X(_IndirectDiffuseTexture); diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/BilateralUpsample.compute b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/BilateralUpsample.compute new file mode 100644 index 00000000000..0516d9984e2 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/BilateralUpsample.compute @@ -0,0 +1,126 @@ +#pragma kernel BilateralUpSampleSingle BILATERAL_UPSAMPLE=BilateralUpSampleSingle SINGLE_CHANNEL +#pragma kernel BilateralUpSampleColor BILATERAL_UPSAMPLE=BilateralUpSampleColor +#pragma kernel BilateralUpSampleColorTM BILATERAL_UPSAMPLE=BilateralUpSampleColorTM TONE_MAPPED + +//#pragma enable_d3d11_debug_symbols + +#define BILATERAL_UPSAMPLE_TILE_SIZE 8 + +#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" +#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingCommon.hlsl" + +#define _UpsampleTolerance 1e-7f +#define _NoiseFilterStrength 0.99999f + +// Mip chain depth buffer +TEXTURE2D_X(_DepthTexture); +// The half resolution texture that needs to be upscaled +TEXTURE2D_X(_LowResolutionTexture); + +// Constant buffer where all variables should land +CBUFFER_START(UnityScreenSpaceGlobalIllumination) + float4 _HalfScreenSize; + float2 _DepthPyramidFirstMipLevelOffset; +CBUFFER_END + +// The output of our upscaling pass +RW_TEXTURE2D_X(float4, _OutputUpscaledTexture); + +// THe bilateral upscale fonction (color version) +float3 BilUpColor(float HiDepth, float4 LowDepths, float3 lowValue0, float3 lowValue1, float3 lowValue2, float3 lowValue3) +{ + float4 weights = float4(9, 3, 1, 3) / (abs(HiDepth - LowDepths) + _UpsampleTolerance); + float TotalWeight = dot(weights, 1) + _NoiseFilterStrength; + float3 WeightedSum = lowValue0 * weights.x + + lowValue1 * weights.y + + lowValue2 * weights.z + + lowValue3 * weights.w + + _NoiseFilterStrength; + return WeightedSum / TotalWeight; +} + +// THe bilateral upscale fonction (single channel version) +float BilUpSingle(float HiDepth, float4 LowDepths, float4 lowValue) +{ + float4 weights = float4(9, 3, 1, 3) / (abs(HiDepth - LowDepths) + _UpsampleTolerance); + float TotalWeight = dot(weights, 1) + _NoiseFilterStrength; + float WeightedSum = dot(lowValue, weights) + _NoiseFilterStrength; + return WeightedSum / TotalWeight; +} + +// This table references the set of pixels that are used for bilateral upscale based on the expected order +static const int2 UpscaleBilateralPixels[16] = {int2(0, 0), int2(0, -1), int2(-1, -1), int2(-1, 0) + , int2(0, 0), int2(0, -1), int2(1, -1), int2(1, 0) + , int2(0, 0) , int2(-1, 0), int2(-1, 1), int2(0, 1) + , int2(0, 0), int2(1, 0), int2(1, 1), int2(0, 1), }; + +[numthreads(BILATERAL_UPSAMPLE_TILE_SIZE, BILATERAL_UPSAMPLE_TILE_SIZE, 1)] +void BILATERAL_UPSAMPLE(uint3 dispatchThreadId : SV_DispatchThreadID, uint2 groupThreadId : SV_GroupThreadID, uint2 groupId : SV_GroupID) +{ + UNITY_XR_ASSIGN_VIEW_INDEX(dispatchThreadId.z); + + // If out of bounds, discard + if (any(dispatchThreadId.xy > uint2(_ScreenSize.xy))) + return; + + // The pixel position to process + const uint2 outputCoord = dispatchThreadId.xy; + + // Read the depth value as early as possible and use it as late as possible + float hiResDepth = LOAD_TEXTURE2D_X(_DepthTexture, outputCoord).x; + + // Define what is the half resolution of this pixel + int2 halfResolution = (int2)(outputCoord / 2); + + // Define what is the half resolution of this pixel + int2 coordRepresenatative = halfResolution * 2; + + // Compute the shift within the half res + int2 halfResShift = outputCoord - coordRepresenatative; + + // Compute the shift of the pixel in the group + int shiftIndex = halfResShift.y * 2 + halfResShift.x; + + // Compute the shift in the upscale table + int offsetInCoordTable = shiftIndex * 4; + + // Compute the half resolution coordinates we should tap from + int2 halfResTap0 = clamp(0, halfResolution + UpscaleBilateralPixels[offsetInCoordTable], _HalfScreenSize.xy - 1); + int2 halfResTap1 = clamp(0, halfResolution + UpscaleBilateralPixels[offsetInCoordTable + 1], _HalfScreenSize.xy - 1); + int2 halfResTap2 = clamp(0, halfResolution + UpscaleBilateralPixels[offsetInCoordTable + 2], _HalfScreenSize.xy - 1); + int2 halfResTap3 = clamp(0, halfResolution + UpscaleBilateralPixels[offsetInCoordTable + 3], _HalfScreenSize.xy - 1); + + // Grab the depth of all the half resolution pixels + float4 lowDepths = float4(LOAD_TEXTURE2D_X(_DepthTexture, asuint(_DepthPyramidFirstMipLevelOffset) + halfResTap0).x + , LOAD_TEXTURE2D_X(_DepthTexture, asuint(_DepthPyramidFirstMipLevelOffset) + halfResTap1).x + , LOAD_TEXTURE2D_X(_DepthTexture, asuint(_DepthPyramidFirstMipLevelOffset) + halfResTap2).x + , LOAD_TEXTURE2D_X(_DepthTexture, asuint(_DepthPyramidFirstMipLevelOffset) + halfResTap3).x); + +#if SINGLE_CHANNEL + // Grab all the scalar values required for upscale + float4 lowRes = float4(_LowResolutionTexture[COORD_TEXTURE2D_X(halfResTap0)].x + , _LowResolutionTexture[COORD_TEXTURE2D_X(halfResTap1)].x + , _LowResolutionTexture[COORD_TEXTURE2D_X(halfResTap2)].x + , _LowResolutionTexture[COORD_TEXTURE2D_X(halfResTap3)].x); + // Upscale and output + _OutputUpscaledTexture[COORD_TEXTURE2D_X(outputCoord)] = BilUpSingle(hiResDepth, lowDepths, lowRes); +#else + // Grab all the color values required for upscale + float3 lowResCol0 = max(0, _LowResolutionTexture[COORD_TEXTURE2D_X(halfResTap0)].xyz); + float3 lowResCol1 = max(0, _LowResolutionTexture[COORD_TEXTURE2D_X(halfResTap1)].xyz); + float3 lowResCol2 = max(0, _LowResolutionTexture[COORD_TEXTURE2D_X(halfResTap2)].xyz); + float3 lowResCol3 = max(0, _LowResolutionTexture[COORD_TEXTURE2D_X(halfResTap3)].xyz); + + // Upscale + float3 upscaledColor = BilUpColor(hiResDepth, lowDepths, lowResCol0, lowResCol1, lowResCol2, lowResCol3); + + #if TONE_MAPPED + // Reverse the tone mapping (when SSGI is computed in half res, we denoise it in tonemapped space to avoid high variance during the denoising) + _OutputUpscaledTexture[COORD_TEXTURE2D_X(outputCoord)] = float4(upscaledColor / (1.0 - upscaledColor), 1.0f); + #else + _OutputUpscaledTexture[COORD_TEXTURE2D_X(outputCoord)] = float4(upscaledColor, 1.0f); + #endif +#endif +} \ No newline at end of file diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/BilateralUpsample.compute.meta b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/BilateralUpsample.compute.meta new file mode 100644 index 00000000000..4132f499f40 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/BilateralUpsample.compute.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 68e831c555284d741b985e05369f0e63 +ComputeShaderImporter: + externalObjects: {} + currentAPIMask: 278528 + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/SSGIDenoiser.compute b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/SSGIDenoiser.compute new file mode 100644 index 00000000000..64e18e22537 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/SSGIDenoiser.compute @@ -0,0 +1,268 @@ +#pragma kernel SpatialFilterHalf SPATIAL_FILTER=SpatialFilterHalf HALF_RES +#pragma kernel SpatialFilter SPATIAL_FILTER=SpatialFilter +#pragma kernel TemporalFilterHalf TEMPORAL_FILTER=TemporalFilterHalf HALF_RES +#pragma kernel TemporalFilter TEMPORAL_FILTER=TemporalFilter +#pragma kernel CopyHistory COPY_HISTORY=CopyHistory + +// Common includes +#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" +#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonLighting.hlsl" +#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Sampling/Sampling.hlsl" +#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" + +// HDRP includes +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/NormalBuffer.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Builtin/BuiltinData.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/TemporalAntialiasing.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Denoising/BilateralFilter.hlsl" + +// #pragma only_renderers d3d11 +// #pragma enable_d3d11_debug_symbols + +// Tile size of this compute shaders +#define SSGI_FILTER_TILE_SIZE 8 + +// Noisy buffer input +TEXTURE2D_X(_InputNoisyBuffer); + +// Constant buffer that should hold all the scalar values require +CBUFFER_START(UnityScreenSpaceGlobalIllumination) + float2 _DepthPyramidFirstMipLevelOffset; + float4 _HalfScreenSize; + int _IndirectDiffuseSpatialFilter; +CBUFFER_END + +// Denoised output buffer +RW_TEXTURE2D_X(float4, _OutputFilteredBuffer); + +#define SPATIAL_FILTER_SIGMA_RATIO 1.0 +#define DEPTH_WEIGHT_MULTIPLIER 1000.0f +#define NORMAL_WEIGHT_MULTIPLIER 5.0 + +[numthreads(SSGI_FILTER_TILE_SIZE, SSGI_FILTER_TILE_SIZE, 1)] +void SPATIAL_FILTER(uint3 dispatchThreadId : SV_DispatchThreadID , uint2 groupThreadId : SV_GroupThreadID , uint2 groupId : SV_GroupID) +{ + UNITY_XR_ASSIGN_VIEW_INDEX(dispatchThreadId.z); + + // Fetch the current pixel coordinates + int2 centerCoord = dispatchThreadId.xy; + +#if HALF_RES + // Get the posinputs of the current version of the pixel + float depth = LOAD_TEXTURE2D_X(_DepthTexture, asuint(_DepthPyramidFirstMipLevelOffset) + centerCoord).r; + float4 normalCompressed = LOAD_TEXTURE2D_X(_NormalBufferTexture, centerCoord * 2 ); + NormalData normalData; + DecodeFromNormalBuffer(normalCompressed, 0, normalData); +#else + // Get the posinputs of the current version of the pixel + float depth = LOAD_TEXTURE2D_X(_DepthTexture, centerCoord).r; + float4 normalCompressed = LOAD_TEXTURE2D_X(_NormalBufferTexture, centerCoord); + NormalData normalData; + DecodeFromNormalBuffer(normalCompressed, 0, normalData); +#endif + + // If the current point we are processing is a background point or the whole history should be discarded for an other reason, we invalidate the history + if (depth == UNITY_RAW_FAR_CLIP_VALUE) + { + _OutputFilteredBuffer[COORD_TEXTURE2D_X(centerCoord)] = 0; + return; + } + + // Convert the depth into linear for weight evaluation + float centerz01 = Linear01Depth(depth, _ZBufferParams); + float3 colorSum = 0.0; + float wSum = 0.0; + int2 tapCoord = centerCoord; + float sigma = _IndirectDiffuseSpatialFilter * SPATIAL_FILTER_SIGMA_RATIO; + + // Loop through the neighboord and do our filter + for (int y = -_IndirectDiffuseSpatialFilter; y <= _IndirectDiffuseSpatialFilter; ++y) + { + for (int x = -_IndirectDiffuseSpatialFilter; x <= _IndirectDiffuseSpatialFilter; ++x) + { + // This could probably be avoided, but the shader is badwidth bound anyway, so.. + float r = sqrt(x * x + y * y); + + // Compute the absolute tap coord + tapCoord = centerCoord + int2(x, y); + + // We should not tap outside of the screen (given that its a unit, if we go below zero we wrap around) +#if HALF_RES + if (tapCoord.x >= _HalfScreenSize.x + || tapCoord.x < 0 + || tapCoord.y >= _HalfScreenSize.y + || tapCoord.y < 0) + continue; +#else + if (tapCoord.x >= _ScreenSize.x + || tapCoord.x < 0 + || tapCoord.y >= _ScreenSize.y + || tapCoord.y < 0) + continue; +#endif + + // Read the depth of the tap pixel +#if HALF_RES + float tapDepth = LOAD_TEXTURE2D_X(_DepthTexture, asuint(_DepthPyramidFirstMipLevelOffset) + tapCoord).r; + float4 normalCompressedTap = LOAD_TEXTURE2D_X(_NormalBufferTexture, tapCoord * 2); + NormalData normalDataTap; + DecodeFromNormalBuffer(normalCompressedTap, 0, normalDataTap); +#else + float tapDepth = LOAD_TEXTURE2D_X(_DepthTexture, tapCoord).r; + float4 normalCompressedTap = LOAD_TEXTURE2D_X(_NormalBufferTexture, tapCoord); + NormalData normalDataTap; + DecodeFromNormalBuffer(normalCompressedTap, 0, normalDataTap); +#endif + // Convert the tapped depth to linear for weight evaluation + float tapz01 = Linear01Depth(tapDepth, _ZBufferParams); + + // Compute the depth for this pixel + float depthWeight = max(0.0, 1.0 - abs(tapz01 - centerz01) * DEPTH_WEIGHT_MULTIPLIER); + + const float normalCloseness = sqr(sqr(max(0.0, dot(normalDataTap.normalWS, normalData.normalWS)))); + const float normalError = 1.0 - normalCloseness; + const float normalWeight = max(0.0, (1.0 - normalError * NORMAL_WEIGHT_MULTIPLIER)); + + // Compute the weight (skip computation for the center) + const float w = r ? gaussian(r, sigma) * depthWeight * normalWeight : 1.0; + + // Accumuate this value + colorSum += LOAD_TEXTURE2D_X(_InputNoisyBuffer, tapCoord).xyz * w; + wSum += w; + } + } + + // Output the result to the buffer and propagate the w channel as is. + // TODO: We could save bandwidth by doing this using a 111110 texture and storing the w in a different texture + _OutputFilteredBuffer[COORD_TEXTURE2D_X(centerCoord)] = float4(colorSum / wSum, LOAD_TEXTURE2D_X(_InputNoisyBuffer, centerCoord).w); +} + +// History buffer input +TEXTURE2D_X(_HistoryBuffer); +// Depth buffer of the previous frame, this is either the full res depth or half res based on the variant of the shader +TEXTURE2D_X(_HistoryDepthTexture); + +[numthreads(SSGI_FILTER_TILE_SIZE, SSGI_FILTER_TILE_SIZE, 1)] +void TEMPORAL_FILTER(uint3 dispatchThreadId : SV_DispatchThreadID + , uint2 groupThreadId : SV_GroupThreadID + , uint2 groupId : SV_GroupID) +{ + UNITY_XR_ASSIGN_VIEW_INDEX(dispatchThreadId.z); + + int2 centerCoord = dispatchThreadId.xy; + + // Read the color as early as possible + float4 color = LOAD_TEXTURE2D_X(_InputNoisyBuffer, centerCoord); + +#if HALF_RES + // We need the full res coordinate for the inputs + uint2 fullResCoord = centerCoord * 2; + + // Get the posinputs of the current version of the pixel + float depth = LOAD_TEXTURE2D_X(_DepthTexture, asuint(_DepthPyramidFirstMipLevelOffset) + centerCoord).r; + PositionInputs posInputs = GetPositionInput(fullResCoord, _ScreenSize.zw, depth, UNITY_MATRIX_I_VP, GetWorldToViewMatrix()); +#else + // Get the posinputs of the current version of the pixel + float depth = LOAD_TEXTURE2D_X(_DepthTexture, centerCoord).r; + PositionInputs posInputs = GetPositionInput(centerCoord, _ScreenSize.zw, depth, UNITY_MATRIX_I_VP, GetWorldToViewMatrix()); +#endif + + // Initialize the output buffer in case of an early exit. + _OutputFilteredBuffer[COORD_TEXTURE2D_X(centerCoord)] = 0.0; + + + // If the current point we are processing is a background point or the whole history should be discarded for an other reason, we invalidate the history + if (depth == UNITY_RAW_FAR_CLIP_VALUE) + return; + + // Decode the velocity of the pixel + float2 velocity = float2(0.0, 0.0); +#if HALF_RES + DecodeMotionVector(LOAD_TEXTURE2D_X(_CameraMotionVectorsTexture, (float2)fullResCoord), velocity); +#else + DecodeMotionVector(LOAD_TEXTURE2D_X(_CameraMotionVectorsTexture, (float2)centerCoord), velocity); +#endif + + // Compute the pixel coordinate for the history tapping + int2 historyTapCoord = (int2)((posInputs.positionNDC - velocity) * _ScreenSize.xy); +#if HALF_RES + historyTapCoord *= 0.5; + // If the pixel was outside of the screen during the previous frame, invalidate the history + if (historyTapCoord.x >= _HalfScreenSize.x || historyTapCoord.x < 0 + || historyTapCoord.y >= _HalfScreenSize.y || historyTapCoord.y < 0) + return; +#else + // If the pixel was outside of the screen during the previous frame, invalidate the history + if (historyTapCoord.x >= _ScreenSize.x || historyTapCoord.x < 0 + || historyTapCoord.y >= _ScreenSize.y || historyTapCoord.y < 0) + return; +#endif + + // Fetch the depth of the history pixel. If the history position was a background point, invalidate the history + float historyDepth = LOAD_TEXTURE2D_X(_HistoryDepthTexture, historyTapCoord).r; + + // If the history was a background pixel, skip it + bool invalidHistory = false; + if (historyDepth == UNITY_RAW_FAR_CLIP_VALUE) + invalidHistory = true; + + // Compute the world space position (from previous frame) + float3 historyPositionWS = ComputeWorldSpacePosition(posInputs.positionNDC - velocity, historyDepth, UNITY_MATRIX_PREV_I_VP); + + // Is it too far from the current position? + if (length(historyPositionWS - posInputs.positionWS) > 0.1) + invalidHistory = true; + + // Fetch history data + float4 history = LOAD_TEXTURE2D_X(_HistoryBuffer, historyTapCoord); + float sampleCount = history.w; + + // Accumulation factor that tells us how much we need to keep the history data + float accumulationFactor = 0.0; + + // If the history is invalid + if (invalidHistory || sampleCount == 0.0) + { + // We only take the current value + accumulationFactor = 0.0; + + // To avoid nan values + #if SINGLE_CHANNEL + history.x = 0.0; + #else + history.xyz = 0.0; + #endif + sampleCount = 1.0; + } + else + { + // Otherwise we compute the accumulation factor + accumulationFactor = sampleCount >= 8.0 ? 0.97 : (sampleCount / (sampleCount + 1.0)); + + // Update the sample count + sampleCount = min(sampleCount + 1.0, 8.0); + + // If the history pixel was moving, we descide to throw partially the history + // TODO: Expose this as a parameter + if (color.w > 0.0) + { + sampleCount = 5.0; + accumulationFactor = sampleCount / (sampleCount + 1.0); + } + } + + // Do the accumulation based on the values we computed and store the new sample count in the w channel + _OutputFilteredBuffer[COORD_TEXTURE2D_X(centerCoord)] = float4(color.xyz * (1.0 - accumulationFactor) + history.xyz * accumulationFactor, sampleCount); +} + +[numthreads(SSGI_FILTER_TILE_SIZE, SSGI_FILTER_TILE_SIZE, 1)] +void COPY_HISTORY(uint3 dispatchThreadId : SV_DispatchThreadID) +{ + UNITY_XR_ASSIGN_VIEW_INDEX(dispatchThreadId.z); + + if (any(dispatchThreadId.xy > uint2(_ScreenSize.xy))) + return; // Out of bounds, discard + + _OutputFilteredBuffer[COORD_TEXTURE2D_X(dispatchThreadId.xy)] = LOAD_TEXTURE2D_X(_InputNoisyBuffer, dispatchThreadId.xy); +} \ No newline at end of file diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/SSGIDenoiser.compute.meta b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/SSGIDenoiser.compute.meta new file mode 100644 index 00000000000..76ca950c3f0 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/SSGIDenoiser.compute.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a435d803bc32d0845ba1a713b7a1c8b1 +ComputeShaderImporter: + externalObjects: {} + currentAPIMask: 4 + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/SSGIDenoiser.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/SSGIDenoiser.cs new file mode 100644 index 00000000000..fb30bdd2939 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/SSGIDenoiser.cs @@ -0,0 +1,168 @@ +using UnityEngine.Rendering; +using UnityEngine.Rendering.HighDefinition; +using UnityEngine.Experimental.Rendering; +using UnityEngine.Experimental.Rendering.HighDefinition; + +namespace UnityEngine.Experimental.Rendering.HighDefinition +{ + class SSGIDenoiser + { + // Resources used for the denoiser + ComputeShader m_SSGIDenoiserCS; + + // Required for fetching depth and normal buffers + SharedRTManager m_SharedRTManager; + HDRenderPipeline m_RenderPipeline; + + int m_SpatialFilterHalfKernel; + int m_SpatialFilterKernel; + int m_TemporalFilterHalfKernel; + int m_TemporalFilterKernel; + int m_CopyHistory; + + // Temporary variables to avoid memory alloc + Vector2 firstMipOffset = new Vector2(0.0f, 0.0f); + + public SSGIDenoiser() + { + } + + public void Init(RenderPipelineResources rpResources, SharedRTManager sharedRTManager, HDRenderPipeline renderPipeline) + { + // Keep track of the resources + m_SSGIDenoiserCS = rpResources.shaders.ssGIDenoiserCS; + + // Keep track of the shared rt manager + m_SharedRTManager = sharedRTManager; + m_RenderPipeline = renderPipeline; + + // Fetch the kernels we are going to require + m_SpatialFilterHalfKernel = m_SSGIDenoiserCS.FindKernel("SpatialFilterHalf"); + m_SpatialFilterKernel = m_SSGIDenoiserCS.FindKernel("SpatialFilter"); + + // Fetch the kernels we are going to require + m_TemporalFilterHalfKernel = m_SSGIDenoiserCS.FindKernel("TemporalFilterHalf"); + m_TemporalFilterKernel = m_SSGIDenoiserCS.FindKernel("TemporalFilter"); + + m_CopyHistory = m_SSGIDenoiserCS.FindKernel("CopyHistory"); + } + + public void Release() + { + } + + void EvaluateDispatchParameters(HDCamera hdCamera, bool halfResolution, int tileSize, + out int numTilesX, out int numTilesY, out Vector4 halfScreenSize) + { + if (halfResolution) + { + // Fetch texture dimensions + int texWidth = hdCamera.actualWidth / 2; + int texHeight = hdCamera.actualHeight / 2; + numTilesX = (texWidth + (tileSize - 1)) / tileSize; + numTilesY = (texHeight + (tileSize - 1)) / tileSize; + halfScreenSize = new Vector4(texWidth, texHeight, 1.0f / texWidth, 1.0f / texHeight); + + } + else + { + // Fetch texture dimensions + int texWidth = hdCamera.actualWidth; + int texHeight = hdCamera.actualHeight; + numTilesX = (texWidth + (tileSize - 1)) / tileSize; + numTilesY = (texHeight + (tileSize - 1)) / tileSize; + halfScreenSize = new Vector4(texWidth / 2, texHeight / 2, 0.5f / texWidth, 0.5f / texHeight); + } + } + + RTHandle IndirectDiffuseHistoryBufferAllocatorFunction(string viewName, int frameIndex, RTHandleSystem rtHandleSystem) + { + return rtHandleSystem.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, dimension: TextureXR.dimension, + enableRandomWrite: true, useMipMap: false, autoGenerateMips: false, + name: string.Format("IndirectDiffuseHistoryBuffer{0}", frameIndex)); + } + + public void Denoise(CommandBuffer cmd, HDCamera hdCamera, + RTHandle noisyBuffer, RTHandle outputBuffer, + bool halfResolution = false) + { + // Grab the global illumination volume component + var giSettings = hdCamera.volumeStack.GetComponent(); + + var historyDepthBuffer = hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.Depth); + var historyDepthBuffer1 = hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.Depth1); + // If the depth textures are not available, we can't denoise + if (historyDepthBuffer == null || historyDepthBuffer1 == null) + { + HDUtils.BlitCameraTexture(cmd, noisyBuffer, outputBuffer); + return; + } + + // Compute the dispatch parameters based on if we are half res or not + int tileSize = 8; + int numTilesX, numTilesY; + Vector4 halfScreenSize; + EvaluateDispatchParameters(hdCamera, halfResolution, tileSize, out numTilesX, out numTilesY, out halfScreenSize); + + // Pick the right kernel to use + int m_KernelFilter = halfResolution ? m_SpatialFilterHalfKernel : m_SpatialFilterKernel; + + // Bind the input scalars + var info = m_SharedRTManager.GetDepthBufferMipChainInfo(); + firstMipOffset.Set(HDShadowUtils.Asfloat((uint)info.mipLevelOffsets[1].x), HDShadowUtils.Asfloat((uint)info.mipLevelOffsets[1].y)); + cmd.SetComputeVectorParam(m_SSGIDenoiserCS, HDShaderIDs._DepthPyramidFirstMipLevelOffset, firstMipOffset); + cmd.SetComputeIntParam(m_SSGIDenoiserCS, HDShaderIDs._IndirectDiffuseSpatialFilter, giSettings.filterRadius); + // Inject half screen size if required + if (halfResolution) + cmd.SetComputeVectorParam(m_SSGIDenoiserCS, HDShaderIDs._HalfScreenSize, halfScreenSize); + + // Bind the input buffers + cmd.SetComputeTextureParam(m_SSGIDenoiserCS, m_KernelFilter, HDShaderIDs._DepthTexture, m_SharedRTManager.GetDepthTexture()); + cmd.SetComputeTextureParam(m_SSGIDenoiserCS, m_KernelFilter, HDShaderIDs._InputNoisyBuffer, noisyBuffer); + + // Bind the output buffer + cmd.SetComputeTextureParam(m_SSGIDenoiserCS, m_KernelFilter, HDShaderIDs._OutputFilteredBuffer, outputBuffer); + + // Do the spatial pass + cmd.DispatchCompute(m_SSGIDenoiserCS, m_KernelFilter, numTilesX, numTilesY, hdCamera.viewCount); + + // Grab the history buffer + RTHandle indirectDiffuseHistory = hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.RaytracedIndirectDiffuseHF); + if(indirectDiffuseHistory == null) + { + indirectDiffuseHistory = hdCamera.AllocHistoryFrameRT((int)HDCameraFrameHistoryType.RaytracedIndirectDiffuseHF, IndirectDiffuseHistoryBufferAllocatorFunction, 1); + // clear it to black if this is the first pass to avoid nans + CoreUtils.SetRenderTarget(cmd, indirectDiffuseHistory, m_SharedRTManager.GetDepthStencilBuffer(), ClearFlag.Color, clearColor: Color.black); + } + + // Pick the right kernel to use + m_KernelFilter = halfResolution ? m_TemporalFilterHalfKernel : m_TemporalFilterKernel; + + // Bind the input buffers + cmd.SetComputeTextureParam(m_SSGIDenoiserCS, m_KernelFilter, HDShaderIDs._DepthTexture, m_SharedRTManager.GetDepthTexture()); + cmd.SetComputeTextureParam(m_SSGIDenoiserCS, m_KernelFilter, HDShaderIDs._NormalBufferTexture, m_SharedRTManager.GetNormalBuffer()); + if (halfResolution) + { + cmd.SetComputeTextureParam(m_SSGIDenoiserCS, m_KernelFilter, HDShaderIDs._HistoryDepthTexture, historyDepthBuffer1); + cmd.SetComputeVectorParam(m_SSGIDenoiserCS, HDShaderIDs._DepthPyramidFirstMipLevelOffset, firstMipOffset); + } + else + { + cmd.SetComputeTextureParam(m_SSGIDenoiserCS, m_KernelFilter, HDShaderIDs._HistoryDepthTexture, historyDepthBuffer); + } + cmd.SetComputeTextureParam(m_SSGIDenoiserCS, m_KernelFilter, HDShaderIDs._HistoryBuffer, indirectDiffuseHistory); + cmd.SetComputeTextureParam(m_SSGIDenoiserCS, m_KernelFilter, HDShaderIDs._InputNoisyBuffer, outputBuffer); + + // Bind the output buffer + cmd.SetComputeTextureParam(m_SSGIDenoiserCS, m_KernelFilter, HDShaderIDs._OutputFilteredBuffer, noisyBuffer); + + // Do the temporal pass + cmd.DispatchCompute(m_SSGIDenoiserCS, m_KernelFilter, numTilesX, numTilesY, hdCamera.viewCount); + + // Copy the new version into the history buffer + cmd.SetComputeTextureParam(m_SSGIDenoiserCS, m_CopyHistory, HDShaderIDs._InputNoisyBuffer, noisyBuffer); + cmd.SetComputeTextureParam(m_SSGIDenoiserCS, m_CopyHistory, HDShaderIDs._OutputFilteredBuffer, indirectDiffuseHistory); + cmd.DispatchCompute(m_SSGIDenoiserCS, m_CopyHistory, numTilesX, numTilesY, hdCamera.viewCount); + } + } +} diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/SSGIDenoiser.cs.meta b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/SSGIDenoiser.cs.meta new file mode 100644 index 00000000000..39df34e40f3 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/SSGIDenoiser.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d3e15f22b48ced841a9f0183a77078f7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/ScreenSpaceGlobalIllumination.compute b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/ScreenSpaceGlobalIllumination.compute new file mode 100644 index 00000000000..22f39efa81d --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/ScreenSpaceGlobalIllumination.compute @@ -0,0 +1,353 @@ +// HDRP generic includes +#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" +#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/NormalBuffer.hlsl" + +// Raytracing includes (should probably be in generic files) +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingSampling.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RayTracingCommon.hlsl" + +// #pragma enable_d3d11_debug_symbols + +#pragma kernel TraceGlobalIllumination TRACE_GLOBAL_ILLUMINATION=TraceGlobalIllumination GI_TRACE +#pragma kernel TraceGlobalIlluminationHalf TRACE_GLOBAL_ILLUMINATION=TraceGlobalIlluminationHalf GI_TRACE HALF_RES +#pragma kernel ReprojectGlobalIllumination REPROJECT_GLOBAL_ILLUMINATION=ReprojectGlobalIllumination GI_REPROJECT +#pragma kernel ReprojectGlobalIlluminationHalf REPROJECT_GLOBAL_ILLUMINATION=ReprojectGlobalIlluminationHalf GI_REPROJECT HALF_RES + +// The dispatch tile resolution +#define INDIRECT_DIFFUSE_TILE_SIZE 8 + +// Epslon value used for the computation +#define GI_TRACE_EPS 0.00024414 + +// Input depth pyramid texture +TEXTURE2D_X(_DepthTexture); +// Input texture that holds the offset for every level of the depth pyramid +StructuredBuffer _DepthPyramidMipLevelOffsets; + +// Constant buffer that holds all scalar that we need +CBUFFER_START(UnityScreenSpaceGlobalIllumination) + int _IndirectDiffuseSteps; + float _IndirectDiffuseThicknessScale; + float _IndirectDiffuseThicknessBias; + float _IndirectDiffuseMaximalRadius; + int _IndirectDiffuseProbeFallbackFlag; + int _IndirectDiffuseProbeFallbackBias; + float4 _ColorPyramidUvScaleAndLimitPrevFrame; +CBUFFER_END + +// Output texture that holds the hit point NDC coordinates +RW_TEXTURE2D_X(float2, _IndirectDiffuseHitPointTextureRW); + +// TODO: It is not really possible to share all of this with SSR for couple reason, but it probably possible share a part of it +bool RayMarch(float3 positionWS, float3 sampleDir, float3 normalWS, float2 positionSS, float deviceDepth, bool killRay, out float3 rayPos) +{ + // Initialize ray pos to invalid value + rayPos = -1.0; + + // We start tracing from the center of the current pixel, and do so up to the far plane. + float3 rayOrigin = float3(positionSS + 0.5, deviceDepth); + + // Compute the sampled position in world space (one meter away from the original point along the sampled direction) + float3 sampledPosWS = positionWS + sampleDir * _IndirectDiffuseMaximalRadius; + + // Convert the sampled position to NDC, then to SS + float3 sampledPosNDC = ComputeNormalizedDeviceCoordinatesWithZ(sampledPosWS, UNITY_MATRIX_VP); // Jittered + float3 sampledPosSS = float3(sampledPosNDC.xy * _ScreenSize.xy, sampledPosNDC.z); + + // Compute the ray direction in screen space + float3 rayDir = (sampledPosSS - rayOrigin); + + // Compute the reciprocal of the direction (not sure why tho ftm) + float3 rcpRayDir = rcp(rayDir); + + // Compute a ray step (added an abs here looks better, maybe its wrong need to check mmore) + int2 rayStep = int2((rcpRayDir.x) >= 0 ? 1 : 0, + (rcpRayDir.y) >= 0 ? 1 : 0); + + float3 raySign = float3(rcpRayDir.x >= 0 ? 1 : -1, + rcpRayDir.y >= 0 ? 1 : -1, + rcpRayDir.z >= 0 ? 1 : -1); + bool rayTowardsEye = rcpRayDir.z >= 0; + + // If the point is behind the camera, this ray should not be cast + killRay = killRay || (sampledPosSS.z <= 0); + + // If this ray + if (killRay) + return false; + + // Build the bounds that start at the center of the pixel and travel to the edge of the screen + float tMax; + { + // Shrink the frustum by half a texel for efficiency reasons. + const float halfTexel = 0.5; + + float3 bounds; + bounds.x = clamp(sampledPosSS.x, halfTexel, _ScreenSize.x - halfTexel); + bounds.y = clamp(sampledPosSS.y, halfTexel, _ScreenSize.y - halfTexel); + // If we do not want to intersect the skybox, it is more efficient to not trace too far. + float maxDepth = -0.00000024; // 2^-22 + bounds.z = (rcpRayDir.z >= 0) ? 1 : maxDepth; + + float3 dist = bounds * rcpRayDir - (rayOrigin * rcpRayDir); + tMax = Min3(dist.x, dist.y, dist.z); + } + + // Start ray marching from the next texel to avoid self-intersections. + float t; + { + // 'rayOrigin' is the exact texel center. + float2 dist = abs(0.5 * rcpRayDir.xy); + t = min(dist.x, dist.y); + } + + int mipLevel = 0; + int2 mipOffset = _DepthPyramidMipLevelOffsets[mipLevel]; + int iterCount = 0; + bool hit = false; + bool miss = false; + bool belowMip0 = false; // This value is set prior to entering the cell + + while (!(hit || miss) && (t <= tMax) && (iterCount < _IndirectDiffuseSteps)) + { + rayPos = rayOrigin + t * rayDir; + + // Ray position often ends up on the edge. To determine (and look up) the right cell, + // we need to bias the position by a small epsilon in the direction of the ray. + float2 sgnEdgeDist = round(rayPos.xy) - rayPos.xy; + float2 satEdgeDist = clamp(raySign.xy * sgnEdgeDist + GI_TRACE_EPS, 0, GI_TRACE_EPS); + rayPos.xy += raySign.xy * satEdgeDist; + + int2 mipCoord = (int2)rayPos.xy >> mipLevel; + // Bounds define 4 faces of a cube: + // 2 walls in front of the ray, and a floor and a base below it. + float4 bounds; + + bounds.z = LOAD_TEXTURE2D_X(_CameraDepthTexture, mipOffset + mipCoord).r; + bounds.xy = (mipCoord + rayStep) << mipLevel; + + // We define the depth of the base as the depth value as: + // b = DeviceDepth((1 + thickness) * LinearDepth(d)) + // b = ((f - n) * d + n * (1 - (1 + thickness))) / ((f - n) * (1 + thickness)) + // b = ((f - n) * d - n * thickness) / ((f - n) * (1 + thickness)) + // b = d / (1 + thickness) - n / (f - n) * (thickness / (1 + thickness)) + // b = d * k_s + k_b + bounds.w = bounds.z * _IndirectDiffuseThicknessScale + _IndirectDiffuseThicknessBias; + + float4 dist = bounds * rcpRayDir.xyzz - (rayOrigin.xyzz * rcpRayDir.xyzz); + float distWall = min(dist.x, dist.y); + float distFloor = dist.z; + float distBase = dist.w; + + // Note: 'rayPos' given by 't' can correspond to one of several depth values: + // - above or exactly on the floor + // - inside the floor (between the floor and the base) + // - below the base + bool belowFloor = rayPos.z < bounds.z; + bool aboveBase = rayPos.z >= bounds.w; + + bool insideFloor = belowFloor && aboveBase; + bool hitFloor = (t <= distFloor) && (distFloor <= distWall); + + // Game rules: + // * if the closest intersection is with the wall of the cell, switch to the coarser MIP, and advance the ray. + // * if the closest intersection is with the heightmap below, switch to the finer MIP, and advance the ray. + // * if the closest intersection is with the heightmap above, switch to the finer MIP, and do NOT advance the ray. + // Victory conditions: + // * See below. Do NOT reorder the statements! + + miss = belowMip0 && insideFloor; + hit = (mipLevel == 0) && (hitFloor || insideFloor); + belowMip0 = (mipLevel == 0) && belowFloor; + + // 'distFloor' can be smaller than the current distance 't'. + // We can also safely ignore 'distBase'. + // If we hit the floor, it's always safe to jump there. + // If we are at (mipLevel != 0) and we are below the floor, we should not move. + t = hitFloor ? distFloor : (((mipLevel != 0) && belowFloor) ? t : distWall); + rayPos.z = bounds.z; // Retain the depth of the potential intersection + + // Warning: both rays towards the eye, and tracing behind objects has linear + // rather than logarithmic complexity! This is due to the fact that we only store + // the maximum value of depth, and not the min-max. + mipLevel += (hitFloor || belowFloor || rayTowardsEye) ? -1 : 1; + mipLevel = clamp(mipLevel, 0, 6); + mipOffset = _DepthPyramidMipLevelOffsets[mipLevel]; + // mipLevel = 0; + + iterCount++; + } + + // Treat intersections with the sky as misses. + miss = miss || ((rayPos.z == 0)); + return hit && !miss; +} + +[numthreads(INDIRECT_DIFFUSE_TILE_SIZE, INDIRECT_DIFFUSE_TILE_SIZE, 1)] +void TRACE_GLOBAL_ILLUMINATION(uint3 dispatchThreadId : SV_DispatchThreadID, uint2 groupThreadId : SV_GroupThreadID, uint2 groupId : SV_GroupID) +{ + UNITY_XR_ASSIGN_VIEW_INDEX(dispatchThreadId.z); + + // Compute the pixel position to process + uint2 currentCoord = dispatchThreadId.xy; + +#if HALF_RES + // Fetch the mipoffset for the second mip (half res) + int2 mipOffset = _DepthPyramidMipLevelOffsets[1]; + // Grab the depth of the half res pixel (better than grabbing a random one across the 4 candidates or averaging) + float deviceDepth = LOAD_TEXTURE2D_X(_DepthTexture, mipOffset + currentCoord).x; + // Compute the full resolution pixel for the inputs that do not have a pyramid + uint2 fullResCoord = currentCoord * 2; +#else + // Read the depth value as early as possible + float deviceDepth = LOAD_TEXTURE2D_X(_DepthTexture, currentCoord).x; +#endif + // Initialize the hitpoint texture to a miss + _IndirectDiffuseHitPointTextureRW[COORD_TEXTURE2D_X(currentCoord)] = float2(99.0, 0.0); + + // Read the pixel normal + NormalData normalData; +#if HALF_RES + // For half resolution, we take the top left corner (0, 0) in the upscaled 2x2 pixel neighborhood + DecodeFromNormalBuffer(fullResCoord.xy, normalData); +#else + DecodeFromNormalBuffer(currentCoord.xy, normalData); +#endif + // Generete a new direction to follow + float2 newSample; + newSample.x = GetBNDSequenceSample(currentCoord.xy, _RaytracingFrameIndex, 0); + newSample.y = GetBNDSequenceSample(currentCoord.xy, _RaytracingFrameIndex, 1); + + // Importance sample with a cosine lobe (direction that will be used for ray casting) + float3 sampleDir = SampleHemisphereCosine(newSample.x, newSample.y, normalData.normalWS); + + // Compute the camera position + float3 camPosWS = GetCurrentViewPosition(); + + // If this is a background pixel, we flag the ray as a dead ray (we are also trying to keep the usage of the depth buffer the latest possible) + bool killRay = deviceDepth == UNITY_RAW_FAR_CLIP_VALUE; + // Convert this to a world space position (camera relative) +#if HALF_RES + PositionInputs posInput = GetPositionInput(fullResCoord, _ScreenSize.zw, deviceDepth, UNITY_MATRIX_I_VP, GetWorldToViewMatrix(), 0); +#else + PositionInputs posInput = GetPositionInput(currentCoord, _ScreenSize.zw, deviceDepth, UNITY_MATRIX_I_VP, GetWorldToViewMatrix(), 0); +#endif + + // Compute the view direction (world space) + float3 viewWS = GetWorldSpaceNormalizeViewDir(posInput.positionWS); + + // Apply normal bias with the magnitude dependent on the distance from the camera. + // Unfortunately, we only have access to the shading normal, which is less than ideal... + posInput.positionWS = camPosWS + (posInput.positionWS - camPosWS) * (1 - 0.001 * rcp(max(dot(normalData.normalWS, viewWS), FLT_EPS))); + deviceDepth = ComputeNormalizedDeviceCoordinatesWithZ(posInput.positionWS, UNITY_MATRIX_VP).z; + + // Ray March along our ray + float3 rayPos; + bool hit = RayMarch(posInput.positionWS, sampleDir, normalData.normalWS, posInput.positionSS, deviceDepth, killRay, rayPos); + + // If we had a hit, store the NDC position of the intersection point + if (hit) + { + // Note that we are using 'rayPos' from the penultimate iteration, rather than + // recompute it using the last value of 't', which would result in an overshoot. + // It also needs to be precisely at the center of the pixel to avoid artifacts. + float2 hitPositionNDC = floor(rayPos.xy) * _ScreenSize.zw + (0.5 * _ScreenSize.zw); // Should we precompute the half-texel bias? We seem to use it a lot. + _IndirectDiffuseHitPointTextureRW[COORD_TEXTURE2D_X(currentCoord)] = hitPositionNDC; + } +} + +// Input hit point texture that holds the NDC position if an intersection was found +TEXTURE2D_X(_IndirectDiffuseHitPointTexture); +// Depth buffer of the previous frame (full resolution) +TEXTURE2D_X(_HistoryDepthTexture); +// Output indirect diffuse texture +RW_TEXTURE2D_X(float4, _IndirectDiffuseTextureRW); + +[numthreads(INDIRECT_DIFFUSE_TILE_SIZE, INDIRECT_DIFFUSE_TILE_SIZE, 1)] +void REPROJECT_GLOBAL_ILLUMINATION(uint3 dispatchThreadId : SV_DispatchThreadID, uint2 groupThreadId : SV_GroupThreadID, uint2 groupId : SV_GroupID) +{ + UNITY_XR_ASSIGN_VIEW_INDEX(dispatchThreadId.z); + + // Compute the pixel position to process + uint2 currentCoord = groupId * INDIRECT_DIFFUSE_TILE_SIZE + groupThreadId; + +#if HALF_RES + // Fetch the mipoffset for the second mip (given that we are in half res) + int2 mipOffset = _DepthPyramidMipLevelOffsets[1]; + float deviceDepth = LOAD_TEXTURE2D_X(_DepthTexture, mipOffset + currentCoord).x; + + // Compute the full resolution pixel for the inputs that do not have a pyramid + uint2 fullResCoord = currentCoord * 2; +#else + // Fetch the depth of the current pixel + float deviceDepth = LOAD_TEXTURE2D_X(_DepthTexture, currentCoord).x; +#endif + + // Read the hit point ndc position to fetch + float2 hitPositionNDC = LOAD_TEXTURE2D_X(_IndirectDiffuseHitPointTexture, currentCoord).xy; + + // Grab the depth of the hit point + float hitPointDepth = LOAD_TEXTURE2D_X(_DepthTexture, hitPositionNDC * _ScreenSize.xy).x; + + // Flag that tracks if this ray lead to a valid result + bool invalid = false; + + // If this missed, we need to find something else to fallback on + if (hitPositionNDC.x > 1.0) + invalid = true; + + // Fetch the motion vector of the current target pixel + float2 motionVectorNDC; + DecodeMotionVector(SAMPLE_TEXTURE2D_X_LOD(_CameraMotionVectorsTexture, s_linear_clamp_sampler, min(hitPositionNDC, 1.0f - 0.5f * _ScreenSize.zw) * _RTHandleScale.xy, 0), motionVectorNDC); + + float2 prevFrameNDC = hitPositionNDC - motionVectorNDC; + float2 prevFrameUV = prevFrameNDC * _ColorPyramidUvScaleAndLimitPrevFrame.xy; + + // If the previous value to read was out of screen, this is invalid, needs a fallback + if ((prevFrameUV.x < 0) + || (prevFrameUV.x > _ColorPyramidUvScaleAndLimitPrevFrame.z) + || (prevFrameUV.y < 0) + || (prevFrameUV.y > _ColorPyramidUvScaleAndLimitPrevFrame.w)) + invalid = true; + + // Grab the depth of the hit point and reject the history buffer if the depth is too different + // TODO: Find a better metric + float hitPointHistoryDepth = LOAD_TEXTURE2D_X(_HistoryDepthTexture, prevFrameNDC * _ScreenSize.xy).x; + if (abs(hitPointHistoryDepth - hitPointDepth) > 0.01) + invalid = true; + + // Based on if the intersection was valid (or not, pick a source for the lighting) + float3 color = 0.0; + if (!invalid) + // The intersection was considered valid, we can read from the color pyramid + color = SAMPLE_TEXTURE2D_X_LOD(_ColorPyramidTexture, s_linear_clamp_sampler, prevFrameUV, 0).rgb; + + // TODO: Remove me when you can find where the nans come from + if (AnyIsNaN(color)) + color = 0.0f; + + // Convert the color to HSV + float3 hsvColor = RgbToHsv(color); + + // We need to clamp before leaving, this need to be exposed properly before clamping + // We only apply the clamp to the luminance + hsvColor.z = clamp(hsvColor.z * GetInversePreviousExposureMultiplier() * GetCurrentExposureMultiplier(), 0.0, _RaytracingIntensityClamp); + + // Convert back to the RGB space + color = HsvToRgb(hsvColor); + + // We are simply interested to know if the intersected pixel was moving, so we multiply it by a big number + // TODO: make this process not binary +#if HALF_RES + // Write the output to the target pixel + _IndirectDiffuseTextureRW[COORD_TEXTURE2D_X(currentCoord)] = float4(color / (1.0 + color), length(motionVectorNDC * 10000.0f)); +#else + // Write the output to the target pixel + _IndirectDiffuseTextureRW[COORD_TEXTURE2D_X(currentCoord)] = float4(color, length(motionVectorNDC * 10000.0f)); +#endif + +} \ No newline at end of file diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/ScreenSpaceGlobalIllumination.compute.meta b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/ScreenSpaceGlobalIllumination.compute.meta new file mode 100644 index 00000000000..b261cbec441 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/ScreenSpaceGlobalIllumination.compute.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 96170a954eb538b40a5ff369552c3629 +ComputeShaderImporter: + externalObjects: {} + currentAPIMask: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/ScreenSpaceGlobalIllumination.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/ScreenSpaceGlobalIllumination.cs new file mode 100644 index 00000000000..9a0d4ee6cd4 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/ScreenSpaceGlobalIllumination.cs @@ -0,0 +1,209 @@ +using UnityEngine.Experimental.Rendering; +using UnityEngine.Experimental.Rendering.HighDefinition; + +namespace UnityEngine.Rendering.HighDefinition +{ + public partial class HDRenderPipeline + { + // Buffers used for the evaluation + RTHandle m_IndirectDiffuseBuffer0 = null; + RTHandle m_IndirectDiffuseBuffer1 = null; + RTHandle m_IndirectDiffuseHitPointBuffer = null; + + // The set of kernels that we shall be using + int m_TraceGlobalIlluminationKernel; + int m_TraceGlobalIlluminationHalfKernel; + int m_ReprojectGlobalIlluminationKernel; + int m_ReprojectGlobalIlluminationHalfKernel; + int m_BilateralUpSampleColorTMKernel; + + // Temporal variables (to avoid allocation at runtime) + Vector4 halfScreenSize = new Vector4(0.0f, 0.0f, 0.0f, 0.0f); + Vector2 firstMipOffset = new Vector2(0.0f, 0.0f); + + void InitScreenSpaceGlobalIllumination() + { + if (m_Asset.currentPlatformRenderPipelineSettings.supportSSGI) + { + m_IndirectDiffuseBuffer0 = RTHandles.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, dimension: TextureXR.dimension, enableRandomWrite: true, useDynamicScale: true, useMipMap: false, autoGenerateMips: false, name: "IndirectDiffuseBuffer0"); + m_IndirectDiffuseBuffer1 = RTHandles.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, dimension: TextureXR.dimension, enableRandomWrite: true, useDynamicScale: true, useMipMap: false, autoGenerateMips: false, name: "IndirectDiffuseBuffer1"); + m_IndirectDiffuseHitPointBuffer = RTHandles.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R16G16_SFloat, dimension: TextureXR.dimension, enableRandomWrite: true, useDynamicScale: true, useMipMap: false, autoGenerateMips: false, name: "IndirectDiffuseHitBuffer"); + + // Grab the sets of shaders that we'll be using + ComputeShader ssGICS = m_Asset.renderPipelineResources.shaders.screenSpaceGlobalIlluminationCS; + ComputeShader bilateralUpsampleCS = m_Asset.renderPipelineResources.shaders.bilateralUpsampleCS; + + // Grab the set of kernels that we shall be using + m_TraceGlobalIlluminationKernel = ssGICS.FindKernel("TraceGlobalIllumination"); + m_TraceGlobalIlluminationHalfKernel = ssGICS.FindKernel("TraceGlobalIlluminationHalf"); + m_ReprojectGlobalIlluminationKernel = ssGICS.FindKernel("ReprojectGlobalIllumination"); + m_ReprojectGlobalIlluminationHalfKernel = ssGICS.FindKernel("ReprojectGlobalIlluminationHalf"); + m_BilateralUpSampleColorTMKernel = bilateralUpsampleCS.FindKernel("BilateralUpSampleColorTM"); + } + } + + void ReleaseScreenSpaceGlobalIllumination() + { + if (m_IndirectDiffuseBuffer0 != null) + RTHandles.Release(m_IndirectDiffuseBuffer0); + if (m_IndirectDiffuseBuffer1 != null) + RTHandles.Release(m_IndirectDiffuseBuffer1); + if (m_IndirectDiffuseHitPointBuffer != null) + RTHandles.Release(m_IndirectDiffuseHitPointBuffer); + } + + // This is shared between SSGI and RTGI + bool ValidIndirectDiffuseState(HDCamera hdCamera) + { + var settings = hdCamera.volumeStack.GetComponent(); + return m_Asset.currentPlatformRenderPipelineSettings.supportSSGI + && hdCamera.camera.cameraType != CameraType.Reflection + && hdCamera.frameSettings.IsEnabled(FrameSettingsField.SSGI) + && settings.enable.value; + } + + // Bind the indirect diffuse texture for the lightloop to read from it + void BindIndirectDiffuseTexture(CommandBuffer cmd) + { + cmd.SetGlobalTexture(HDShaderIDs._IndirectDiffuseTexture, m_IndirectDiffuseBuffer0); + } + + // If there is no SSGI, bind a black 1x1 texture + void BindBlackIndirectDiffuseTexture(CommandBuffer cmd) + { + cmd.SetGlobalTexture(HDShaderIDs._IndirectDiffuseTexture, TextureXR.GetBlackTexture()); + } + + void RenderSSGI(HDCamera hdCamera, CommandBuffer cmd, ScriptableRenderContext renderContext, int frameCount) + { + // Grab the global illumination volume component + GlobalIllumination giSettings = hdCamera.volumeStack.GetComponent(); + + // Grab the noise texture manager + BlueNoise blueNoise = GetBlueNoiseManager(); + + // Grab the shaders we shall be using + ComputeShader ssGICS = m_Asset.renderPipelineResources.shaders.screenSpaceGlobalIlluminationCS; + + // Evaluate the dispatch parameters + int texWidth, texHeight; + if (giSettings.fullResolutionSS) + { + texWidth = hdCamera.actualWidth; + texHeight = hdCamera.actualHeight; + halfScreenSize.Set(texWidth * 0.5f, texHeight * 0.5f, 2.0f / texWidth, 2.0f / texHeight); + } + else + { + texWidth = hdCamera.actualWidth / 2; + texHeight = hdCamera.actualHeight / 2; + halfScreenSize.Set(texWidth, texHeight, 1.0f / texWidth, 1.0f / texHeight); + } + int areaTileSize = 8; + int numTilesXHR = (texWidth + (areaTileSize - 1)) / areaTileSize; + int numTilesYHR = (texHeight + (areaTileSize - 1)) / areaTileSize; + + // Based on if we are doing it in half resolution or full, we need to define initial and final buffer to avoid a useless blit + RTHandle buffer0, buffer1; + if (!giSettings.fullResolutionSS) + { + buffer0 = m_IndirectDiffuseBuffer0; + buffer1 = m_IndirectDiffuseBuffer1; + } + else + { + buffer0 = m_IndirectDiffuseBuffer1; + buffer1 = m_IndirectDiffuseBuffer0; + } + + using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.SsgiPass))) + { + // Fetch the right tracing kernel + int currentKernel = giSettings.fullResolutionSS ? m_TraceGlobalIlluminationKernel : m_TraceGlobalIlluminationHalfKernel; + + // Inject all the input scalars + float n = hdCamera.camera.nearClipPlane; + float f = hdCamera.camera.farClipPlane; + float thickness = giSettings.depthBufferThickness.value; + float thicknessScale = 1.0f / (1.0f + thickness); + float thicknessBias = -n / (f - n) * (thickness * thicknessScale); + cmd.SetComputeFloatParam(ssGICS, HDShaderIDs._IndirectDiffuseThicknessScale, thicknessScale); + cmd.SetComputeFloatParam(ssGICS, HDShaderIDs._IndirectDiffuseThicknessBias, thicknessBias); + cmd.SetComputeIntParam(ssGICS, HDShaderIDs._IndirectDiffuseSteps, giSettings.raySteps); + cmd.SetComputeFloatParam(ssGICS, HDShaderIDs._IndirectDiffuseMaximalRadius, giSettings.maximalRadius); + // Inject half screen size if required + if (!giSettings.fullResolutionSS) + cmd.SetComputeVectorParam(ssGICS, HDShaderIDs._HalfScreenSize, halfScreenSize); + + // Inject the ray-tracing sampling data + blueNoise.BindDitheredRNGData1SPP(cmd); + + // Inject all the input textures/buffers + cmd.SetComputeTextureParam(ssGICS, currentKernel, HDShaderIDs._DepthTexture, m_SharedRTManager.GetDepthTexture()); + cmd.SetComputeTextureParam(ssGICS, currentKernel, HDShaderIDs._NormalBufferTexture, m_SharedRTManager.GetNormalBuffer()); + cmd.SetComputeTextureParam(ssGICS, currentKernel, HDShaderIDs._IndirectDiffuseHitPointTextureRW, m_IndirectDiffuseHitPointBuffer); + var info = m_SharedRTManager.GetDepthBufferMipChainInfo(); + cmd.SetComputeBufferParam(ssGICS, currentKernel, HDShaderIDs._DepthPyramidMipLevelOffsets, info.GetOffsetBufferData(m_DepthPyramidMipLevelOffsetsBuffer)); + cmd.SetGlobalBuffer(HDShaderIDs.g_vLightListGlobal, m_TileAndClusterData.lightList); + + // Do the ray marching + cmd.DispatchCompute(ssGICS, currentKernel, numTilesXHR, numTilesYHR, hdCamera.viewCount); + + // Fetch the right kernel to use + currentKernel = giSettings.fullResolutionSS ? m_ReprojectGlobalIlluminationKernel : m_ReprojectGlobalIlluminationHalfKernel; + + // Inject all the input scalars + cmd.SetComputeFloatParam(ssGICS, HDShaderIDs._RaytracingIntensityClamp, giSettings.clampValueSS); + cmd.SetComputeVectorParam(ssGICS, HDShaderIDs._ColorPyramidUvScaleAndLimitPrevFrame, HDUtils.ComputeViewportScaleAndLimit(hdCamera.historyRTHandleProperties.previousViewportSize, hdCamera.historyRTHandleProperties.previousRenderTargetSize)); + + // Bind all the input buffers + cmd.SetComputeTextureParam(ssGICS, currentKernel, HDShaderIDs._DepthTexture, m_SharedRTManager.GetDepthStencilBuffer()); + cmd.SetComputeTextureParam(ssGICS, currentKernel, HDShaderIDs._NormalBufferTexture, m_SharedRTManager.GetNormalBuffer()); + cmd.SetComputeTextureParam(ssGICS, currentKernel, HDShaderIDs._IndirectDiffuseHitPointTexture, m_IndirectDiffuseHitPointBuffer); + var previousColorPyramid = hdCamera.GetPreviousFrameRT((int)HDCameraFrameHistoryType.ColorBufferMipChain); + cmd.SetComputeTextureParam(ssGICS, currentKernel, HDShaderIDs._ColorPyramidTexture, previousColorPyramid != null ? previousColorPyramid : TextureXR.GetBlackTexture()); + var historyDepthBuffer = hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.Depth); + cmd.SetComputeTextureParam(ssGICS, currentKernel, HDShaderIDs._HistoryDepthTexture, historyDepthBuffer != null ? historyDepthBuffer : TextureXR.GetBlackTexture()); + cmd.SetComputeBufferParam(ssGICS, currentKernel, HDShaderIDs._DepthPyramidMipLevelOffsets, info.GetOffsetBufferData(m_DepthPyramidMipLevelOffsetsBuffer)); + + // Bind the output texture + cmd.SetComputeTextureParam(ssGICS, currentKernel, HDShaderIDs._IndirectDiffuseTextureRW, buffer1); + + // Do the reprojection + cmd.DispatchCompute(ssGICS, currentKernel, numTilesXHR, numTilesYHR, hdCamera.viewCount); + + // Do the denoising part + SSGIDenoiser ssgiDenoiser = GetSSGIDenoiser(); + ssgiDenoiser.Denoise(cmd, hdCamera, buffer1, buffer0, halfResolution: !giSettings.fullResolutionSS); + + // If this was a half resolution effect, we still have to upscale it + if (!giSettings.fullResolutionSS) + { + ComputeShader bilateralUpsampleCS = m_Asset.renderPipelineResources.shaders.bilateralUpsampleCS; + + // Re-evaluate the dispatch parameters (we are evaluating the upsample in full resolution) + numTilesXHR = (hdCamera.actualWidth + (areaTileSize - 1)) / areaTileSize; + numTilesYHR = (hdCamera.actualHeight + (areaTileSize - 1)) / areaTileSize; + + // Inject the input scalars + cmd.SetComputeVectorParam(bilateralUpsampleCS, HDShaderIDs._HalfScreenSize, halfScreenSize); + firstMipOffset.Set(HDShadowUtils.Asfloat((uint)info.mipLevelOffsets[1].x), HDShadowUtils.Asfloat((uint)info.mipLevelOffsets[1].y)); + cmd.SetComputeVectorParam(bilateralUpsampleCS, HDShaderIDs._DepthPyramidFirstMipLevelOffset, firstMipOffset); + + // Inject all the input buffers + cmd.SetComputeTextureParam(bilateralUpsampleCS, m_BilateralUpSampleColorTMKernel, HDShaderIDs._DepthTexture, m_SharedRTManager.GetDepthTexture()); + cmd.SetComputeTextureParam(bilateralUpsampleCS, m_BilateralUpSampleColorTMKernel, HDShaderIDs._LowResolutionTexture, buffer1); + cmd.SetComputeBufferParam(bilateralUpsampleCS, m_BilateralUpSampleColorTMKernel, HDShaderIDs._DepthPyramidMipLevelOffsets, info.GetOffsetBufferData(m_DepthPyramidMipLevelOffsetsBuffer)); + + // Inject the output textures + cmd.SetComputeTextureParam(bilateralUpsampleCS, m_BilateralUpSampleColorTMKernel, HDShaderIDs._OutputUpscaledTexture, buffer0); + + // Upscale the buffer to full resolution + cmd.DispatchCompute(bilateralUpsampleCS, m_BilateralUpSampleColorTMKernel, numTilesXHR, numTilesYHR, hdCamera.viewCount); + } + + (RenderPipelineManager.currentPipeline as HDRenderPipeline).PushFullScreenDebugTexture(hdCamera, cmd, m_IndirectDiffuseBuffer0, FullScreenDebugMode.ScreenSpaceGlobalIllumination); + } + } + } +} diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/ScreenSpaceGlobalIllumination.cs.meta b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/ScreenSpaceGlobalIllumination.cs.meta new file mode 100644 index 00000000000..ee4112dc252 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/ScreenSpaceGlobalIllumination.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8e106aaaafa6ea1449c03db0a6b59eef +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl index 65e1815119f..efd7a3a5096 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl @@ -42,8 +42,8 @@ void InitBuiltinData(PositionInputs posInput, float alpha, float3 normalWS, floa builtinData.renderingLayers = _EnableLightLayers ? asuint(unity_RenderingLayer.x) : DEFAULT_LIGHT_LAYERS; // We only want to read the screen space buffer that holds the indirect diffuse signal if this is not a transparent surface -#if RAYTRACING_ENABLED && (SHADERPASS == SHADERPASS_GBUFFER || SHADERPASS == SHADERPASS_FORWARD) && !defined(_SURFACE_TYPE_TRANSPARENT) - if (_RaytracedIndirectDiffuse == 1) +#if RAYTRACING_ENABLED && ((SHADERPASS == SHADERPASS_GBUFFER) || (SHADERPASS == SHADERPASS_FORWARD)) && !defined(_SURFACE_TYPE_TRANSPARENT) + if (_UseIndirectDiffuse == RAY_TRACED_INDIRECT_DIFFUSE_FLAG) { #if SHADERPASS == SHADERPASS_GBUFFER // Incase we shall be using raytraced indirect diffuse, we want to make sure to not add the GBuffer because that will be happening later in the pipeline diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl index dd646cbe1eb..9fc292fcfee 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl @@ -2005,6 +2005,7 @@ void PostEvaluateBSDF( LightLoopContext lightLoopContext, #else GetScreenSpaceAmbientOcclusionMultibounce(posInput.positionSS, preLightData.NdotV, bsdfData.perceptualRoughness, bsdfData.ambientOcclusion, bsdfData.specularOcclusion, bsdfData.diffuseColor, bsdfData.fresnel0, aoFactor); #endif + ApplyAmbientOcclusionFactor(aoFactor, builtinData, lighting); // Subsurface scattering mode diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.shader index 0e1236c3e1f..2e282274290 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.shader @@ -540,6 +540,8 @@ Shader "HDRP/Unlit" #define SHADOW_LOW #pragma multi_compile _ TRANSPARENT_COLOR_SHADOW + + #define SHADERPASS SHADERPASS_RAYTRACING_VISIBILITY #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingMacros.hlsl" diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCameraFrameHistoryType.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCameraFrameHistoryType.cs index 47b2c979f1b..08a16af16a0 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCameraFrameHistoryType.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCameraFrameHistoryType.cs @@ -19,6 +19,8 @@ public enum HDCameraFrameHistoryType Normal, /// Depth buffer. Depth, + /// Mip one of the depth buffer . + Depth1, /// Ambient Occlusion buffer. AmbientOcclusion, /// Ray traced ambient occlusion buffer. diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/GlobalLightingQualitySettings.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/GlobalLightingQualitySettings.cs index d9925114bbd..f7bacf1b677 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/GlobalLightingQualitySettings.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/GlobalLightingQualitySettings.cs @@ -42,6 +42,31 @@ internal GlobalLightingQualitySettings() SSRMaxRaySteps[(int)ScalableSettingLevelParameter.Level.Low] = 16; SSRMaxRaySteps[(int)ScalableSettingLevelParameter.Level.Medium] = 32; SSRMaxRaySteps[(int)ScalableSettingLevelParameter.Level.High] = 64; + + /* Screen Space Global Illumination */ + SSGIRaySteps[(int)ScalableSettingLevelParameter.Level.Low] = 24; + SSGIRaySteps[(int)ScalableSettingLevelParameter.Level.Medium] = 32; + SSGIRaySteps[(int)ScalableSettingLevelParameter.Level.High] = 64; + + SSGIResolution[(int)ScalableSettingLevelParameter.Level.Low] = false; + SSGIResolution[(int)ScalableSettingLevelParameter.Level.Medium] = true; + SSGIResolution[(int)ScalableSettingLevelParameter.Level.High] = true; + + SSGIRadius[(int)ScalableSettingLevelParameter.Level.Low] = 0.5f; + SSGIRadius[(int)ScalableSettingLevelParameter.Level.Medium] = 3.0f; + SSGIRadius[(int)ScalableSettingLevelParameter.Level.High] = 5.0f; + + SSGIFullResolution[(int)ScalableSettingLevelParameter.Level.Low] = false; + SSGIFullResolution[(int)ScalableSettingLevelParameter.Level.Medium] = true; + SSGIFullResolution[(int)ScalableSettingLevelParameter.Level.High] = true; + + SSGIClampValue[(int)ScalableSettingLevelParameter.Level.Low] = 0.5f; + SSGIClampValue[(int)ScalableSettingLevelParameter.Level.Medium] = 0.8f; + SSGIClampValue[(int)ScalableSettingLevelParameter.Level.High] = 1.0f; + + SSGIFilterRadius[(int)ScalableSettingLevelParameter.Level.Low] = 2; + SSGIFilterRadius[(int)ScalableSettingLevelParameter.Level.Medium] = 5; + SSGIFilterRadius[(int)ScalableSettingLevelParameter.Level.High] = 7; } internal static GlobalLightingQualitySettings NewDefault() => new GlobalLightingQualitySettings(); @@ -66,6 +91,20 @@ internal GlobalLightingQualitySettings() /// Maximum number of rays for Screen Space Reflection for each quality level. public int[] SSRMaxRaySteps = new int[s_QualitySettingCount]; + // Screen Space Global Illumination + [System.NonSerialized] + public int[] SSGIRaySteps = new int[s_QualitySettingCount]; + [System.NonSerialized] + public bool[] SSGIResolution = new bool[s_QualitySettingCount]; + [System.NonSerialized] + public float[] SSGIRadius = new float[s_QualitySettingCount]; + [System.NonSerialized] + public bool[] SSGIFullResolution = new bool[s_QualitySettingCount]; + [System.NonSerialized] + public float[] SSGIClampValue = new float[s_QualitySettingCount]; + [System.NonSerialized] + public int[] SSGIFilterRadius = new int[s_QualitySettingCount]; + // TODO: Volumetric fog quality // TODO: Shadows. This needs to be discussed further as there is an idiosyncracy here as we have different level of quality settings, diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDProfileId.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDProfileId.cs index a3e989d5c53..73b9af844f4 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDProfileId.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDProfileId.cs @@ -37,6 +37,7 @@ internal enum HDProfileId SsrTracing, SsrReprojection, PrepareForTransparentSsr, + SsgiPass, ForwardEmissive, ForwardOpaque, ForwardOpaqueDebug, diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs index a437a07dbd1..09de756b62f 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -519,6 +519,8 @@ public HDRenderPipeline(HDRenderPipelineAsset asset, HDRenderPipelineAsset defau m_AmbientOcclusionSystem.InitRaytracing(this); } + // Initialize the SSGI structures + InitScreenSpaceGlobalIllumination(); // Initialize screen space shadows InitializeScreenSpaceShadows(); @@ -932,6 +934,7 @@ protected override void Dispose(bool disposing) base.Dispose(disposing); ReleaseScreenSpaceShadows(); + ReleaseScreenSpaceGlobalIllumination(); if (m_RayTracingSupported) { @@ -940,8 +943,8 @@ protected override void Dispose(bool disposing) ReleaseRayTracedIndirectDiffuse(); ReleaseRayTracedReflections(); ReleasePathTracing(); - ReleaseRayTracingManager(); } + ReleaseRayTracingManager(); m_DebugDisplaySettings.UnregisterDebug(); CleanupLightLoop(); @@ -1121,13 +1124,13 @@ void UpdateShaderVariablesGlobalCB(HDCamera hdCamera, CommandBuffer cmd) ScreenSpaceReflection settings = hdCamera.volumeStack.GetComponent(); bool usesRaytracedReflections = hdCamera.frameSettings.IsEnabled(FrameSettingsField.RayTracing) && settings.rayTracing.value; m_ShaderVariablesGlobalCB._UseRayTracedReflections = usesRaytracedReflections ? 1 : 0; - m_ShaderVariablesGlobalCB._RaytracedIndirectDiffuse = ValidIndirectDiffuseState(hdCamera) ? 1 : 0; + m_ShaderVariablesGlobalCB._UseIndirectDiffuse = ValidIndirectDiffuseState(hdCamera) ? (RayTracedIndirectDiffuseState(hdCamera) ? LightDefinitions.k_RayTracedIndirectDiffuseFlag : LightDefinitions.k_ScreenSpaceIndirectDiffuseFlag) : LightDefinitions.k_IndirectDiffuseFlagOff; m_ShaderVariablesGlobalCB._EnableRecursiveRayTracing = recursiveSettings.enable.value ? 1u : 0u; } else { m_ShaderVariablesGlobalCB._UseRayTracedReflections = 0; - m_ShaderVariablesGlobalCB._RaytracedIndirectDiffuse = 0; + m_ShaderVariablesGlobalCB._UseIndirectDiffuse = ValidIndirectDiffuseState(hdCamera) ? LightDefinitions.k_ScreenSpaceIndirectDiffuseFlag : LightDefinitions.k_IndirectDiffuseFlagOff; m_ShaderVariablesGlobalCB._EnableRecursiveRayTracing = 0; } @@ -2384,7 +2387,32 @@ void AsyncSSAODispatch(CommandBuffer c, HDGPUAsyncTaskParams a) bool validIndirectDiffuse = ValidIndirectDiffuseState(hdCamera); if (validIndirectDiffuse) { - RenderIndirectDiffuse(hdCamera, cmd, renderContext, m_FrameCount); + if (RayTracedIndirectDiffuseState(hdCamera)) + { + RenderRayTracedIndirectDiffuse(hdCamera, cmd, renderContext, m_FrameCount); + } + else + { + RenderSSGI(hdCamera, cmd, renderContext, m_FrameCount); + BindIndirectDiffuseTexture(cmd); + } + } + else + { + BindBlackIndirectDiffuseTexture(cmd); + } + } + else + { + bool validIndirectDiffuse = ValidIndirectDiffuseState(hdCamera); + if (validIndirectDiffuse) + { + RenderSSGI(hdCamera, cmd, renderContext, m_FrameCount); + BindIndirectDiffuseTexture(cmd); + } + else + { + BindBlackIndirectDiffuseTexture(cmd); } } @@ -4864,6 +4892,7 @@ void SendGeometryGraphicsBuffers(CommandBuffer cmd, HDCamera hdCamera) Texture normalBuffer = null; bool needDepthBuffer = false; Texture depthBuffer = null; + Texture depthBuffer1 = null; HDAdditionalCameraData acd = null; hdCamera.camera.TryGetComponent(out acd); @@ -4877,7 +4906,7 @@ void SendGeometryGraphicsBuffers(CommandBuffer cmd, HDCamera hdCamera) VFXCameraBufferTypes neededVFXBuffers = VFXManager.IsCameraBufferNeeded(hdCamera.camera); needNormalBuffer |= ((neededVFXBuffers & VFXCameraBufferTypes.Normal) != 0 || (externalAccess & HDAdditionalCameraData.BufferAccessType.Normal) != 0); needDepthBuffer |= ((neededVFXBuffers & VFXCameraBufferTypes.Depth) != 0 || (externalAccess & HDAdditionalCameraData.BufferAccessType.Depth) != 0); - if (hdCamera.frameSettings.IsEnabled(FrameSettingsField.RayTracing) && GetRayTracingState()) + if (hdCamera.frameSettings.IsEnabled(FrameSettingsField.RayTracing) && GetRayTracingState() || ValidIndirectDiffuseState(hdCamera)) { needNormalBuffer = true; needDepthBuffer = true; @@ -4909,11 +4938,20 @@ RTHandle Allocator(string id, int frameIndex, RTHandleSystem rtHandleSystem) return rtHandleSystem.Alloc(Vector2.one, TextureXR.slices, colorFormat: mainDepthBuffer.rt.graphicsFormat, dimension: TextureXR.dimension, enableRandomWrite: mainDepthBuffer.rt.enableRandomWrite, name: $"Depth History Buffer" ); } - depthBuffer = hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.Depth) ?? hdCamera.AllocHistoryFrameRT((int)HDCameraFrameHistoryType.Depth, Allocator, 1); for (int i = 0; i < hdCamera.viewCount; i++) cmd.CopyTexture(mainDepthBuffer, i, 0, 0, 0, hdCamera.actualWidth, hdCamera.actualHeight, depthBuffer, i, 0, 0, 0); + + RTHandle Allocator1(string id, int frameIndex, RTHandleSystem rtHandleSystem) + { + return rtHandleSystem.Alloc(Vector2.one * 0.5f, TextureXR.slices, colorFormat: mainDepthBuffer.rt.graphicsFormat, dimension: TextureXR.dimension, enableRandomWrite: mainDepthBuffer.rt.enableRandomWrite, name: $"Depth History Buffer Mip 1" + ); + } + var mipchainInfo = m_SharedRTManager.GetDepthBufferMipChainInfo(); + depthBuffer1 = hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.Depth1) ?? hdCamera.AllocHistoryFrameRT((int)HDCameraFrameHistoryType.Depth1, Allocator1, 1); + for (int i = 0; i < hdCamera.viewCount; i++) + cmd.CopyTexture(mainDepthBuffer, i, 0, 0, 0, hdCamera.actualWidth / 2, hdCamera.actualHeight / 2, depthBuffer1, i, 0, 0, 0); } // Send buffers to client. diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs index 91fc137cfe6..51bb0335eaa 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs @@ -222,6 +222,7 @@ static class HDShaderIDs public static readonly int unity_OrthoParams = Shader.PropertyToID("unity_OrthoParams"); public static readonly int _InvProjParam = Shader.PropertyToID("_InvProjParam"); public static readonly int _ScreenSize = Shader.PropertyToID("_ScreenSize"); + public static readonly int _HalfScreenSize = Shader.PropertyToID("_HalfScreenSize"); public static readonly int _ScreenParams = Shader.PropertyToID("_ScreenParams"); public static readonly int _RTHandleScale = Shader.PropertyToID("_RTHandleScale"); public static readonly int _RTHandleScaleHistory = Shader.PropertyToID("_RTHandleScaleHistory"); @@ -303,6 +304,8 @@ static class HDShaderIDs public static readonly int _SsrHitPointTexture = Shader.PropertyToID("_SsrHitPointTexture"); public static readonly int _SsrClearCoatMaskTexture = Shader.PropertyToID("_SsrClearCoatMaskTexture"); public static readonly int _DepthPyramidMipLevelOffsets = Shader.PropertyToID("_DepthPyramidMipLevelOffsets"); + public static readonly int _DepthPyramidFirstMipLevelOffset = Shader.PropertyToID("_DepthPyramidFirstMipLevelOffset"); + // Still used by ray tracing. public static readonly int _SsrStencilBit = Shader.PropertyToID("_SsrStencilBit"); @@ -569,9 +572,19 @@ static class HDShaderIDs // Indirect diffuse public static readonly int _IndirectDiffuseTexture = Shader.PropertyToID("_IndirectDiffuseTexture"); public static readonly int _IndirectDiffuseTextureRW = Shader.PropertyToID("_IndirectDiffuseTextureRW"); - public static readonly int _IndirectDiffuseHitPointTextureRW = Shader.PropertyToID("_IndirectDiffuseHitPointTextureRW"); public static readonly int _UpscaledIndirectDiffuseTextureRW = Shader.PropertyToID("_UpscaledIndirectDiffuseTextureRW"); - + public static readonly int _IndirectDiffuseHitPointTexture = Shader.PropertyToID("_IndirectDiffuseHitPointTexture"); + public static readonly int _IndirectDiffuseHitPointTextureRW = Shader.PropertyToID("_IndirectDiffuseHitPointTextureRW"); + public static readonly int _IndirectDiffuseThicknessScale = Shader.PropertyToID("_IndirectDiffuseThicknessScale"); + public static readonly int _IndirectDiffuseThicknessBias = Shader.PropertyToID("_IndirectDiffuseThicknessBias"); + public static readonly int _IndirectDiffuseSteps = Shader.PropertyToID("_IndirectDiffuseSteps"); + public static readonly int _IndirectDiffuseMaximalRadius = Shader.PropertyToID("_IndirectDiffuseMaximalRadius"); + public static readonly int _InputNoisyBuffer = Shader.PropertyToID("_InputNoisyBuffer"); + public static readonly int _OutputFilteredBuffer = Shader.PropertyToID("_OutputFilteredBuffer"); + public static readonly int _LowResolutionTexture = Shader.PropertyToID("_LowResolutionTexture"); + public static readonly int _OutputUpscaledTexture = Shader.PropertyToID("_OutputUpscaledTexture"); + public static readonly int _IndirectDiffuseSpatialFilter = Shader.PropertyToID("_IndirectDiffuseSpatialFilter"); + // Deferred Lighting public static readonly int _RaytracingLitBufferRW = Shader.PropertyToID("_RaytracingLitBufferRW"); public static readonly int _RaytracingDiffuseRay = Shader.PropertyToID("_RaytracingDiffuseRay"); diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingIndirectDiffuse.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingIndirectDiffuse.cs index 740f1e1ef71..bf6a56d012f 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingIndirectDiffuse.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingIndirectDiffuse.cs @@ -5,28 +5,23 @@ namespace UnityEngine.Rendering.HighDefinition { public partial class HDRenderPipeline { - // Buffers used for the evaluation - RTHandle m_IndirectDiffuseBuffer = null; - // String values const string m_RayGenIndirectDiffuseIntegrationName = "RayGenIntegration"; - const string m_RayGenIndirectDiffuseFullResName = "RayGenFullRes"; - const string m_MissIndirectDiffuseName = "MissShaderIndirectDiffuse"; - const string m_ClosestHitIndirectDiffuseName = "ClosestHitMain"; void InitRayTracedIndirectDiffuse() { - m_IndirectDiffuseBuffer = RTHandles.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, dimension: TextureXR.dimension, enableRandomWrite: true, useDynamicScale: true, useMipMap: false, autoGenerateMips: false, name: "IndirectDiffuseBuffer"); } void ReleaseRayTracedIndirectDiffuse() { - RTHandles.Release(m_IndirectDiffuseBuffer); } - void BindIndirectDiffuseTexture(CommandBuffer cmd) + bool RayTracedIndirectDiffuseState(HDCamera hdCamera) { - cmd.SetGlobalTexture(HDShaderIDs._IndirectDiffuseTexture, m_IndirectDiffuseBuffer); + var settings = hdCamera.volumeStack.GetComponent(); + return ValidIndirectDiffuseState(hdCamera) + && settings.rayTracing.value + && hdCamera.frameSettings.IsEnabled(FrameSettingsField.RayTracing); } RTHandle IndirectDiffuseHistoryBufferAllocatorFunction(string viewName, int frameIndex, RTHandleSystem rtHandleSystem) @@ -35,23 +30,11 @@ RTHandle IndirectDiffuseHistoryBufferAllocatorFunction(string viewName, int fram enableRandomWrite: true, useMipMap: false, autoGenerateMips: false, name: string.Format("IndirectDiffuseHistoryBuffer{0}", frameIndex)); } - - RTHandle GetIndirectDiffuseTexture() - { - return m_IndirectDiffuseBuffer; - } - - bool ValidIndirectDiffuseState(HDCamera hdCamera) - { - // First thing to check is: Do we have a valid ray-tracing environment? - var settings = hdCamera.volumeStack.GetComponent(); - return !(!hdCamera.frameSettings.IsEnabled(FrameSettingsField.RayTracing) || !settings.rayTracing.value); - } - - void RenderIndirectDiffuse(HDCamera hdCamera, CommandBuffer cmd, ScriptableRenderContext renderContext, int frameCount) + + void RenderRayTracedIndirectDiffuse(HDCamera hdCamera, CommandBuffer cmd, ScriptableRenderContext renderContext, int frameCount) { - // If we are not supposed to evaluate the indirect diffuse term, quit right away - if (!ValidIndirectDiffuseState(hdCamera)) + // If we are not supposed to evaluate the ray traced indirect diffuse term, quit right away + if (!RayTracedIndirectDiffuseState(hdCamera)) return; GlobalIllumination giSettings = hdCamera.volumeStack.GetComponent(); @@ -82,6 +65,11 @@ void RenderIndirectDiffuse(HDCamera hdCamera, CommandBuffer cmd, ScriptableRende RenderIndirectDiffusePerformance(hdCamera, cmd, renderContext, frameCount); } + PropagateIndirectDiffuseData(hdCamera, cmd, renderContext, frameCount); + } + + void PropagateIndirectDiffuseData(HDCamera hdCamera, CommandBuffer cmd, ScriptableRenderContext renderContext, int frameCount) + { // Bind the indirect diffuse texture (for forward materials) BindIndirectDiffuseTexture(cmd); @@ -94,11 +82,11 @@ void RenderIndirectDiffuse(HDCamera hdCamera, CommandBuffer cmd, ScriptableRende int indirectDiffuseKernel = indirectDiffuseCS.FindKernel("IndirectDiffuseAccumulation"); // Bind the source texture - cmd.SetComputeTextureParam(indirectDiffuseCS, indirectDiffuseKernel, HDShaderIDs._IndirectDiffuseTexture, m_IndirectDiffuseBuffer); + cmd.SetComputeTextureParam(indirectDiffuseCS, indirectDiffuseKernel, HDShaderIDs._IndirectDiffuseTexture, m_IndirectDiffuseBuffer0); // Bind the output texture cmd.SetComputeTextureParam(indirectDiffuseCS, indirectDiffuseKernel, HDShaderIDs._GBufferTexture[0], m_GbufferManager.GetBuffer(0)); - cmd.SetComputeTextureParam(indirectDiffuseCS, indirectDiffuseKernel, HDShaderIDs._GBufferTexture[3], m_GbufferManager.GetBuffer(3)); + cmd.SetComputeTextureParam(indirectDiffuseCS, indirectDiffuseKernel, HDShaderIDs._GBufferTextureRW[3], m_GbufferManager.GetBuffer(3)); // Evaluate the dispatch parameters int areaTileSize = 8; @@ -109,7 +97,7 @@ void RenderIndirectDiffuse(HDCamera hdCamera, CommandBuffer cmd, ScriptableRende cmd.DispatchCompute(indirectDiffuseCS, indirectDiffuseKernel, numTilesX, numTilesY, hdCamera.viewCount); } - (RenderPipelineManager.currentPipeline as HDRenderPipeline).PushFullScreenDebugTexture(hdCamera, cmd, m_IndirectDiffuseBuffer, FullScreenDebugMode.RayTracedGlobalIllumination); + (RenderPipelineManager.currentPipeline as HDRenderPipeline).PushFullScreenDebugTexture(hdCamera, cmd, m_IndirectDiffuseBuffer0, FullScreenDebugMode.ScreenSpaceGlobalIllumination); } DeferredLightingRTParameters PrepareIndirectDiffuseDeferredLightingRTParameters(HDCamera hdCamera) @@ -212,7 +200,7 @@ void RenderIndirectDiffusePerformance(HDCamera hdCamera, CommandBuffer cmd, Scri // Prepare the components for the deferred lighting DeferredLightingRTParameters deferredParamters = PrepareIndirectDiffuseDeferredLightingRTParameters(hdCamera); - DeferredLightingRTResources deferredResources = PrepareDeferredLightingRTResources(hdCamera, directionBuffer, m_IndirectDiffuseBuffer); + DeferredLightingRTResources deferredResources = PrepareDeferredLightingRTResources(hdCamera, directionBuffer, m_IndirectDiffuseBuffer0); // Evaluate the deferred lighting RenderRaytracingDeferredLighting(cmd, deferredParamters, deferredResources); @@ -226,7 +214,7 @@ void RenderIndirectDiffusePerformance(HDCamera hdCamera, CommandBuffer cmd, Scri // Inject all the parameters for the compute cmd.SetComputeTextureParam(indirectDiffuseCS, currentKernel, HDShaderIDs._DepthTexture, m_SharedRTManager.GetDepthStencilBuffer()); cmd.SetComputeTextureParam(indirectDiffuseCS, currentKernel, HDShaderIDs._NormalBufferTexture, m_SharedRTManager.GetNormalBuffer()); - cmd.SetComputeTextureParam(indirectDiffuseCS, currentKernel, HDShaderIDs._IndirectDiffuseTexture, m_IndirectDiffuseBuffer); + cmd.SetComputeTextureParam(indirectDiffuseCS, currentKernel, HDShaderIDs._IndirectDiffuseTexture, m_IndirectDiffuseBuffer0); cmd.SetComputeTextureParam(indirectDiffuseCS, currentKernel, HDShaderIDs._RaytracingDirectionBuffer, directionBuffer); cmd.SetComputeTextureParam(indirectDiffuseCS, currentKernel, HDShaderIDs._BlueNoiseTexture, blueNoise.textureArray16RGB); cmd.SetComputeTextureParam(indirectDiffuseCS, currentKernel, HDShaderIDs._UpscaledIndirectDiffuseTextureRW, intermediateBuffer1); @@ -246,7 +234,7 @@ void RenderIndirectDiffusePerformance(HDCamera hdCamera, CommandBuffer cmd, Scri cmd.DispatchCompute(indirectDiffuseCS, currentKernel, numTilesXHR, numTilesYHR, hdCamera.viewCount); // Copy the data back to the right buffer - HDUtils.BlitCameraTexture(cmd, intermediateBuffer1, m_IndirectDiffuseBuffer); + HDUtils.BlitCameraTexture(cmd, intermediateBuffer1, m_IndirectDiffuseBuffer0); // Denoise if required if (settings.denoise.value) @@ -321,7 +309,7 @@ void RenderIndirectDiffuseQuality(HDCamera hdCamera, CommandBuffer cmd, Scriptab RTHandle intermediateBuffer1 = GetRayTracingBuffer(InternalRayTracingBuffers.RGBA1); // Bind all the parameters for ray tracing - BindRayTracedIndirectDiffuseData(cmd, hdCamera, indirectDiffuseRT, giSettings, lightClusterSettings, rtSettings, m_IndirectDiffuseBuffer, intermediateBuffer1); + BindRayTracedIndirectDiffuseData(cmd, hdCamera, indirectDiffuseRT, giSettings, lightClusterSettings, rtSettings, m_IndirectDiffuseBuffer0, intermediateBuffer1); // Compute the actual resolution that is needed base on the quality int widthResolution = hdCamera.actualWidth; @@ -366,11 +354,11 @@ void DenoiseIndirectDiffuseBuffer(HDCamera hdCamera, CommandBuffer cmd, GlobalIl // Apply the temporal denoiser HDTemporalFilter temporalFilter = GetTemporalFilter(); - temporalFilter.DenoiseBuffer(cmd, hdCamera, m_IndirectDiffuseBuffer, indirectDiffuseHistoryHF, intermediateBuffer1, singleChannel: false, historyValidity: historyValidity); + temporalFilter.DenoiseBuffer(cmd, hdCamera, m_IndirectDiffuseBuffer0, indirectDiffuseHistoryHF, intermediateBuffer1, singleChannel: false, historyValidity: historyValidity); // Apply the first pass of our denoiser HDDiffuseDenoiser diffuseDenoiser = GetDiffuseDenoiser(); - diffuseDenoiser.DenoiseBuffer(cmd, hdCamera, intermediateBuffer1, m_IndirectDiffuseBuffer, settings.denoiserRadius.value, singleChannel: false, halfResolutionFilter: settings.halfResolutionDenoiser.value); + diffuseDenoiser.DenoiseBuffer(cmd, hdCamera, intermediateBuffer1, m_IndirectDiffuseBuffer0, settings.denoiserRadius.value, singleChannel: false, halfResolutionFilter: settings.halfResolutionDenoiser.value); // If the second pass is requested, do it otherwise blit if (settings.secondDenoiserPass.value) @@ -379,8 +367,8 @@ void DenoiseIndirectDiffuseBuffer(HDCamera hdCamera, CommandBuffer cmd, GlobalIl RTHandle indirectDiffuseHistoryLF = hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.RaytracedIndirectDiffuseLF) ?? hdCamera.AllocHistoryFrameRT((int)HDCameraFrameHistoryType.RaytracedIndirectDiffuseLF, IndirectDiffuseHistoryBufferAllocatorFunction, 1); - temporalFilter.DenoiseBuffer(cmd, hdCamera, m_IndirectDiffuseBuffer, indirectDiffuseHistoryLF, intermediateBuffer1, singleChannel: false, historyValidity: historyValidity); - diffuseDenoiser.DenoiseBuffer(cmd, hdCamera, intermediateBuffer1, m_IndirectDiffuseBuffer, settings.secondDenoiserRadius.value, singleChannel: false, halfResolutionFilter: settings.halfResolutionDenoiser.value); + temporalFilter.DenoiseBuffer(cmd, hdCamera, m_IndirectDiffuseBuffer0, indirectDiffuseHistoryLF, intermediateBuffer1, singleChannel: false, historyValidity: historyValidity); + diffuseDenoiser.DenoiseBuffer(cmd, hdCamera, intermediateBuffer1, m_IndirectDiffuseBuffer0, settings.secondDenoiserRadius.value, singleChannel: false, halfResolutionFilter: settings.halfResolutionDenoiser.value); } } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingManager.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingManager.cs index 427d0549ba6..7e2a2b0a07a 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingManager.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingManager.cs @@ -64,21 +64,23 @@ public partial class HDRenderPipeline { // Data used for runtime evaluation RayTracingAccelerationStructure m_CurrentRAS = new RayTracingAccelerationStructure(); - HDRaytracingLightCluster m_RayTracingLightCluster = new HDRaytracingLightCluster(); + HDRaytracingLightCluster m_RayTracingLightCluster; HDRayTracingLights m_RayTracingLights = new HDRayTracingLights(); bool m_ValidRayTracingState = false; bool m_ValidRayTracingCluster = false; bool m_ValidRayTracingClusterCulling = false; // Denoisers - HDTemporalFilter m_TemporalFilter = new HDTemporalFilter(); - HDSimpleDenoiser m_SimpleDenoiser = new HDSimpleDenoiser(); - HDDiffuseDenoiser m_DiffuseDenoiser = new HDDiffuseDenoiser(); - HDReflectionDenoiser m_ReflectionDenoiser = new HDReflectionDenoiser(); - HDDiffuseShadowDenoiser m_DiffuseShadowDenoiser = new HDDiffuseShadowDenoiser(); + HDTemporalFilter m_TemporalFilter; + HDSimpleDenoiser m_SimpleDenoiser; + HDDiffuseDenoiser m_DiffuseDenoiser; + HDReflectionDenoiser m_ReflectionDenoiser; + HDDiffuseShadowDenoiser m_DiffuseShadowDenoiser; + SSGIDenoiser m_SSGIDenoiser; + // Ray-count manager data - RayCountManager m_RayCountManager = new RayCountManager(); + RayCountManager m_RayCountManager; const int maxNumSubMeshes = 32; Dictionary m_RayTracingRendererReference = new Dictionary(); @@ -106,86 +108,58 @@ public partial class HDRenderPipeline RTHandle m_RayTracingIntermediateBufferRGBA2; RTHandle m_RayTracingIntermediateBufferRGBA3; - internal RTHandle GetRayTracingBuffer(InternalRayTracingBuffers bufferID) - { - switch (bufferID) - { - case InternalRayTracingBuffers.Distance: - return m_RayTracingDistanceBuffer; - case InternalRayTracingBuffers.Direction: - return m_RayTracingDirectionBuffer; - case InternalRayTracingBuffers.R0: - return m_RayTracingIntermediateBufferR0; - case InternalRayTracingBuffers.R1: - return m_RayTracingIntermediateBufferR1; - case InternalRayTracingBuffers.RG0: - return m_RayTracingIntermediateBufferRG0; - case InternalRayTracingBuffers.RG1: - return m_RayTracingIntermediateBufferRG1; - case InternalRayTracingBuffers.RGBA0: - return m_RayTracingIntermediateBufferRGBA0; - case InternalRayTracingBuffers.RGBA1: - return m_RayTracingIntermediateBufferRGBA1; - case InternalRayTracingBuffers.RGBA2: - return m_RayTracingIntermediateBufferRGBA2; - case InternalRayTracingBuffers.RGBA3: - return m_RayTracingIntermediateBufferRGBA3; - default: - return null; - } - } - internal void InitRayTracingManager() { - // Init the denoisers - m_TemporalFilter.Init(m_Asset.renderPipelineRayTracingResources, m_SharedRTManager, this); - m_SimpleDenoiser.Init(m_Asset.renderPipelineRayTracingResources, m_SharedRTManager, this); - m_DiffuseDenoiser.Init(m_Asset.renderPipelineResources, m_Asset.renderPipelineRayTracingResources, m_SharedRTManager, this); - m_ReflectionDenoiser.Init(m_Asset.renderPipelineRayTracingResources, m_SharedRTManager, this); - m_DiffuseShadowDenoiser.Init(m_Asset.renderPipelineRayTracingResources, m_SharedRTManager, this); - // Init the ray count manager + m_RayCountManager = new RayCountManager(); m_RayCountManager.Init(m_Asset.renderPipelineRayTracingResources); // Build the light cluster + m_RayTracingLightCluster = new HDRaytracingLightCluster(); m_RayTracingLightCluster.Initialize(this); - - // Allocate the direction and instance buffers - m_RayTracingDirectionBuffer = RTHandles.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, dimension: TextureXR.dimension, enableRandomWrite: true, useDynamicScale: true,useMipMap: false, name: "RaytracingDirectionBuffer"); - m_RayTracingDistanceBuffer = RTHandles.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R32_SFloat, dimension: TextureXR.dimension, enableRandomWrite: true, useDynamicScale: true, useMipMap: false, name: "RaytracingDistanceBuffer"); - - // Allocate the intermediate buffers - m_RayTracingIntermediateBufferR0 = RTHandles.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R8_SNorm, dimension: TextureXR.dimension, enableRandomWrite: true, useDynamicScale: true, useMipMap: false, name: "RayTracingIntermediateBufferR0"); - m_RayTracingIntermediateBufferR1 = RTHandles.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R8_SNorm, dimension: TextureXR.dimension, enableRandomWrite: true, useDynamicScale: true, useMipMap: false, name: "RayTracingIntermediateBufferR1"); - m_RayTracingIntermediateBufferRG0 = RTHandles.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R16G16_SFloat, dimension: TextureXR.dimension, enableRandomWrite: true, useDynamicScale: true, useMipMap: false, name: "RayTracingIntermediateBufferRG0"); - m_RayTracingIntermediateBufferRG1 = RTHandles.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R16G16_SFloat, dimension: TextureXR.dimension, enableRandomWrite: true, useDynamicScale: true, useMipMap: false, name: "RayTracingIntermediateBufferRG1"); - m_RayTracingIntermediateBufferRGBA0 = RTHandles.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, dimension: TextureXR.dimension, enableRandomWrite: true, useDynamicScale: true, useMipMap: false, name: "RayTracingIntermediateBufferRGBA0"); - m_RayTracingIntermediateBufferRGBA1 = RTHandles.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, dimension: TextureXR.dimension, enableRandomWrite: true, useDynamicScale: true, useMipMap: false, name: "RayTracingIntermediateBufferRGBA1"); - m_RayTracingIntermediateBufferRGBA2 = RTHandles.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, dimension: TextureXR.dimension, enableRandomWrite: true, useDynamicScale: true, useMipMap: false, name: "RayTracingIntermediateBufferRGBA2"); - m_RayTracingIntermediateBufferRGBA3 = RTHandles.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, dimension: TextureXR.dimension, enableRandomWrite: true, useDynamicScale: true, useMipMap: false, name: "RayTracingIntermediateBufferRGBA3"); } internal void ReleaseRayTracingManager() { - RTHandles.Release(m_RayTracingDistanceBuffer); - RTHandles.Release(m_RayTracingDirectionBuffer); - - RTHandles.Release(m_RayTracingIntermediateBufferR1); - RTHandles.Release(m_RayTracingIntermediateBufferR0); - RTHandles.Release(m_RayTracingIntermediateBufferRG1); - RTHandles.Release(m_RayTracingIntermediateBufferRG0); - RTHandles.Release(m_RayTracingIntermediateBufferRGBA0); - RTHandles.Release(m_RayTracingIntermediateBufferRGBA1); - RTHandles.Release(m_RayTracingIntermediateBufferRGBA2); - RTHandles.Release(m_RayTracingIntermediateBufferRGBA3); - - m_RayTracingLightCluster.ReleaseResources(); - m_ReflectionDenoiser.Release(); - m_TemporalFilter.Release(); - m_SimpleDenoiser.Release(); - m_DiffuseDenoiser.Release(); - m_RayCountManager.Release(); - m_DiffuseShadowDenoiser.Release(); + if (m_RayTracingDistanceBuffer != null) + RTHandles.Release(m_RayTracingDistanceBuffer); + if (m_RayTracingDirectionBuffer != null) + RTHandles.Release(m_RayTracingDirectionBuffer); + + if (m_RayTracingIntermediateBufferR0 != null) + RTHandles.Release(m_RayTracingIntermediateBufferR0); + if (m_RayTracingIntermediateBufferR1 != null) + RTHandles.Release(m_RayTracingIntermediateBufferR1); + if (m_RayTracingIntermediateBufferRG0 != null) + RTHandles.Release(m_RayTracingIntermediateBufferRG0); + if (m_RayTracingIntermediateBufferRG1 != null) + RTHandles.Release(m_RayTracingIntermediateBufferRG1); + if (m_RayTracingIntermediateBufferRGBA0 != null) + RTHandles.Release(m_RayTracingIntermediateBufferRGBA0); + if (m_RayTracingIntermediateBufferRGBA1 != null) + RTHandles.Release(m_RayTracingIntermediateBufferRGBA1); + if (m_RayTracingIntermediateBufferRGBA2 != null) + RTHandles.Release(m_RayTracingIntermediateBufferRGBA2); + if (m_RayTracingIntermediateBufferRGBA3 != null) + RTHandles.Release(m_RayTracingIntermediateBufferRGBA3); + + if (m_RayTracingLightCluster != null) + m_RayTracingLightCluster.ReleaseResources(); + if (m_RayCountManager != null) + m_RayCountManager.Release(); + + if (m_ReflectionDenoiser != null) + m_ReflectionDenoiser.Release(); + if (m_TemporalFilter != null) + m_TemporalFilter.Release(); + if (m_SimpleDenoiser != null) + m_SimpleDenoiser.Release(); + if (m_SSGIDenoiser != null) + m_SSGIDenoiser.Release(); + if (m_DiffuseShadowDenoiser != null) + m_DiffuseShadowDenoiser.Release(); + if (m_DiffuseDenoiser != null) + m_DiffuseDenoiser.Release(); } AccelerationStructureStatus AddInstanceToRAS(Renderer currentRenderer, @@ -644,26 +618,61 @@ internal RayCountManager GetRayCountManager() internal HDTemporalFilter GetTemporalFilter() { + if (m_TemporalFilter == null) + { + m_TemporalFilter = new HDTemporalFilter(); + m_TemporalFilter.Init(m_Asset.renderPipelineRayTracingResources, sharedRTManager, this); + } return m_TemporalFilter; } internal HDSimpleDenoiser GetSimpleDenoiser() { + if (m_SimpleDenoiser == null) + { + m_SimpleDenoiser = new HDSimpleDenoiser(); + m_SimpleDenoiser.Init(m_Asset.renderPipelineRayTracingResources, sharedRTManager, this); + } return m_SimpleDenoiser; } + internal SSGIDenoiser GetSSGIDenoiser() + { + if (m_SSGIDenoiser == null) + { + m_SSGIDenoiser = new SSGIDenoiser(); + m_SSGIDenoiser.Init(m_Asset.renderPipelineResources, sharedRTManager, this); + } + return m_SSGIDenoiser; + } + internal HDDiffuseDenoiser GetDiffuseDenoiser() { + if (m_DiffuseDenoiser == null) + { + m_DiffuseDenoiser = new HDDiffuseDenoiser(); + m_DiffuseDenoiser.Init(m_Asset.renderPipelineResources, m_Asset.renderPipelineRayTracingResources, sharedRTManager, this); + } return m_DiffuseDenoiser; } internal HDReflectionDenoiser GetReflectionDenoiser() { + if (m_ReflectionDenoiser == null) + { + m_ReflectionDenoiser = new HDReflectionDenoiser(); + m_ReflectionDenoiser.Init(m_Asset.renderPipelineRayTracingResources, sharedRTManager, this); + } return m_ReflectionDenoiser; } internal HDDiffuseShadowDenoiser GetDiffuseShadowDenoiser() { + if (m_DiffuseShadowDenoiser == null) + { + m_DiffuseShadowDenoiser = new HDDiffuseShadowDenoiser(); + m_DiffuseShadowDenoiser.Init(m_Asset.renderPipelineRayTracingResources, sharedRTManager, this); + } return m_DiffuseShadowDenoiser; } @@ -677,6 +686,94 @@ internal bool GetRayTracingClusterState() return m_ValidRayTracingCluster; } + internal RTHandle AllocateBuffer(InternalRayTracingBuffers bufferID) + { + switch (bufferID) + { + case InternalRayTracingBuffers.Direction: + { + m_RayTracingDirectionBuffer = RTHandles.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, dimension: TextureXR.dimension, enableRandomWrite: true, useDynamicScale: true,useMipMap: false, name: "RaytracingDirectionBuffer"); + return m_RayTracingDirectionBuffer; + } + case InternalRayTracingBuffers.Distance: + { + m_RayTracingDistanceBuffer = RTHandles.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R32_SFloat, dimension: TextureXR.dimension, enableRandomWrite: true, useDynamicScale: true, useMipMap: false, name: "RaytracingDistanceBuffer"); + return m_RayTracingDistanceBuffer; + } + case InternalRayTracingBuffers.R0: + { + m_RayTracingIntermediateBufferR0 = RTHandles.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R8_SNorm, dimension: TextureXR.dimension, enableRandomWrite: true, useDynamicScale: true, useMipMap: false, name: "RayTracingIntermediateBufferR0"); + return m_RayTracingIntermediateBufferR0; + } + case InternalRayTracingBuffers.R1: + { + m_RayTracingIntermediateBufferR1 = RTHandles.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R8_SNorm, dimension: TextureXR.dimension, enableRandomWrite: true, useDynamicScale: true, useMipMap: false, name: "RayTracingIntermediateBufferR1"); + return m_RayTracingIntermediateBufferR1; + } + case InternalRayTracingBuffers.RG0: + { + m_RayTracingIntermediateBufferRG0 = RTHandles.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R16G16_SFloat, dimension: TextureXR.dimension, enableRandomWrite: true, useDynamicScale: true, useMipMap: false, name: "RayTracingIntermediateBufferRG0"); + return m_RayTracingIntermediateBufferRG0; + } + case InternalRayTracingBuffers.RG1: + { + m_RayTracingIntermediateBufferRG1 = RTHandles.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R16G16_SFloat, dimension: TextureXR.dimension, enableRandomWrite: true, useDynamicScale: true, useMipMap: false, name: "RayTracingIntermediateBufferRG1"); + return m_RayTracingIntermediateBufferRG1; + } + case InternalRayTracingBuffers.RGBA0: + { + m_RayTracingIntermediateBufferRGBA0 = RTHandles.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, dimension: TextureXR.dimension, enableRandomWrite: true, useDynamicScale: true, useMipMap: false, name: "RayTracingIntermediateBufferRGBA0"); + return m_RayTracingIntermediateBufferRGBA0; + } + case InternalRayTracingBuffers.RGBA1: + { + m_RayTracingIntermediateBufferRGBA1 = RTHandles.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, dimension: TextureXR.dimension, enableRandomWrite: true, useDynamicScale: true, useMipMap: false, name: "RayTracingIntermediateBufferRGBA1"); + return m_RayTracingIntermediateBufferRGBA1; + } + case InternalRayTracingBuffers.RGBA2: + { + m_RayTracingIntermediateBufferRGBA2 = RTHandles.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, dimension: TextureXR.dimension, enableRandomWrite: true, useDynamicScale: true, useMipMap: false, name: "RayTracingIntermediateBufferRGBA2"); + return m_RayTracingIntermediateBufferRGBA2; + } + case InternalRayTracingBuffers.RGBA3: + { + m_RayTracingIntermediateBufferRGBA3 = RTHandles.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, dimension: TextureXR.dimension, enableRandomWrite: true, useDynamicScale: true, useMipMap: false, name: "RayTracingIntermediateBufferRGBA3"); + return m_RayTracingIntermediateBufferRGBA3; + } + default: + return null; + } + } + + internal RTHandle GetRayTracingBuffer(InternalRayTracingBuffers bufferID) + { + switch (bufferID) + { + case InternalRayTracingBuffers.Distance: + return m_RayTracingDistanceBuffer != null ? m_RayTracingDistanceBuffer : AllocateBuffer(InternalRayTracingBuffers.Distance); + case InternalRayTracingBuffers.Direction: + return m_RayTracingDirectionBuffer != null ? m_RayTracingDirectionBuffer : AllocateBuffer(InternalRayTracingBuffers.Direction); + case InternalRayTracingBuffers.R0: + return m_RayTracingIntermediateBufferR0 != null ? m_RayTracingIntermediateBufferR0 : AllocateBuffer(InternalRayTracingBuffers.R0); + case InternalRayTracingBuffers.R1: + return m_RayTracingIntermediateBufferR1 != null ? m_RayTracingIntermediateBufferR1 : AllocateBuffer(InternalRayTracingBuffers.R1); + case InternalRayTracingBuffers.RG0: + return m_RayTracingIntermediateBufferRG0 != null ? m_RayTracingIntermediateBufferRG0 : AllocateBuffer(InternalRayTracingBuffers.RG0); + case InternalRayTracingBuffers.RG1: + return m_RayTracingIntermediateBufferRG1 != null ? m_RayTracingIntermediateBufferRG1 : AllocateBuffer(InternalRayTracingBuffers.RG1); + case InternalRayTracingBuffers.RGBA0: + return m_RayTracingIntermediateBufferRGBA0 != null ? m_RayTracingIntermediateBufferRGBA0 : AllocateBuffer(InternalRayTracingBuffers.RGBA0); + case InternalRayTracingBuffers.RGBA1: + return m_RayTracingIntermediateBufferRGBA1 != null ? m_RayTracingIntermediateBufferRGBA1 : AllocateBuffer(InternalRayTracingBuffers.RGBA1); + case InternalRayTracingBuffers.RGBA2: + return m_RayTracingIntermediateBufferRGBA2 != null ? m_RayTracingIntermediateBufferRGBA2 : AllocateBuffer(InternalRayTracingBuffers.RGBA2); + case InternalRayTracingBuffers.RGBA3: + return m_RayTracingIntermediateBufferRGBA3 != null ? m_RayTracingIntermediateBufferRGBA3 : AllocateBuffer(InternalRayTracingBuffers.RGBA3); + default: + return null; + } + } + static internal float GetPixelSpreadTangent(float fov, int width, int height) { return Mathf.Tan(fov * Mathf.Deg2Rad * 0.5f) * 2.0f / Mathf.Min(width, height); diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPipelineResources.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPipelineResources.cs index dd37e951db7..512e90b9f38 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPipelineResources.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPipelineResources.cs @@ -200,6 +200,9 @@ public sealed class ShaderResources [Reload("Runtime/Lighting/ScreenSpaceLighting/GTAOBlurAndUpsample.compute")] public ComputeShader GTAOBlurAndUpsample; + [Reload("Runtime/Lighting/ScreenSpaceLighting/ScreenSpaceGlobalIllumination.compute")] + public ComputeShader screenSpaceGlobalIlluminationCS; + // MSAA Shaders [Reload("Runtime/RenderPipeline/RenderPass/MSAA/DepthValues.shader")] public Shader depthValuesPS; @@ -293,6 +296,12 @@ public sealed class ShaderResources [Reload("Runtime/Compositor/Shaders/CustomClear.shader")] public Shader customClearPS; + // Denoising + [Reload("Runtime/Lighting/ScreenSpaceLighting/SSGIDenoiser.compute")] + public ComputeShader ssGIDenoiserCS; + [Reload("Runtime/Lighting/ScreenSpaceLighting/BilateralUpsample.compute")] + public ComputeShader bilateralUpsampleCS; + // Iterator to retrieve all compute shaders in reflection so we don't have to keep a list of // used compute shaders up to date (prefer editor-only usage) public IEnumerable GetAllComputeShaders() diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Settings/FrameSettings.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Settings/FrameSettings.cs index 377cdd9624a..1a6d9f69243 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Settings/FrameSettings.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Settings/FrameSettings.cs @@ -247,7 +247,9 @@ public enum FrameSettingsField /// When enabled, Cameras using these Frame Settings calculate Screen Space Ambient Occlusion. [FrameSettingsField(1, displayedName: "Screen Space Ambient Occlusion", tooltip: "When enabled, Cameras using these Frame Settings calculate Screen Space Ambient Occlusion (Depends on \"Screen Space Ambient Occlusion\" in current HDRP Asset).")] SSAO = 24, - + /// When enabled, Cameras using these Frame Settings calculate Transparent Screen Space Global Illumination. + [FrameSettingsField(1, displayedName: "Screen Space Global Illumination", customOrderInGroup: 25, tooltip: "When enabled, Cameras using these Frame Settings calculate Screen Space Global Illumination (Depends on \"Screen Space Global Illumination\" in current HDRP Asset).")] + SSGI = 95, /// When enabled, Cameras using these Frame Settings render subsurface scattering (SSS) effects for GameObjects that use a SSS Material. [FrameSettingsField(1, customOrderInGroup: 46, autoName: SubsurfaceScattering, tooltip: "When enabled, Cameras using these Frame Settings render subsurface scattering (SSS) effects for GameObjects that use a SSS Material (Depends on \"Subsurface Scattering\" in current HDRP Asset).")] @@ -373,6 +375,7 @@ partial struct FrameSettings (uint)FrameSettingsField.ScreenSpaceShadows, (uint)FrameSettingsField.SSR, (uint)FrameSettingsField.SSAO, + (uint)FrameSettingsField.SSGI, (uint)FrameSettingsField.SubsurfaceScattering, (uint)FrameSettingsField.Transmission, // Caution: this is only for debug, it doesn't save the cost of Transmission execution (uint)FrameSettingsField.AtmosphericScattering, @@ -444,6 +447,7 @@ partial struct FrameSettings //(uint)FrameSettingsField.ShadowMask, //(uint)FrameSettingsField.SSR, //(uint)FrameSettingsField.SSAO, + //(uint)FrameSettingsField.SSGI, (uint)FrameSettingsField.SubsurfaceScattering, (uint)FrameSettingsField.Transmission, // Caution: this is only for debug, it doesn't save the cost of Transmission execution //(uint)FrameSettingsField.AtmosphericScaterring, @@ -497,6 +501,7 @@ partial struct FrameSettings (uint)FrameSettingsField.Shadowmask, //(uint)FrameSettingsField.SSR, (uint)FrameSettingsField.SSAO, + //(uint)FrameSettingsField.SSGI, (uint)FrameSettingsField.SubsurfaceScattering, (uint)FrameSettingsField.Transmission, // Caution: this is only for debug, it doesn't save the cost of Transmission execution (uint)FrameSettingsField.AtmosphericScattering, @@ -739,6 +744,7 @@ internal static void Sanitize(ref FrameSettings sanitizedFrameSettings, Camera c sanitizedFrameSettings.bitDatas[(int)FrameSettingsField.TransparentSSR] &= renderPipelineSettings.supportSSRTransparent && sanitizedFrameSettings.bitDatas[(int)FrameSettingsField.SSR]; sanitizedFrameSettings.bitDatas[(int)FrameSettingsField.Refraction] &= !preview; sanitizedFrameSettings.bitDatas[(int)FrameSettingsField.SSAO] &= renderPipelineSettings.supportSSAO && !preview; + sanitizedFrameSettings.bitDatas[(int)FrameSettingsField.SSGI] &= renderPipelineSettings.supportSSGI && !preview; sanitizedFrameSettings.bitDatas[(int)FrameSettingsField.SubsurfaceScattering] &= renderPipelineSettings.supportSubsurfaceScattering; // We must take care of the scene view fog flags in the editor diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Settings/RenderPipelineSettings.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Settings/RenderPipelineSettings.cs index 686106a379a..ff0f2a5aecf 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Settings/RenderPipelineSettings.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Settings/RenderPipelineSettings.cs @@ -141,6 +141,8 @@ public struct LightSettings public bool supportSSRTransparent; /// Support screen space ambient occlusion. public bool supportSSAO; + /// Support screen space global illumination. + public bool supportSSGI; /// Support subsurface scattering. public bool supportSubsurfaceScattering; /// Sample budget for the Subsurface Scattering algorithm. diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/HDRenderPipelineResources.asset b/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/HDRenderPipelineResources.asset index 57616a47365..feec86a4344 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/HDRenderPipelineResources.asset +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/HDRenderPipelineResources.asset @@ -15,86 +15,135 @@ MonoBehaviour: m_Version: 4 shaders: defaultPS: {fileID: 4800000, guid: 6e4ae4064600d784cac1e41a9e6f2e59, type: 3} - debugDisplayLatlongPS: {fileID: 4800000, guid: c1d1d149a043a5349ba367da6c2051ba, type: 3} - debugViewMaterialGBufferPS: {fileID: 4800000, guid: 439949ea1bfa91b4ba0d04269fcde33d, type: 3} + debugDisplayLatlongPS: {fileID: 4800000, guid: c1d1d149a043a5349ba367da6c2051ba, + type: 3} + debugViewMaterialGBufferPS: {fileID: 4800000, guid: 439949ea1bfa91b4ba0d04269fcde33d, + type: 3} debugViewTilesPS: {fileID: 4800000, guid: c7c2bd17b06ceb4468e14081aaf1b96f, type: 3} debugFullScreenPS: {fileID: 4800000, guid: e874aca2df8300a488258738c31f85cf, type: 3} - debugColorPickerPS: {fileID: 4800000, guid: 8137b807709e178498f22ed710864bb0, type: 3} - debugLightVolumePS: {fileID: 4800000, guid: 8e706c0e71fcec34a8f5c9713e5e2943, type: 3} - debugLightVolumeCS: {fileID: 7200000, guid: f5d5d21faef5cf445ac2c5d8ff9c4184, type: 3} + debugColorPickerPS: {fileID: 4800000, guid: 8137b807709e178498f22ed710864bb0, + type: 3} + debugLightVolumePS: {fileID: 4800000, guid: 8e706c0e71fcec34a8f5c9713e5e2943, + type: 3} + debugLightVolumeCS: {fileID: 7200000, guid: f5d5d21faef5cf445ac2c5d8ff9c4184, + type: 3} debugBlitQuad: {fileID: 4800000, guid: cf5ca5b6ef18b3f429ed707ee9ceac9f, type: 3} deferredPS: {fileID: 4800000, guid: 00dd221e34a6ab349a1196b0f2fab693, type: 3} colorPyramidPS: {fileID: 4800000, guid: 2fcfb8d92f45e4549b3f0bad5d0654bf, type: 3} depthPyramidCS: {fileID: 7200000, guid: 64a553bb564274041906f78ffba955e4, type: 3} copyChannelCS: {fileID: 7200000, guid: a4d45eda75e8e474dbe24a31f741f3b4, type: 3} - screenSpaceReflectionsCS: {fileID: 7200000, guid: d1de9ac7d9016204da289affe9677942, type: 3} + screenSpaceReflectionsCS: {fileID: 7200000, guid: d1de9ac7d9016204da289affe9677942, + type: 3} applyDistortionPS: {fileID: 4800000, guid: 02ae56f4306413c4a96dcf005cde1971, type: 3} - clearDispatchIndirectCS: {fileID: 7200000, guid: fc1f553acb80a6446a32d33e403d0656, type: 3} + clearDispatchIndirectCS: {fileID: 7200000, guid: fc1f553acb80a6446a32d33e403d0656, + type: 3} clearLightListsCS: {fileID: 7200000, guid: 743eb3491795b9545955695d591195a1, type: 3} - buildDispatchIndirectCS: {fileID: 7200000, guid: 4eb1b418be7044c40bb5200496c50f14, type: 3} + buildDispatchIndirectCS: {fileID: 7200000, guid: 4eb1b418be7044c40bb5200496c50f14, + type: 3} buildScreenAABBCS: {fileID: 7200000, guid: 728dce960f8a9c44bbc3abb3b851d8f6, type: 3} - buildPerTileLightListCS: {fileID: 7200000, guid: 65af3444cbf4b3747a4dead7ee00cfee, type: 3} - buildPerBigTileLightListCS: {fileID: 7200000, guid: 5ee1f9d6e09abe045b2f5e0b784b9072, type: 3} - buildPerVoxelLightListCS: {fileID: 7200000, guid: 0bb1b7e0ddcd5c44baf3ddc7456eb196, type: 3} - lightListClusterClearAtomicIndexCS: {fileID: 7200000, guid: 1e3472a94b14a334a93230bbc700d7b2, type: 3} - buildMaterialFlagsCS: {fileID: 7200000, guid: fb3eda953cd6e634e877fb777be2cd08, type: 3} + buildPerTileLightListCS: {fileID: 7200000, guid: 65af3444cbf4b3747a4dead7ee00cfee, + type: 3} + buildPerBigTileLightListCS: {fileID: 7200000, guid: 5ee1f9d6e09abe045b2f5e0b784b9072, + type: 3} + buildPerVoxelLightListCS: {fileID: 7200000, guid: 0bb1b7e0ddcd5c44baf3ddc7456eb196, + type: 3} + lightListClusterClearAtomicIndexCS: {fileID: 7200000, guid: 1e3472a94b14a334a93230bbc700d7b2, + type: 3} + buildMaterialFlagsCS: {fileID: 7200000, guid: fb3eda953cd6e634e877fb777be2cd08, + type: 3} deferredCS: {fileID: 7200000, guid: 0b64f79746d2daf4198eaf6eab9af259, type: 3} contactShadowCS: {fileID: 7200000, guid: 3e6900e06dc185a4380af4dacb4db0a4, type: 3} - volumeVoxelizationCS: {fileID: 7200000, guid: c20b371db720da244b73830ec74a343a, type: 3} - volumetricLightingCS: {fileID: 7200000, guid: b4901a10df2d1e24282725e9fbc77c97, type: 3} - volumetricLightingFilteringCS: {fileID: 7200000, guid: ef9a910d0ec6ebb41ae3f5c7a69daf46, type: 3} + volumeVoxelizationCS: {fileID: 7200000, guid: c20b371db720da244b73830ec74a343a, + type: 3} + volumetricLightingCS: {fileID: 7200000, guid: b4901a10df2d1e24282725e9fbc77c97, + type: 3} + volumetricLightingFilteringCS: {fileID: 7200000, guid: ef9a910d0ec6ebb41ae3f5c7a69daf46, + type: 3} deferredTilePS: {fileID: 4800000, guid: dedaf4ea0d134ca4aad1d95a558c46e5, type: 3} - screenSpaceShadowPS: {fileID: 4800000, guid: bfa43a48695613b4ea19c58858ae1a61, type: 3} - probeVolumeAtlasBlitCS: {fileID: 7200000, guid: 07f429bf534edb44eb5a0e4b2c65b108, type: 3} - probeVolumeAtlasOctahedralDepthBlitCS: {fileID: 7200000, guid: f60c895d3a3061848844b36ccf9e44a9, type: 3} - probeVolumeAtlasOctahedralDepthConvolveCS: {fileID: 7200000, guid: 7ef71ce05401a4c4081039b475d3b9ee, type: 3} - debugDisplayProbeVolumePS: {fileID: 4800000, guid: e7c19cfee7a88394fbb53652b9644cc0, type: 3} - subsurfaceScatteringCS: {fileID: 7200000, guid: b06a7993621def248addd55d0fe931b1, type: 3} + screenSpaceShadowPS: {fileID: 4800000, guid: bfa43a48695613b4ea19c58858ae1a61, + type: 3} + probeVolumeAtlasBlitCS: {fileID: 7200000, guid: 07f429bf534edb44eb5a0e4b2c65b108, + type: 3} + probeVolumeAtlasOctahedralDepthBlitCS: {fileID: 7200000, guid: f60c895d3a3061848844b36ccf9e44a9, + type: 3} + probeVolumeAtlasOctahedralDepthConvolveCS: {fileID: 7200000, guid: 7ef71ce05401a4c4081039b475d3b9ee, + type: 3} + debugDisplayProbeVolumePS: {fileID: 4800000, guid: e7c19cfee7a88394fbb53652b9644cc0, + type: 3} + subsurfaceScatteringCS: {fileID: 7200000, guid: b06a7993621def248addd55d0fe931b1, + type: 3} combineLightingPS: {fileID: 4800000, guid: 2e37131331fbdca449b1a2bc47a639ca, type: 3} - cameraMotionVectorsPS: {fileID: 4800000, guid: 035941b63024d1943af48811c1db20d9, type: 3} - clearStencilBufferPS: {fileID: 4800000, guid: 8ea49ef16606acd489439e676ab84040, type: 3} - copyStencilBufferPS: {fileID: 4800000, guid: 3d1574f1cdfa0ce4995f9bc79ed7f8ec, type: 3} + cameraMotionVectorsPS: {fileID: 4800000, guid: 035941b63024d1943af48811c1db20d9, + type: 3} + clearStencilBufferPS: {fileID: 4800000, guid: 8ea49ef16606acd489439e676ab84040, + type: 3} + copyStencilBufferPS: {fileID: 4800000, guid: 3d1574f1cdfa0ce4995f9bc79ed7f8ec, + type: 3} copyDepthBufferPS: {fileID: 4800000, guid: 42dfcc8fe803ece4096c58630689982f, type: 3} blitPS: {fileID: 4800000, guid: 370f7a9cc4e362d488af024d371091e8, type: 3} downsampleDepthPS: {fileID: 4800000, guid: 67d6171b0acc6554aad48c845ec7e67f, type: 3} - upsampleTransparentPS: {fileID: 4800000, guid: 2ad7ce40f0dbaf64dadef1f58d8524d3, type: 3} + upsampleTransparentPS: {fileID: 4800000, guid: 2ad7ce40f0dbaf64dadef1f58d8524d3, + type: 3} resolveStencilCS: {fileID: 7200000, guid: 65b89cac5f286b043a31bf8041776ee7, type: 3} blitCubemapPS: {fileID: 4800000, guid: d05913e251bed7a4992c921c62e1b647, type: 3} - buildProbabilityTablesCS: {fileID: 7200000, guid: b9f26cf340afe9145a699753531b2a4c, type: 3} - computeGgxIblSampleDataCS: {fileID: 7200000, guid: 764a24bb47ef5ba4781d9ae82ca07445, type: 3} + buildProbabilityTablesCS: {fileID: 7200000, guid: b9f26cf340afe9145a699753531b2a4c, + type: 3} + computeGgxIblSampleDataCS: {fileID: 7200000, guid: 764a24bb47ef5ba4781d9ae82ca07445, + type: 3} GGXConvolvePS: {fileID: 4800000, guid: 123ed592ad5c2494b8aed301fd609e7b, type: 3} charlieConvolvePS: {fileID: 4800000, guid: 5685fd17e71045e4ca9fefca38a7c177, type: 3} - opaqueAtmosphericScatteringPS: {fileID: 4800000, guid: 32f724728cf19904291226f239ec16f0, type: 3} + opaqueAtmosphericScatteringPS: {fileID: 4800000, guid: 32f724728cf19904291226f239ec16f0, + type: 3} hdriSkyPS: {fileID: 4800000, guid: 9bd32a6ece529fd4f9408b8d7e00c10d, type: 3} - integrateHdriSkyPS: {fileID: 4800000, guid: 48db2705cf2856d4e893eb30a6892d1b, type: 3} + integrateHdriSkyPS: {fileID: 4800000, guid: 48db2705cf2856d4e893eb30a6892d1b, + type: 3} skyboxCubemapPS: {fileID: 103, guid: 0000000000000000f000000000000000, type: 0} gradientSkyPS: {fileID: 4800000, guid: 2b5d4f1b26f03dc4a873b093e0c4adb1, type: 3} - ambientProbeConvolutionCS: {fileID: 7200000, guid: 6d048f7b1bd45e840b4e79ec92639fa8, type: 3} - groundIrradiancePrecomputationCS: {fileID: 7200000, guid: eb6ae6f326207ee4d987a3e5adddf63a, type: 3} - inScatteredRadiancePrecomputationCS: {fileID: 7200000, guid: 70c69d514688f8545855680760d77418, type: 3} - physicallyBasedSkyPS: {fileID: 4800000, guid: a06934a4863e778498be65d8f865b7a4, type: 3} - preIntegratedFGD_GGXDisneyDiffusePS: {fileID: 4800000, guid: 123f13d52852ef547b2962de4bd9eaad, type: 3} - preIntegratedFGD_CharlieFabricLambertPS: {fileID: 4800000, guid: 3b3bf235775cf8b4baae7f3306787ab0, type: 3} - preIntegratedFGD_WardPS: {fileID: 4800000, guid: d279c46a545b0af4f9f0c4fa82cd489e, type: 3} - preIntegratedFGD_CookTorrancePS: {fileID: 4800000, guid: a6402c19b020b4a4fb7073aaa2e26aba, type: 3} + ambientProbeConvolutionCS: {fileID: 7200000, guid: 6d048f7b1bd45e840b4e79ec92639fa8, + type: 3} + groundIrradiancePrecomputationCS: {fileID: 7200000, guid: eb6ae6f326207ee4d987a3e5adddf63a, + type: 3} + inScatteredRadiancePrecomputationCS: {fileID: 7200000, guid: 70c69d514688f8545855680760d77418, + type: 3} + physicallyBasedSkyPS: {fileID: 4800000, guid: a06934a4863e778498be65d8f865b7a4, + type: 3} + preIntegratedFGD_GGXDisneyDiffusePS: {fileID: 4800000, guid: 123f13d52852ef547b2962de4bd9eaad, + type: 3} + preIntegratedFGD_CharlieFabricLambertPS: {fileID: 4800000, guid: 3b3bf235775cf8b4baae7f3306787ab0, + type: 3} + preIntegratedFGD_WardPS: {fileID: 4800000, guid: d279c46a545b0af4f9f0c4fa82cd489e, + type: 3} + preIntegratedFGD_CookTorrancePS: {fileID: 4800000, guid: a6402c19b020b4a4fb7073aaa2e26aba, + type: 3} encodeBC6HCS: {fileID: 7200000, guid: aa922d239de60304f964e24488559eeb, type: 3} cubeToPanoPS: {fileID: 4800000, guid: 595434cc3b6405246b6cd3086d0b6f7d, type: 3} - blitCubeTextureFacePS: {fileID: 4800000, guid: d850d0a2481878d4bbf17e5126b04163, type: 3} - filterAreaLightCookiesPS: {fileID: 4800000, guid: c243aac96dda5fa40bed693ed5ba02c4, type: 3} - clearUIntTextureCS: {fileID: 7200000, guid: d067ad4b88af51c498875426894aef76, type: 3} + blitCubeTextureFacePS: {fileID: 4800000, guid: d850d0a2481878d4bbf17e5126b04163, + type: 3} + filterAreaLightCookiesPS: {fileID: 4800000, guid: c243aac96dda5fa40bed693ed5ba02c4, + type: 3} + clearUIntTextureCS: {fileID: 7200000, guid: d067ad4b88af51c498875426894aef76, + type: 3} xrMirrorViewPS: {fileID: 4800000, guid: e6255f98cf405eb45ab6f9006cf11e1f, type: 3} xrOcclusionMeshPS: {fileID: 4800000, guid: 46a45b32bb110604fb36216b63bcdb81, type: 3} shadowClearPS: {fileID: 4800000, guid: e3cab24f27741f44d8af1e94d006267c, type: 3} evsmBlurCS: {fileID: 7200000, guid: fb36979473602464fa32deacb9630c08, type: 3} - debugHDShadowMapPS: {fileID: 4800000, guid: 93d40cc9a6e13994f86f576a624efa18, type: 3} + debugHDShadowMapPS: {fileID: 4800000, guid: 93d40cc9a6e13994f86f576a624efa18, + type: 3} momentShadowsCS: {fileID: 7200000, guid: 4dea53e2ff15ed0448817c2aa4246e53, type: 3} - decalNormalBufferPS: {fileID: 4800000, guid: fd532bf1795188c4daaa66ea798b8b0a, type: 3} - decalClearPropertyMaskBufferCS: {fileID: 7200000, guid: 1076a08965d4a91479b72599724f7fd6, type: 3} + decalNormalBufferPS: {fileID: 4800000, guid: fd532bf1795188c4daaa66ea798b8b0a, + type: 3} + decalClearPropertyMaskBufferCS: {fileID: 7200000, guid: 1076a08965d4a91479b72599724f7fd6, + type: 3} GTAOCS: {fileID: 7200000, guid: 6710b06492bd58c4bb8aec0fdc1fced3, type: 3} - GTAOSpatialDenoiseCS: {fileID: 7200000, guid: 2cb33c21587d12b4388d7866ab6c65f6, type: 3} - GTAOTemporalDenoiseCS: {fileID: 7200000, guid: 31e0ca4c210f97c468037d11a5b832bb, type: 3} + GTAOSpatialDenoiseCS: {fileID: 7200000, guid: 2cb33c21587d12b4388d7866ab6c65f6, + type: 3} + GTAOTemporalDenoiseCS: {fileID: 7200000, guid: 31e0ca4c210f97c468037d11a5b832bb, + type: 3} GTAOCopyHistoryCS: {fileID: 7200000, guid: 7f43be57ffd12ff469d4fc175c00c4b4, type: 3} - GTAOBlurAndUpsample: {fileID: 7200000, guid: 9eb1abde882538a4ea46fa23e49ab9fa, type: 3} + GTAOBlurAndUpsample: {fileID: 7200000, guid: 9eb1abde882538a4ea46fa23e49ab9fa, + type: 3} + screenSpaceGlobalIlluminationCS: {fileID: 7200000, guid: 96170a954eb538b40a5ff369552c3629, + type: 3} depthValuesPS: {fileID: 4800000, guid: 6e6a4a3dbb788234594aa74f2d6aeb6f, type: 3} colorResolvePS: {fileID: 4800000, guid: dd7047092f3c82b40b3a07868f9c4de2, type: 3} copyAlphaCS: {fileID: 7200000, guid: c2c7eb6611725264187721ef9df0354b, type: 3} @@ -103,23 +152,38 @@ MonoBehaviour: applyExposureCS: {fileID: 7200000, guid: 1a6fea1dc099b984d8f2b27d504dc096, type: 3} uberPostCS: {fileID: 7200000, guid: f1bf52f7c71bffd4f91e6cd90d12a4f7, type: 3} lutBuilder3DCS: {fileID: 7200000, guid: 37f2b1b0ecd6f1c439e4c1b4f2fdb524, type: 3} - depthOfFieldKernelCS: {fileID: 7200000, guid: 7869415cc3e4eaa4d82ac21a752a2780, type: 3} + depthOfFieldKernelCS: {fileID: 7200000, guid: 7869415cc3e4eaa4d82ac21a752a2780, + type: 3} depthOfFieldCoCCS: {fileID: 7200000, guid: 048b235b54fbfaa4d80ec85ea847d4f8, type: 3} - depthOfFieldCoCReprojectCS: {fileID: 7200000, guid: 4980decaa3878d6448569489f5fc7931, type: 3} - depthOfFieldDilateCS: {fileID: 7200000, guid: 1c93af4338c0c1b42b92464992eebc10, type: 3} + depthOfFieldCoCReprojectCS: {fileID: 7200000, guid: 4980decaa3878d6448569489f5fc7931, + type: 3} + depthOfFieldDilateCS: {fileID: 7200000, guid: 1c93af4338c0c1b42b92464992eebc10, + type: 3} depthOfFieldMipCS: {fileID: 7200000, guid: d3ef53de069ded64e8377cba6eb951fa, type: 3} - depthOfFieldMipSafeCS: {fileID: 7200000, guid: 2d24ee7b2c804d947a5c371c12ed46bd, type: 3} - depthOfFieldPrefilterCS: {fileID: 7200000, guid: f2b89d19910854346b792fe7177ce634, type: 3} - depthOfFieldTileMaxCS: {fileID: 7200000, guid: 84f84585ea8a7a849bea4a581adb93a7, type: 3} - depthOfFieldGatherCS: {fileID: 7200000, guid: 486be52dddc4e054fb10a7b9b78788c2, type: 3} - depthOfFieldCombineCS: {fileID: 7200000, guid: c8049ca85c4c7d047ba28f34d800c663, type: 3} - depthOfFieldPreCombineFarCS: {fileID: 7200000, guid: 3b4a2acd03d1ce2438d93c325d588735, type: 3} - depthOfFieldClearIndirectArgsCS: {fileID: 7200000, guid: 69905045e1d0a65458b205d6ab55502b, type: 3} - paniniProjectionCS: {fileID: 7200000, guid: 0ddbf72c8fbb6e44b983f470c8384ef6, type: 3} - motionBlurMotionVecPrepCS: {fileID: 7200000, guid: ed9438fa777911d48933402087203b15, type: 3} - motionBlurGenTileCS: {fileID: 7200000, guid: 336e1fdbb3a1b8647b06208415f87804, type: 3} - motionBlurMergeTileCS: {fileID: 7200000, guid: cd14ddf849edeed43b0e3ccf66023038, type: 3} - motionBlurNeighborhoodTileCS: {fileID: 7200000, guid: 5ea9865df3e53b448856785b88f8e7b9, type: 3} + depthOfFieldMipSafeCS: {fileID: 7200000, guid: 2d24ee7b2c804d947a5c371c12ed46bd, + type: 3} + depthOfFieldPrefilterCS: {fileID: 7200000, guid: f2b89d19910854346b792fe7177ce634, + type: 3} + depthOfFieldTileMaxCS: {fileID: 7200000, guid: 84f84585ea8a7a849bea4a581adb93a7, + type: 3} + depthOfFieldGatherCS: {fileID: 7200000, guid: 486be52dddc4e054fb10a7b9b78788c2, + type: 3} + depthOfFieldCombineCS: {fileID: 7200000, guid: c8049ca85c4c7d047ba28f34d800c663, + type: 3} + depthOfFieldPreCombineFarCS: {fileID: 7200000, guid: 3b4a2acd03d1ce2438d93c325d588735, + type: 3} + depthOfFieldClearIndirectArgsCS: {fileID: 7200000, guid: 69905045e1d0a65458b205d6ab55502b, + type: 3} + paniniProjectionCS: {fileID: 7200000, guid: 0ddbf72c8fbb6e44b983f470c8384ef6, + type: 3} + motionBlurMotionVecPrepCS: {fileID: 7200000, guid: ed9438fa777911d48933402087203b15, + type: 3} + motionBlurGenTileCS: {fileID: 7200000, guid: 336e1fdbb3a1b8647b06208415f87804, + type: 3} + motionBlurMergeTileCS: {fileID: 7200000, guid: cd14ddf849edeed43b0e3ccf66023038, + type: 3} + motionBlurNeighborhoodTileCS: {fileID: 7200000, guid: 5ea9865df3e53b448856785b88f8e7b9, + type: 3} motionBlurCS: {fileID: 7200000, guid: 2af5c49c7865edb4b823826970ec176a, type: 3} bloomPrefilterCS: {fileID: 7200000, guid: 243b24008041aaa4a91800690f63c684, type: 3} bloomBlurCS: {fileID: 7200000, guid: 133a68380d324de4ea8d3ff8657b02d8, type: 3} @@ -128,12 +192,17 @@ MonoBehaviour: finalPassPS: {fileID: 4800000, guid: 5ac9ef0c50282754b93c7692488e7ee7, type: 3} clearBlackPS: {fileID: 4800000, guid: 3330c1503ea8c6d4d9408df3f64227eb, type: 3} SMAAPS: {fileID: 4800000, guid: 9655f4aa89a469c49aceaceabf9bc77b, type: 3} - temporalAntialiasingPS: {fileID: 4800000, guid: 3dd9fd928fdb83743b1f27d15df22179, type: 3} - contrastAdaptiveSharpenCS: {fileID: 7200000, guid: 560896aec2f412c48995be35551a4ac6, type: 3} + temporalAntialiasingPS: {fileID: 4800000, guid: 3dd9fd928fdb83743b1f27d15df22179, + type: 3} + contrastAdaptiveSharpenCS: {fileID: 7200000, guid: 560896aec2f412c48995be35551a4ac6, + type: 3} accumulationCS: {fileID: 7200000, guid: ed80add7a217efa468d137d6f7c668f3, type: 3} alphaInjectionPS: {fileID: 4800000, guid: 4edd96259a5e8b44c90479928f0cd11e, type: 3} chromaKeyingPS: {fileID: 4800000, guid: 49feb6b111e82ec4eb6d3d08e4b6903e, type: 3} customClearPS: {fileID: 4800000, guid: 9cef3686fa32c8840947ed99b561195c, type: 3} + ssGIDenoiserCS: {fileID: 7200000, guid: a435d803bc32d0845ba1a713b7a1c8b1, type: 3} + bilateralUpsampleCS: {fileID: 7200000, guid: 68e831c555284d741b985e05369f0e63, + type: 3} textures: debugFontTex: {fileID: 2800000, guid: a3ad2df0e49aaa341a3b3a80f93b3f66, type: 3} colorGradient: {fileID: 2800000, guid: 4ea52e665573c1644bf05dd9b11fd2a4, type: 3} @@ -204,15 +273,20 @@ MonoBehaviour: - {fileID: 2800000, guid: 7641a2b116fafd64d9c3d6459fdfe801, type: 3} - {fileID: 2800000, guid: c6a5e40e6746fef4fa486e8f620ee8d4, type: 3} - {fileID: 2800000, guid: fd4189357c6dfb94fa2d36afbce72086, type: 3} - owenScrambledRGBATex: {fileID: 2800000, guid: b0fe077c1ee7d80428f3d8dfa28a027d, type: 3} - owenScrambled256Tex: {fileID: 2800000, guid: 2a205358e67aa9e4a94a128ac9362f4e, type: 3} + owenScrambledRGBATex: {fileID: 2800000, guid: b0fe077c1ee7d80428f3d8dfa28a027d, + type: 3} + owenScrambled256Tex: {fileID: 2800000, guid: 2a205358e67aa9e4a94a128ac9362f4e, + type: 3} scramblingTex: {fileID: 2800000, guid: bf25cd6288e2c8d43854a61a8496a830, type: 3} rankingTile1SPP: {fileID: 2800000, guid: f2fe0251f704c4c478a8063775cffedb, type: 3} - scramblingTile1SPP: {fileID: 2800000, guid: 6185473f62ad3e74da4acac5d482917a, type: 3} + scramblingTile1SPP: {fileID: 2800000, guid: 6185473f62ad3e74da4acac5d482917a, + type: 3} rankingTile8SPP: {fileID: 2800000, guid: af4bd638a4b3eb14781e6441adcdfbb9, type: 3} - scramblingTile8SPP: {fileID: 2800000, guid: 152f8b933250a7b448fc2d4d301b9944, type: 3} + scramblingTile8SPP: {fileID: 2800000, guid: 152f8b933250a7b448fc2d4d301b9944, + type: 3} rankingTile256SPP: {fileID: 2800000, guid: 1e604a266c415cd46b36d97cd9220aa8, type: 3} - scramblingTile256SPP: {fileID: 2800000, guid: 882fb55d7b3e7c94598a318df9376e32, type: 3} + scramblingTile256SPP: {fileID: 2800000, guid: 882fb55d7b3e7c94598a318df9376e32, + type: 3} filmGrainTex: - {fileID: 2800000, guid: 284a1ac236869fa4eacf377d73c7dff8, type: 3} - {fileID: 2800000, guid: bd74961b009b93145a998ae93a5fc186, type: 3} @@ -228,6 +302,8 @@ MonoBehaviour: SMAAAreaTex: {fileID: 2800000, guid: 92e0d85ab4eca874098e7fcf6f8f674e, type: 3} defaultHDRISky: {fileID: 8900000, guid: 8253d41e6e8b11a4cbe77a4f8f82934d, type: 3} assets: - defaultDiffusionProfile: {fileID: 11400000, guid: 2b7005ba3a4d8474b8cdc34141ad766e, type: 2} - emissiveCylinderMesh: {fileID: 2534964839176971238, guid: accb6d90f0d50fe4ca0f68159b4323de, type: 3} + defaultDiffusionProfile: {fileID: 11400000, guid: 2b7005ba3a4d8474b8cdc34141ad766e, + type: 2} + emissiveCylinderMesh: {fileID: 2534964839176971238, guid: accb6d90f0d50fe4ca0f68159b4323de, + type: 3} emissiveQuadMesh: {fileID: 4300000, guid: 1d5a8595286f94f4bb54171d49f473c3, type: 3} diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Texture/CoherentNoise/RankingTile1SPP.png.meta b/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Texture/CoherentNoise/RankingTile1SPP.png.meta index d9f235db1b6..631232e00f5 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Texture/CoherentNoise/RankingTile1SPP.png.meta +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Texture/CoherentNoise/RankingTile1SPP.png.meta @@ -3,11 +3,11 @@ guid: f2fe0251f704c4c478a8063775cffedb TextureImporter: internalIDToNameTable: [] externalObjects: {} - serializedVersion: 10 + serializedVersion: 11 mipmaps: mipMapMode: 0 enableMipMap: 1 - sRGBTexture: 1 + sRGBTexture: 0 linearTexture: 0 fadeOut: 0 borderMipMap: 0 @@ -23,6 +23,7 @@ TextureImporter: isReadable: 0 streamingMipmaps: 0 streamingMipmapsPriority: 0 + vTOnly: 0 grayScaleToAlpha: 0 generateCubemap: 6 cubemapConvolution: 0 @@ -31,12 +32,12 @@ TextureImporter: maxTextureSize: 2048 textureSettings: serializedVersion: 2 - filterMode: -1 + filterMode: 0 aniso: -1 mipBias: -100 - wrapU: -1 - wrapV: -1 - wrapW: -1 + wrapU: 1 + wrapV: 1 + wrapW: 1 nPOTScale: 1 lightmap: 0 compressionQuality: 50 @@ -48,7 +49,7 @@ TextureImporter: spritePixelsToUnits: 100 spriteBorder: {x: 0, y: 0, z: 0, w: 0} spriteGenerateFallbackPhysicsShape: 1 - alphaUsage: 1 + alphaUsage: 0 alphaIsTransparency: 0 spriteTessellationDetail: -1 textureType: 0 @@ -57,13 +58,27 @@ TextureImporter: maxTextureSizeSet: 0 compressionQualitySet: 0 textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 1 platformSettings: - serializedVersion: 3 buildTarget: DefaultTexturePlatform maxTextureSize: 2048 resizeAlgorithm: 0 textureFormat: -1 - textureCompression: 1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 0 compressionQuality: 50 crunchedCompression: 0 allowsAlphaSplitting: 0 diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Texture/CoherentNoise/ScramblingTile1SPP.png.meta b/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Texture/CoherentNoise/ScramblingTile1SPP.png.meta index fff0a625f95..1486a3ff327 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Texture/CoherentNoise/ScramblingTile1SPP.png.meta +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Texture/CoherentNoise/ScramblingTile1SPP.png.meta @@ -3,11 +3,11 @@ guid: 6185473f62ad3e74da4acac5d482917a TextureImporter: internalIDToNameTable: [] externalObjects: {} - serializedVersion: 10 + serializedVersion: 11 mipmaps: mipMapMode: 0 enableMipMap: 1 - sRGBTexture: 1 + sRGBTexture: 0 linearTexture: 0 fadeOut: 0 borderMipMap: 0 @@ -23,6 +23,7 @@ TextureImporter: isReadable: 0 streamingMipmaps: 0 streamingMipmapsPriority: 0 + vTOnly: 0 grayScaleToAlpha: 0 generateCubemap: 6 cubemapConvolution: 0 @@ -31,12 +32,12 @@ TextureImporter: maxTextureSize: 2048 textureSettings: serializedVersion: 2 - filterMode: -1 - aniso: -1 + filterMode: 0 + aniso: 2 mipBias: -100 - wrapU: -1 - wrapV: -1 - wrapW: -1 + wrapU: 1 + wrapV: 1 + wrapW: 1 nPOTScale: 1 lightmap: 0 compressionQuality: 50 @@ -57,13 +58,27 @@ TextureImporter: maxTextureSizeSet: 0 compressionQualitySet: 0 textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 1 platformSettings: - serializedVersion: 3 buildTarget: DefaultTexturePlatform maxTextureSize: 2048 resizeAlgorithm: 0 textureFormat: -1 - textureCompression: 1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 0 compressionQuality: 50 crunchedCompression: 0 allowsAlphaSplitting: 0 diff --git a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs index c1046fe61a0..e383be28c1b 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs @@ -231,7 +231,7 @@ unsafe struct ShaderVariablesGlobal public Vector4 _CoarseStencilBufferSize; - public int _RaytracedIndirectDiffuse; // Uniform variables that defines if we should be using the raytraced indirect diffuse + public int _UseIndirectDiffuse; // Uniform variables that defines if we should be using the raytraced indirect diffuse public int _UseRayTracedReflections; public int _RaytracingFrameIndex; // Index of the current frame [0, 7] public uint _EnableRecursiveRayTracing; diff --git a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs.hlsl b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs.hlsl index fb99ea3af8c..eaa41b94a68 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs.hlsl @@ -128,7 +128,7 @@ GLOBAL_CBUFFER_START(ShaderVariablesGlobal, b0) uint _XRViewCount; int _FrameCount; float4 _CoarseStencilBufferSize; - int _RaytracedIndirectDiffuse; + int _UseIndirectDiffuse; int _UseRayTracedReflections; int _RaytracingFrameIndex; uint _EnableRecursiveRayTracing;