diff --git a/TestProjects/HDRP_DXR_Tests/LocalPackages/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs.hlsl b/TestProjects/HDRP_DXR_Tests/LocalPackages/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs.hlsl index a593822cbef..6b354cd380c 100644 --- a/TestProjects/HDRP_DXR_Tests/LocalPackages/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs.hlsl +++ b/TestProjects/HDRP_DXR_Tests/LocalPackages/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs.hlsl @@ -4,13 +4,6 @@ #ifndef SHADERCONFIG_CS_HLSL #define SHADERCONFIG_CS_HLSL -// -// UnityEngine.Rendering.HighDefinition.HDShadowFilteringQuality: static fields -// -#define HDSHADOWFILTERINGQUALITY_LOW (0) -#define HDSHADOWFILTERINGQUALITY_MEDIUM (1) -#define HDSHADOWFILTERINGQUALITY_HIGH (2) - // // UnityEngine.Rendering.HighDefinition.ProbeVolumesEvaluationModes: static fields // @@ -45,7 +38,6 @@ #define SHADEROPTIONS_PROBE_VOLUMES_BILATERAL_FILTERING_MODE (1) #define SHADEROPTIONS_PROBE_VOLUMES_ENCODING_MODE (1) #define SHADEROPTIONS_AREA_LIGHTS (1) -#define SHADEROPTIONS_DEFERRED_SHADOW_FILTERING (1) #define SHADEROPTIONS_BARN_DOOR (0) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightEvaluation.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightEvaluation.hlsl index 706a9e1787b..3e93f753279 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightEvaluation.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightEvaluation.hlsl @@ -526,20 +526,17 @@ void EvaluateLight_EnvIntersection(float3 positionWS, float3 normalWS, EnvLightD void InversePreExposeSsrLighting(inout float4 ssrLighting) { - float prevExposureInvMultiplier = GetInversePreviousExposureMultiplier(); - -#if SHADEROPTIONS_RAYTRACING - if (!_UseRayTracedReflections) -#endif - ssrLighting.rgb *= prevExposureInvMultiplier; + // Raytrace reflection use the current frame exposure - TODO: currently the buffer don't use pre-exposure. + // Screen space reflection reuse color buffer from previous frame + float exposureMultiplier = _EnableRayTracedReflections ? 1.0 : GetInversePreviousExposureMultiplier(); + ssrLighting.rgb *= exposureMultiplier; } void ApplyScreenSpaceReflectionWeight(inout float4 ssrLighting) { // Note: RGB is already premultiplied by A for SSR -#if SHADEROPTIONS_RAYTRACING - if (_UseRayTracedReflections) - ssrLighting.rgb *= ssrLighting.a; -#endif + // TODO: check why it isn't consistent between SSR and RTR + float weight = _EnableRayTracedReflections ? 1.0 : ssrLighting.a; + ssrLighting.rgb *= ssrLighting.a; } #endif 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 950f7f75f05..e5cfe8f807a 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,11 +121,6 @@ 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 63b4a6b8c86..b13cb8c12e9 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,9 +59,6 @@ #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 a182d07ec53..1ffc924088f 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 @@ -2,6 +2,9 @@ #if SHADEROPTIONS_PROBE_VOLUMES_EVALUATION_MODE == PROBEVOLUMESEVALUATIONMODES_LIGHT_LOOP #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" +#else +// Required to have access to the indirectDiffuseMode enum in forward pass where we don't include BuiltinUtilities +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/ScreenSpaceGlobalIllumination.cs.hlsl" #endif // We perform scalarization only for forward rendering as for deferred loads will already be scalar since tiles will match waves and therefore all threads will read from the same tile. @@ -534,15 +537,23 @@ void LightLoop( float3 V, PositionInputs posInput, PreLightData preLightData, BS #if !defined(_SURFACE_TYPE_TRANSPARENT) // If we use the texture ssgi for ssgi or rtgi, we want to combine it with the value in the bake diffuse lighting value - if (_UseIndirectDiffuse != INDIRECT_DIFFUSE_FLAG_OFF) + if (_IndirectDiffuseMode != INDIRECTDIFFUSEMODE_OFF) { - BuiltinData builtInDataSSGI; - ZERO_INITIALIZE(BuiltinData, builtInDataSSGI); - builtInDataSSGI.bakeDiffuseLighting = LOAD_TEXTURE2D_X(_IndirectDiffuseTexture, posInput.positionSS).xyz * GetInverseCurrentExposureMultiplier(); - float indirectDiffuseMultiplier = GetIndirectDiffuseMultiplier(builtinData.renderingLayers); - builtInDataSSGI.bakeDiffuseLighting *= indirectDiffuseMultiplier; - ModifyBakedDiffuseLighting(V, posInput, preLightData, bsdfData, builtInDataSSGI); - builtinData.bakeDiffuseLighting += builtInDataSSGI.bakeDiffuseLighting; + BuiltinData builtinDataSSGI; + ZERO_INITIALIZE(BuiltinData, builtinDataSSGI); + builtinDataSSGI.bakeDiffuseLighting = LOAD_TEXTURE2D_X(_IndirectDiffuseTexture, posInput.positionSS).xyz * GetInverseCurrentExposureMultiplier(); + builtinDataSSGI.bakeDiffuseLighting *= GetIndirectDiffuseMultiplier(builtinData.renderingLayers); + + // TODO: try to see if we can share code with probe volume +#ifdef MODIFY_BAKED_DIFFUSE_LIGHTING +#ifdef DEBUG_DISPLAY + // When the lux meter is enabled, we don't want the albedo of the material to modify the diffuse baked lighting + if (_DebugLightingMode != DEBUGLIGHTINGMODE_LUX_METER) +#endif + ModifyBakedDiffuseLighting(V, posInput, preLightData, bsdfData, builtinDataSSGI); + +#endif + builtinData.bakeDiffuseLighting += builtinDataSSGI.bakeDiffuseLighting; } #endif 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 index 4d48d36f971..fa7a5956b10 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/ScreenSpaceGlobalIllumination.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/ScreenSpaceGlobalIllumination.cs @@ -2,6 +2,15 @@ namespace UnityEngine.Rendering.HighDefinition { + [GenerateHLSL] + // Define if we use SSGI, RTGI or none + enum IndirectDiffuseMode + { + Off, + ScreenSpace, + Raytrace + } + public partial class HDRenderPipeline { // Buffers used for the evaluation @@ -52,13 +61,21 @@ void ReleaseScreenSpaceGlobalIllumination() } // This is shared between SSGI and RTGI - bool ValidIndirectDiffuseState(HDCamera hdCamera) + IndirectDiffuseMode GetIndirectDiffuseMode(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; + IndirectDiffuseMode mode = IndirectDiffuseMode.Off; + + if (hdCamera.frameSettings.IsEnabled(FrameSettingsField.SSGI)) + { + var settings = hdCamera.volumeStack.GetComponent(); + if (settings.enable.value) + { + // RTGI is only valid if raytracing is enabled + bool raytracing = hdCamera.frameSettings.IsEnabled(FrameSettingsField.RayTracing) && settings.rayTracing.value; + mode = raytracing ? IndirectDiffuseMode.Raytrace : IndirectDiffuseMode.ScreenSpace; + } + } + return mode; } // Bind the indirect diffuse texture for the lightloop to read from it diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/ScreenSpaceGlobalIllumination.cs.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/ScreenSpaceGlobalIllumination.cs.hlsl new file mode 100644 index 00000000000..f592dfe6892 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/ScreenSpaceGlobalIllumination.cs.hlsl @@ -0,0 +1,15 @@ +// +// This file was automatically generated. Please don't edit by hand. +// + +#ifndef SCREENSPACEGLOBALILLUMINATION_CS_HLSL +#define SCREENSPACEGLOBALILLUMINATION_CS_HLSL +// +// UnityEngine.Rendering.HighDefinition.IndirectDiffuseMode: static fields +// +#define INDIRECTDIFFUSEMODE_OFF (0) +#define INDIRECTDIFFUSEMODE_SCREEN_SPACE (1) +#define INDIRECTDIFFUSEMODE_RAYTRACE (2) + + +#endif diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/ScreenSpaceGlobalIllumination.cs.hlsl.meta b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/ScreenSpaceGlobalIllumination.cs.hlsl.meta new file mode 100644 index 00000000000..08a3fdb9904 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/ScreenSpaceGlobalIllumination.cs.hlsl.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 27b3afeb6fce1d4498775965a8582439 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + preprocessorOverride: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinGIUtilities.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinGIUtilities.hlsl index 1bba1ad2a07..cab6d66d264 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinGIUtilities.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinGIUtilities.hlsl @@ -1,6 +1,9 @@ #ifndef __BUILTINGIUTILITIES_HLSL__ #define __BUILTINGIUTILITIES_HLSL__ +// Include the IndirectDiffuseMode enum +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/ScreenSpaceGlobalIllumination.cs.hlsl" + #ifdef SHADERPASS #if ((SHADEROPTIONS_PROBE_VOLUMES_EVALUATION_MODE == PROBEVOLUMESEVALUATIONMODES_MATERIAL_PASS) && (SHADERPASS == SHADERPASS_GBUFFER || SHADERPASS == SHADERPASS_FORWARD)) || \ ((SHADEROPTIONS_PROBE_VOLUMES_EVALUATION_MODE == PROBEVOLUMESEVALUATIONMODES_LIGHT_LOOP) && (SHADERPASS == SHADERPASS_DEFERRED_LIGHTING || SHADERPASS == SHADERPASS_FORWARD)) @@ -83,14 +86,8 @@ void EvaluateLightProbeBuiltin(float3 positionRWS, float3 normalWS, float3 backN } else { -#if RAYTRACING_ENABLED - if (unity_ProbeVolumeParams.w == 1.0) - SampleProbeVolumeSH9(TEXTURE3D_ARGS(unity_ProbeVolumeSH, samplerunity_ProbeVolumeSH), positionRWS, normalWS, backNormalWS, GetProbeVolumeWorldToObject(), - unity_ProbeVolumeParams.y, unity_ProbeVolumeParams.z, unity_ProbeVolumeMin.xyz, unity_ProbeVolumeSizeInv.xyz, bakeDiffuseLighting, backBakeDiffuseLighting); - else -#endif - SampleProbeVolumeSH4(TEXTURE3D_ARGS(unity_ProbeVolumeSH, samplerunity_ProbeVolumeSH), positionRWS, normalWS, backNormalWS, GetProbeVolumeWorldToObject(), - unity_ProbeVolumeParams.y, unity_ProbeVolumeParams.z, unity_ProbeVolumeMin.xyz, unity_ProbeVolumeSizeInv.xyz, bakeDiffuseLighting, backBakeDiffuseLighting); + SampleProbeVolumeSH4(TEXTURE3D_ARGS(unity_ProbeVolumeSH, samplerunity_ProbeVolumeSH), positionRWS, normalWS, backNormalWS, GetProbeVolumeWorldToObject(), + unity_ProbeVolumeParams.y, unity_ProbeVolumeParams.z, unity_ProbeVolumeMin.xyz, unity_ProbeVolumeSizeInv.xyz, bakeDiffuseLighting, backBakeDiffuseLighting); } } @@ -105,6 +102,18 @@ void SampleBakedGI( out float3 bakeDiffuseLighting, out float3 backBakeDiffuseLighting) { + bakeDiffuseLighting = float3(0, 0, 0); + backBakeDiffuseLighting = float3(0, 0, 0); + + // Check if we are RTGI in which case we don't want to read GI at all (We rely fully on the raytrace effect) + // The check need to be here to work with both regular shader and shader graph + // Note: with Probe volume it will prevent to add the UNINITIALIZED_GI tag and + // the ProbeVolume will not be evaluate in the lightloop which is the desired behavior +#if !defined(_SURFACE_TYPE_TRANSPARENT) + if (_IndirectDiffuseMode == INDIRECTDIFFUSEMODE_RAYTRACE) + return ; +#endif + float3 positionRWS = posInputs.positionWS; #define SAMPLE_LIGHTMAP (defined(LIGHTMAP_ON) || defined(DYNAMICLIGHTMAP_ON)) @@ -112,9 +121,6 @@ void SampleBakedGI( && (!SAMPLE_LIGHTMAP || SHADEROPTIONS_PROBE_VOLUMES_ADDITIVE_BLENDING) #define SAMPLE_PROBEVOLUME_BUILTIN (!SAMPLE_LIGHTMAP && !SAMPLE_PROBEVOLUME) - bakeDiffuseLighting = float3(0, 0, 0); - backBakeDiffuseLighting = float3(0, 0, 0); - #if SAMPLE_LIGHTMAP EvaluateLightmap(positionRWS, normalWS, backNormalWS, uvStaticLightmap, uvDynamicLightmap, bakeDiffuseLighting, backBakeDiffuseLighting); #endif 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 60ec640bba0..5b2bd9f44c4 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl @@ -46,16 +46,6 @@ void InitBuiltinData(PositionInputs posInput, float alpha, float3 normalWS, floa builtinData.backBakeDiffuseLighting = 0.0; SampleBakedGI( posInput, normalWS, backNormalWS, builtinData.renderingLayers, texCoord1.xy, texCoord2.xy, builtinData.bakeDiffuseLighting, builtinData.backBakeDiffuseLighting); - - // 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 (_UseIndirectDiffuse == RAY_TRACED_INDIRECT_DIFFUSE_FLAG) - { - // Incase we shall be using raytraced indirect diffuse, we want to make sure to not add the other forms of indirect lighting to avoid - // double contribution. - builtinData.bakeDiffuseLighting = float3(0.0, 0.0, 0.0); - } -#endif #ifdef SHADOWS_SHADOWMASK float4 shadowMask = SampleShadowMask(posInput.positionWS, texCoord1.xy); diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/SubsurfaceScattering/SubsurfaceScatteringManager.cs b/com.unity.render-pipelines.high-definition/Runtime/Material/SubsurfaceScattering/SubsurfaceScatteringManager.cs index 05a93901fbd..250732fcf0e 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/SubsurfaceScattering/SubsurfaceScatteringManager.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/SubsurfaceScattering/SubsurfaceScatteringManager.cs @@ -390,7 +390,7 @@ void RenderSubsurfaceScattering(HDCamera hdCamera, CommandBuffer cmd, RTHandle c // Now based on the mask, we need to blend the subsurface and the diffuse lighting - bool validSSGI = ValidIndirectDiffuseState(hdCamera); + bool validSSGI = GetIndirectDiffuseMode(hdCamera) != IndirectDiffuseMode.Off; int m_CombineSubSurfaceKernel = rayTracingSubSurfaceCS.FindKernel(validSSGI ? "BlendSubSurfaceDataWithGI" : "BlendSubSurfaceData"); cmd.SetComputeTextureParam(rayTracingSubSurfaceCS, m_CombineSubSurfaceKernel, HDShaderIDs._SubSurfaceLightingBuffer, intermediateBuffer0); cmd.SetComputeTextureParam(rayTracingSubSurfaceCS, m_CombineSubSurfaceKernel, HDShaderIDs._DiffuseLightingTextureRW, diffuseBufferRT); diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs index fd432eb5872..a3c5b74b9f4 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs @@ -102,6 +102,7 @@ void ExecuteWithRenderGraph( RenderRequest renderRequest, // lightCluster.EvaluateClusterDebugView(cmd, hdCamera); // } + // TODO: check code, everything have change // bool validIndirectDiffuse = ValidIndirectDiffuseState(hdCamera); // if (validIndirectDiffuse) // { 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 58a8e2fdd1b..7a1a6f77ef6 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -1266,21 +1266,21 @@ void UpdateShaderVariablesGlobalCB(HDCamera hdCamera, CommandBuffer cmd) m_ShaderVariablesGlobalCB._CoarseStencilBufferSize = new Vector4(coarseStencilWidth, coarseStencilHeight, 1.0f / coarseStencilWidth, 1.0f / coarseStencilHeight); m_ShaderVariablesGlobalCB._RaytracingFrameIndex = RayTracingFrameIndex(hdCamera); + m_ShaderVariablesGlobalCB._IndirectDiffuseMode = (int)GetIndirectDiffuseMode(hdCamera); + if (hdCamera.frameSettings.IsEnabled(FrameSettingsField.RayTracing)) { // Check if recursive rendering is enabled or not. This will control the cull of primitive // during the gbuffer and forward pass - RecursiveRendering recursiveSettings = hdCamera.volumeStack.GetComponent(); ScreenSpaceReflection settings = hdCamera.volumeStack.GetComponent(); - bool usesRaytracedReflections = hdCamera.frameSettings.IsEnabled(FrameSettingsField.RayTracing) && settings.rayTracing.value; - m_ShaderVariablesGlobalCB._UseRayTracedReflections = usesRaytracedReflections ? 1 : 0; - m_ShaderVariablesGlobalCB._UseIndirectDiffuse = ValidIndirectDiffuseState(hdCamera) ? (RayTracedIndirectDiffuseState(hdCamera) ? LightDefinitions.k_RayTracedIndirectDiffuseFlag : LightDefinitions.k_ScreenSpaceIndirectDiffuseFlag) : LightDefinitions.k_IndirectDiffuseFlagOff; + bool enableRaytracedReflections = hdCamera.frameSettings.IsEnabled(FrameSettingsField.RayTracing) && settings.rayTracing.value; + m_ShaderVariablesGlobalCB._EnableRayTracedReflections = enableRaytracedReflections ? 1 : 0; + RecursiveRendering recursiveSettings = hdCamera.volumeStack.GetComponent(); m_ShaderVariablesGlobalCB._EnableRecursiveRayTracing = recursiveSettings.enable.value ? 1u : 0u; } else { - m_ShaderVariablesGlobalCB._UseRayTracedReflections = 0; - m_ShaderVariablesGlobalCB._UseIndirectDiffuse = ValidIndirectDiffuseState(hdCamera) ? LightDefinitions.k_ScreenSpaceIndirectDiffuseFlag : LightDefinitions.k_IndirectDiffuseFlagOff; + m_ShaderVariablesGlobalCB._EnableRayTracedReflections = 0; m_ShaderVariablesGlobalCB._EnableRecursiveRayTracing = 0; } @@ -2603,37 +2603,22 @@ void AsyncSSAODispatch(CommandBuffer c, HDGPUAsyncTaskParams a) HDRaytracingLightCluster lightCluster = RequestLightCluster(); lightCluster.EvaluateClusterDebugView(cmd, hdCamera); } - - bool validIndirectDiffuse = ValidIndirectDiffuseState(hdCamera); - if (validIndirectDiffuse) - { - if (RayTracedIndirectDiffuseState(hdCamera)) - { - RenderRayTracedIndirectDiffuse(hdCamera, cmd, renderContext, m_FrameCount); - } - else - { - RenderSSGI(hdCamera, cmd, renderContext, m_FrameCount); - BindIndirectDiffuseTexture(cmd); - } - } - else - { - BindBlackIndirectDiffuseTexture(cmd); - } } - else + + switch (GetIndirectDiffuseMode(hdCamera)) { - bool validIndirectDiffuse = ValidIndirectDiffuseState(hdCamera); - if (validIndirectDiffuse) - { + case IndirectDiffuseMode.Off: + BindBlackIndirectDiffuseTexture(cmd); + break; + + case IndirectDiffuseMode.ScreenSpace: RenderSSGI(hdCamera, cmd, renderContext, m_FrameCount); BindIndirectDiffuseTexture(cmd); - } - else - { - BindBlackIndirectDiffuseTexture(cmd); - } + break; + + case IndirectDiffuseMode.Raytrace: + RenderRayTracedIndirectDiffuse(hdCamera, cmd, renderContext, m_FrameCount); + break; } if (!hdCamera.frameSettings.SSRRunsAsync()) @@ -5308,7 +5293,16 @@ 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() || ValidIndirectDiffuseState(hdCamera)) + IndirectDiffuseMode indirectDiffuseMode = GetIndirectDiffuseMode(hdCamera); + + // SSGI required the depth of the previous frame + if (indirectDiffuseMode == IndirectDiffuseMode.ScreenSpace) + { + needDepthBuffer = true; + } + + // Raytracing require both normal and depth from previous frame. + if (hdCamera.frameSettings.IsEnabled(FrameSettingsField.RayTracing) && GetRayTracingState()) { needNormalBuffer = true; needDepthBuffer = true; 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 fd34ac79eb1..e9d5614e5f0 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 @@ -15,14 +15,6 @@ void ReleaseRayTracedIndirectDiffuse() { } - bool RayTracedIndirectDiffuseState(HDCamera hdCamera) - { - var settings = hdCamera.volumeStack.GetComponent(); - return ValidIndirectDiffuseState(hdCamera) - && settings.rayTracing.value - && hdCamera.frameSettings.IsEnabled(FrameSettingsField.RayTracing); - } - RTHandle IndirectDiffuseHistoryBufferAllocatorFunction(string viewName, int frameIndex, RTHandleSystem rtHandleSystem) { return rtHandleSystem.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, dimension: TextureXR.dimension, @@ -32,10 +24,6 @@ RTHandle IndirectDiffuseHistoryBufferAllocatorFunction(string viewName, int fram void RenderRayTracedIndirectDiffuse(HDCamera hdCamera, CommandBuffer cmd, ScriptableRenderContext renderContext, int frameCount) { - // 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(); // Based on what the asset supports, follow the volume or force the right mode. 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 11c4a407f0e..f6a6201fcdf 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs @@ -240,8 +240,8 @@ unsafe struct ShaderVariablesGlobal public Vector4 _CoarseStencilBufferSize; - public int _UseIndirectDiffuse; // Uniform variables that defines if we should be using the raytraced indirect diffuse - public int _UseRayTracedReflections; + public int _IndirectDiffuseMode; // Match IndirectDiffuseMode enum in LightLoop.cs + public int _EnableRayTracedReflections; 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 ebe3ecad8b0..15c4a6b84f3 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 @@ -133,8 +133,8 @@ GLOBAL_CBUFFER_START(ShaderVariablesGlobal, b0) uint _XRViewCount; int _FrameCount; float4 _CoarseStencilBufferSize; - int _UseIndirectDiffuse; - int _UseRayTracedReflections; + int _IndirectDiffuseMode; + int _EnableRayTracedReflections; int _RaytracingFrameIndex; uint _EnableRecursiveRayTracing; float4 _ProbeVolumeAtlasResolutionAndSliceCount;