diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/501_RecursiveRendering.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/501_RecursiveRendering.png index 0a8bda173c7..ab6b27f3f3c 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/501_RecursiveRendering.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/501_RecursiveRendering.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4fcb6d155bc04372222b20f973ef94dc3c0447e9af9fb489c4bf59d522458f02 -size 164375 +oid sha256:780cee510502590a10c34e4f73057792db144c28dd6411833131917204553304 +size 164349 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 be91c0a9a6c..05dec005554 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 @@ -3586,7 +3586,6 @@ struct ContactShadowsParameters public bool rayTracingEnabled; public RayTracingShader contactShadowsRTS; public RayTracingAccelerationStructure accelerationStructure; - public float rayTracingBias; public int actualWidth; public int actualHeight; public int depthTextureParameterName; @@ -3606,9 +3605,7 @@ ContactShadowsParameters PrepareContactShadowsParameters(HDCamera hdCamera, floa parameters.rayTracingEnabled = hdCamera.frameSettings.IsEnabled(FrameSettingsField.RayTracing); if (hdCamera.frameSettings.IsEnabled(FrameSettingsField.RayTracing)) { - RayTracingSettings raySettings = hdCamera.volumeStack.GetComponent(); parameters.contactShadowsRTS = m_Asset.renderPipelineRayTracingResources.contactShadowRayTracingRT; - parameters.rayTracingBias = raySettings.rayBias.value; parameters.accelerationStructure = RequestAccelerationStructure(); parameters.actualWidth = hdCamera.actualWidth; @@ -3664,7 +3661,6 @@ static void RenderContactShadows( in ContactShadowsParameters parameters, if (parameters.rayTracingEnabled) { cmd.SetRayTracingShaderPass(parameters.contactShadowsRTS, "VisibilityDXR"); - cmd.SetGlobalFloat(HDShaderIDs._RaytracingRayBias, parameters.rayTracingBias); cmd.SetRayTracingAccelerationStructure(parameters.contactShadowsRTS, HDShaderIDs._RaytracingAccelerationStructureName, parameters.accelerationStructure); cmd.SetRayTracingVectorParam(parameters.contactShadowsRTS, HDShaderIDs._ContactShadowParamsParameters, parameters.params1); diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/AmbientOcclusion.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/AmbientOcclusion.cs index 40bf78c2e80..25273975777 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/AmbientOcclusion.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/AmbientOcclusion.cs @@ -252,7 +252,7 @@ internal void InitRaytracing(HDRenderPipeline renderPipeline) internal bool IsActive(HDCamera camera, AmbientOcclusion settings) => camera.frameSettings.IsEnabled(FrameSettingsField.SSAO) && settings.intensity.value > 0f; - internal void Render(CommandBuffer cmd, HDCamera camera, ScriptableRenderContext renderContext, int frameCount) + internal void Render(CommandBuffer cmd, HDCamera camera, ScriptableRenderContext renderContext, in ShaderVariablesRaytracing globalRTCB, int frameCount) { var settings = camera.volumeStack.GetComponent(); @@ -264,7 +264,7 @@ internal void Render(CommandBuffer cmd, HDCamera camera, ScriptableRenderContext else { if (camera.frameSettings.IsEnabled(FrameSettingsField.RayTracing) && settings.rayTracing.value) - m_RaytracingAmbientOcclusion.RenderAO(camera, cmd, m_AmbientOcclusionTex, renderContext, frameCount); + m_RaytracingAmbientOcclusion.RenderAO(camera, cmd, m_AmbientOcclusionTex, globalRTCB, renderContext, frameCount); else { Dispatch(cmd, camera, frameCount); 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 2b5fc8db8a1..445f66fdd32 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 @@ -28,7 +28,7 @@ void InitScreenSpaceGlobalIllumination() 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; @@ -68,7 +68,7 @@ void BindIndirectDiffuseTexture(CommandBuffer cmd) cmd.SetGlobalTexture(HDShaderIDs._IndirectDiffuseTexture, m_IndirectDiffuseBuffer0); } - // If there is no SSGI, bind a black 1x1 texture + // If there is no SSGI, bind a black 1x1 texture void BindBlackIndirectDiffuseTexture(CommandBuffer cmd) { cmd.SetGlobalTexture(HDShaderIDs._IndirectDiffuseTexture, TextureXR.GetBlackTexture()); @@ -152,10 +152,14 @@ void RenderSSGI(HDCamera hdCamera, CommandBuffer cmd, ScriptableRenderContext re // Fetch the right kernel to use currentKernel = giSettings.fullResolutionSS ? m_ReprojectGlobalIlluminationKernel : m_ReprojectGlobalIlluminationHalfKernel; + // Update global constant buffer. + // This should probably be a shader specific uniform instead of reusing the global constant buffer one since it's the only one udpated here. + m_ShaderVariablesRayTracingCB._RaytracingIntensityClamp = giSettings.clampValueSS; + ConstantBuffer.PushGlobal(cmd, m_ShaderVariablesRayTracingCB, HDShaderIDs._ShaderVariablesRaytracing); + // 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()); @@ -165,7 +169,7 @@ void RenderSSGI(HDCamera hdCamera, CommandBuffer cmd, ScriptableRenderContext re 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); @@ -198,12 +202,12 @@ void RenderSSGI(HDCamera hdCamera, CommandBuffer cmd, ScriptableRenderContext re 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); diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/ScreenSpaceShadowManager.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/ScreenSpaceShadowManager.cs index 9d6428cc704..362860a5c7b 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/ScreenSpaceShadowManager.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/ScreenSpaceShadowManager.cs @@ -337,10 +337,6 @@ void RenderDirectionalLightScreenSpaceShadow(CommandBuffer cmd, HDCamera hdCamer // Inject the ray-tracing sampling data m_BlueNoise.BindDitheredRNGData8SPP(cmd); - // Inject the ray generation data - RayTracingSettings rayTracingSettings = hdCamera.volumeStack.GetComponent(); - cmd.SetGlobalFloat(HDShaderIDs._RaytracingRayBias, rayTracingSettings.rayBias.value); - // Make sure the right closest hit/any hit will be triggered by using the right multi compile CoreUtils.SetKeyword(cmd, "TRANSPARENT_COLOR_SHADOW", m_CurrentSunLightAdditionalLightData.colorShadow); @@ -350,10 +346,13 @@ void RenderDirectionalLightScreenSpaceShadow(CommandBuffer cmd, HDCamera hdCamer // Loop through the samples of this frame for (int sampleIdx = 0; sampleIdx < m_CurrentSunLightAdditionalLightData.numRayTracingSamples; ++sampleIdx) { + // Update global Constant Buffer + m_ShaderVariablesRayTracingCB._RaytracingSampleIndex = sampleIdx; + m_ShaderVariablesRayTracingCB._RaytracingNumSamples = m_CurrentSunLightAdditionalLightData.numRayTracingSamples; + ConstantBuffer.PushGlobal(cmd, m_ShaderVariablesRayTracingCB, HDShaderIDs._ShaderVariablesRaytracing); + // Bind the light & sampling data cmd.SetComputeBufferParam(m_ScreenSpaceShadowsCS, m_RaytracingDirectionalShadowSample, HDShaderIDs._DirectionalLightDatas, m_LightLoopLightData.directionalLightData); - cmd.SetGlobalInt(HDShaderIDs._RaytracingSampleIndex, sampleIdx); - cmd.SetGlobalInt(HDShaderIDs._RaytracingNumSamples, m_CurrentSunLightAdditionalLightData.numRayTracingSamples); // Input Buffer cmd.SetComputeTextureParam(m_ScreenSpaceShadowsCS, m_RaytracingDirectionalShadowSample, HDShaderIDs._DepthTexture, m_SharedRTManager.GetDepthStencilBuffer()); @@ -370,14 +369,12 @@ void RenderDirectionalLightScreenSpaceShadow(CommandBuffer cmd, HDCamera hdCamer // Set ray count texture RayCountManager rayCountManager = GetRayCountManager(); - cmd.SetGlobalInt(HDShaderIDs._RayCountEnabled, rayCountManager.RayCountIsEnabled()); cmd.SetRayTracingTextureParam(m_ScreenSpaceShadowsRT, HDShaderIDs._RayCountTexture, rayCountManager.GetRayCountTexture()); // Input buffers cmd.SetRayTracingTextureParam(m_ScreenSpaceShadowsRT, HDShaderIDs._DepthTexture, m_SharedRTManager.GetDepthStencilBuffer()); cmd.SetRayTracingTextureParam(m_ScreenSpaceShadowsRT, HDShaderIDs._NormalBufferTexture, m_SharedRTManager.GetNormalBuffer()); cmd.SetRayTracingTextureParam(m_ScreenSpaceShadowsRT, HDShaderIDs._RaytracingDirectionBuffer, directionBuffer); - cmd.SetGlobalInt(HDShaderIDs._RaytracingNumSamples, m_CurrentSunLightAdditionalLightData.numRayTracingSamples); // Output buffer cmd.SetRayTracingTextureParam(m_ScreenSpaceShadowsRT, m_CurrentSunLightAdditionalLightData.colorShadow ? HDShaderIDs._RaytracedColorShadowIntegration : HDShaderIDs._RaytracedShadowIntegration, intermediateBuffer0); @@ -546,7 +543,9 @@ void RenderAreaScreenSpaceShadow(CommandBuffer cmd, HDCamera hdCamera cmd.SetComputeBufferParam(m_ScreenSpaceShadowsCS, m_AreaRaytracingAreaShadowPrepassKernel, HDShaderIDs._LightDatas, m_LightLoopLightData.lightData); cmd.SetComputeMatrixParam(m_ScreenSpaceShadowsCS, HDShaderIDs._RaytracingAreaWorldToLocal, m_WorldToLocalArea); cmd.SetComputeIntParam(m_ScreenSpaceShadowsCS, HDShaderIDs._RaytracingTargetAreaLight, lightIndex); - cmd.SetGlobalInt(HDShaderIDs._RaytracingNumSamples, additionalLightData.numRayTracingSamples); + + m_ShaderVariablesRayTracingCB._RaytracingNumSamples = additionalLightData.numRayTracingSamples; + ConstantBuffer.PushGlobal(cmd, m_ShaderVariablesRayTracingCB, HDShaderIDs._ShaderVariablesRaytracing); // Bind the input buffers cmd.SetComputeTextureParam(m_ScreenSpaceShadowsCS, m_AreaRaytracingAreaShadowPrepassKernel, HDShaderIDs._DepthTexture, m_SharedRTManager.GetDepthStencilBuffer()); @@ -579,7 +578,6 @@ void RenderAreaScreenSpaceShadow(CommandBuffer cmd, HDCamera hdCamera // Set ray count texture RayCountManager rayCountManager = GetRayCountManager(); - cmd.SetGlobalInt(HDShaderIDs._RayCountEnabled, rayCountManager.RayCountIsEnabled()); cmd.SetRayTracingTextureParam(m_ScreenSpaceShadowsRT, HDShaderIDs._RayCountTexture, rayCountManager.GetRayCountTexture()); // Input data @@ -591,8 +589,6 @@ void RenderAreaScreenSpaceShadow(CommandBuffer cmd, HDCamera hdCamera cmd.SetRayTracingTextureParam(m_ScreenSpaceShadowsRT, HDShaderIDs._RaytracingDirectionBuffer, directionBuffer); cmd.SetRayTracingTextureParam(m_ScreenSpaceShadowsRT, HDShaderIDs._RaytracingDistanceBuffer, distanceBuffer); cmd.SetRayTracingIntParam(m_ScreenSpaceShadowsRT, HDShaderIDs._RaytracingTargetAreaLight, lightIndex); - RayTracingSettings rayTracingSettings = hdCamera.volumeStack.GetComponent(); - cmd.SetGlobalFloat(HDShaderIDs._RaytracingRayBias, rayTracingSettings.rayBias.value); // Output data cmd.SetRayTracingTextureParam(m_ScreenSpaceShadowsRT, HDShaderIDs._RaytracedAreaShadowIntegration, intermediateBufferRGBA0); @@ -603,12 +599,15 @@ void RenderAreaScreenSpaceShadow(CommandBuffer cmd, HDCamera hdCamera // Let's do the following samples (if any) for (int sampleIndex = 1; sampleIndex < additionalLightData.numRayTracingSamples; ++sampleIndex) { + // Update global Constant Buffer + m_ShaderVariablesRayTracingCB._RaytracingNumSamples = additionalLightData.numRayTracingSamples; + m_ShaderVariablesRayTracingCB._RaytracingSampleIndex = sampleIndex; + ConstantBuffer.PushGlobal(cmd, m_ShaderVariablesRayTracingCB, HDShaderIDs._ShaderVariablesRaytracing); + // Bind the light data cmd.SetComputeBufferParam(m_ScreenSpaceShadowsCS, m_AreaRaytracingAreaShadowNewSampleKernel, HDShaderIDs._LightDatas, m_LightLoopLightData.lightData); cmd.SetComputeIntParam(m_ScreenSpaceShadowsCS, HDShaderIDs._RaytracingTargetAreaLight, lightIndex); - cmd.SetGlobalInt(HDShaderIDs._RaytracingSampleIndex, sampleIndex); cmd.SetComputeMatrixParam(m_ScreenSpaceShadowsCS, HDShaderIDs._RaytracingAreaWorldToLocal, m_WorldToLocalArea); - cmd.SetGlobalInt(HDShaderIDs._RaytracingNumSamples, additionalLightData.numRayTracingSamples); // Input Buffers cmd.SetComputeTextureParam(m_ScreenSpaceShadowsCS, m_AreaRaytracingAreaShadowNewSampleKernel, HDShaderIDs._DepthTexture, m_SharedRTManager.GetDepthStencilBuffer()); @@ -780,21 +779,20 @@ void RenderPunctualScreenSpaceShadow(CommandBuffer cmd, HDCamera hdCamera cmd.DispatchCompute(m_ScreenSpaceShadowsCS, m_ClearShadowTexture, numTilesX, numTilesY, hdCamera.viewCount); } - // Bind the ray generation scalars - RayTracingSettings rayTracingSettings = hdCamera.volumeStack.GetComponent(); - cmd.SetGlobalFloat(HDShaderIDs._RaytracingRayBias, rayTracingSettings.rayBias.value); - // Loop through the samples of this frame for (int sampleIdx = 0; sampleIdx < additionalLightData.numRayTracingSamples; ++sampleIdx) { + // Update global constant buffer + m_ShaderVariablesRayTracingCB._RaytracingSampleIndex = sampleIdx; + m_ShaderVariablesRayTracingCB._RaytracingNumSamples = additionalLightData.numRayTracingSamples; + ConstantBuffer.PushGlobal(cmd, m_ShaderVariablesRayTracingCB, HDShaderIDs._ShaderVariablesRaytracing); + // Bind the right kernel int shadowKernel = lightData.lightType == GPULightType.Point ? m_RaytracingPointShadowSample : m_RaytracingSpotShadowSample; // Bind the light & sampling data cmd.SetComputeBufferParam(m_ScreenSpaceShadowsCS, shadowKernel, HDShaderIDs._LightDatas, m_LightLoopLightData.lightData); cmd.SetComputeIntParam(m_ScreenSpaceShadowsCS, HDShaderIDs._RaytracingTargetAreaLight, lightIndex); - cmd.SetGlobalInt(HDShaderIDs._RaytracingSampleIndex, sampleIdx); - cmd.SetGlobalInt(HDShaderIDs._RaytracingNumSamples, additionalLightData.numRayTracingSamples); cmd.SetComputeFloatParam(m_ScreenSpaceShadowsCS, HDShaderIDs._RaytracingLightRadius, additionalLightData.shapeRadius); // If this is a spot light, inject the spot angle in radians @@ -820,7 +818,6 @@ void RenderPunctualScreenSpaceShadow(CommandBuffer cmd, HDCamera hdCamera // Set ray count texture RayCountManager rayCountManager = GetRayCountManager(); - cmd.SetGlobalInt(HDShaderIDs._RayCountEnabled, rayCountManager.RayCountIsEnabled()); cmd.SetRayTracingTextureParam(m_ScreenSpaceShadowsRT, HDShaderIDs._RayCountTexture, rayCountManager.GetRayCountTexture()); // Input buffers @@ -828,7 +825,6 @@ void RenderPunctualScreenSpaceShadow(CommandBuffer cmd, HDCamera hdCamera cmd.SetRayTracingTextureParam(m_ScreenSpaceShadowsRT, HDShaderIDs._NormalBufferTexture, m_SharedRTManager.GetNormalBuffer()); cmd.SetRayTracingTextureParam(m_ScreenSpaceShadowsRT, HDShaderIDs._RaytracingDirectionBuffer, directionBuffer); cmd.SetRayTracingTextureParam(m_ScreenSpaceShadowsRT, HDShaderIDs._RaytracingDistanceBuffer, distanceBuffer); - cmd.SetGlobalInt(HDShaderIDs._RaytracingNumSamples, additionalLightData.numRayTracingSamples); // Output buffer cmd.SetRayTracingTextureParam(m_ScreenSpaceShadowsRT, HDShaderIDs._RaytracedShadowIntegration, intermediateBuffer0); 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 d3d27f4b498..71f5d006f98 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 @@ -295,7 +295,6 @@ void RenderSubsurfaceScattering(HDCamera hdCamera, CommandBuffer cmd, RTHandle c // Fetch the volume overrides that we shall be using RayTracingShader subSurfaceShader = m_Asset.renderPipelineRayTracingResources.subSurfaceRayTracing; - RayTracingSettings rayTracingSettings = hdCamera.volumeStack.GetComponent(); ComputeShader deferredRayTracing = m_Asset.renderPipelineRayTracingResources.deferredRaytracingCS; // Fetch all the intermediate buffers that we need @@ -327,9 +326,9 @@ void RenderSubsurfaceScattering(HDCamera hdCamera, CommandBuffer cmd, RTHandle c for (int sampleIndex = 0; sampleIndex < settings.sampleCount.value; ++sampleIndex) { // Inject the ray generation data - cmd.SetGlobalFloat(HDShaderIDs._RaytracingRayBias, rayTracingSettings.rayBias.value); - cmd.SetGlobalInt(HDShaderIDs._RaytracingNumSamples, settings.sampleCount.value); - cmd.SetGlobalInt(HDShaderIDs._RaytracingSampleIndex, sampleIndex); + m_ShaderVariablesRayTracingCB._RaytracingNumSamples = settings.sampleCount.value; + m_ShaderVariablesRayTracingCB._RaytracingSampleIndex = sampleIndex; + ConstantBuffer.PushGlobal(cmd, m_ShaderVariablesRayTracingCB, HDShaderIDs._ShaderVariablesRaytracing); // Bind the textures for ray generation cmd.SetRayTracingTextureParam(subSurfaceShader, HDShaderIDs._DepthTexture, sharedRTManager.GetDepthStencilBuffer()); diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.LightLoop.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.LightLoop.cs index a1e33784e5b..caa18d08333 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.LightLoop.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.LightLoop.cs @@ -394,9 +394,6 @@ TextureHandle RenderSSR( RenderGraph renderGraph, } } - // TODO RENDERGRAPH - //cmd.SetGlobalInt(HDShaderIDs._UseRayTracedReflections, usesRaytracedReflections ? 1 : 0); - PushFullScreenDebugTexture(renderGraph, result, FullScreenDebugMode.ScreenSpaceReflections); return result; } 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 d01c88cf40c..9c3b4df7b05 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -190,6 +190,7 @@ internal static Volume GetOrCreateDefaultVolume() ShaderVariablesGlobal m_ShaderVariablesGlobalCB = new ShaderVariablesGlobal(); ShaderVariablesXR m_ShaderVariablesXRCB = new ShaderVariablesXR(); ShaderVariablesDebugDisplay m_ShaderVariablesDebugDisplayCB = new ShaderVariablesDebugDisplay(); + ShaderVariablesRaytracing m_ShaderVariablesRayTracingCB = new ShaderVariablesRaytracing(); // The current MSAA count MSAASamples m_MSAASamples; @@ -1150,6 +1151,16 @@ void Resize(HDCamera hdCamera) } } + void UpdateGlobalConstantBuffers(HDCamera hdCamera, CommandBuffer cmd) + { + UpdateShaderVariablesGlobalCB(hdCamera, cmd); + UpdateShaderVariablesXRCB(hdCamera, cmd); + UpdateShaderVariablesRaytracingCB(hdCamera, cmd); + + // This one is not in a constant buffer because it's only used as a parameter for some shader's render states. It's not actually used inside shader code. + cmd.SetGlobalInt(HDShaderIDs._ColorMaskTransparentVel, (int)ColorWriteMask.All); + } + void UpdateShaderVariablesGlobalCB(HDCamera hdCamera, CommandBuffer cmd) { hdCamera.UpdateShaderVariablesGlobalCB(ref m_ShaderVariablesGlobalCB, m_FrameCount); @@ -1203,13 +1214,33 @@ void UpdateShaderVariablesGlobalCB(HDCamera hdCamera, CommandBuffer cmd) } ConstantBuffer.PushGlobal(cmd, m_ShaderVariablesGlobalCB, HDShaderIDs._ShaderVariablesGlobal); + } + void UpdateShaderVariablesXRCB(HDCamera hdCamera, CommandBuffer cmd) + { hdCamera.xr.UpdateBuiltinStereoMatrices(cmd); hdCamera.UpdateShaderVariablesXRCB(ref m_ShaderVariablesXRCB); ConstantBuffer.PushGlobal(cmd, m_ShaderVariablesXRCB, HDShaderIDs._ShaderVariablesXR); + } - // This one is not in a constant buffer because it's only used as a parameter for some shader's render states. It's not actually used inside shader code. - cmd.SetGlobalInt(HDShaderIDs._ColorMaskTransparentVel, (int)ColorWriteMask.All); + + void UpdateShaderVariablesRaytracingCB(HDCamera hdCamera, CommandBuffer cmd) + { + if (!hdCamera.frameSettings.IsEnabled(FrameSettingsField.RayTracing)) + return; + + RayTracingSettings rayTracingSettings = hdCamera.volumeStack.GetComponent(); + ScreenSpaceReflection screenSpaceReflection = hdCamera.volumeStack.GetComponent(); + + // Those are globally set parameters. The others are set per effect and will update the constant buffer as we render. + m_ShaderVariablesRayTracingCB._RaytracingRayBias = rayTracingSettings.rayBias.value; + m_ShaderVariablesRayTracingCB._RayCountEnabled = m_RayCountManager.RayCountIsEnabled(); + m_ShaderVariablesRayTracingCB._RaytracingCameraNearPlane = hdCamera.camera.nearClipPlane; + m_ShaderVariablesRayTracingCB._RaytracingPixelSpreadAngle = GetPixelSpreadAngle(hdCamera.camera.fieldOfView, hdCamera.actualWidth, hdCamera.actualHeight); + m_ShaderVariablesRayTracingCB._RaytracingReflectionMinSmoothness = screenSpaceReflection.minSmoothness.value; + m_ShaderVariablesRayTracingCB._RaytracingReflectionSmoothnessFadeStart = screenSpaceReflection.smoothnessFadeStart.value; + + ConstantBuffer.PushGlobal(cmd, m_ShaderVariablesRayTracingCB, HDShaderIDs._ShaderVariablesRaytracing); } void CopyDepthBufferIfNeeded(HDCamera hdCamera, CommandBuffer cmd) @@ -2173,7 +2204,7 @@ AOVRequestData aovRequest // So the first thing to do is to go through all the light: PrepareLightsForGPU bool enableBakeShadowMask = PrepareLightsForGPU(cmd, hdCamera, cullingResults, hdProbeCullingResults, densityVolumes, probeVolumes, m_CurrentDebugDisplaySettings, aovRequest); - UpdateShaderVariablesGlobalCB(hdCamera, cmd); + UpdateGlobalConstantBuffers(hdCamera, cmd); // Do the same for ray tracing if allowed if (m_RayTracingSupported) @@ -2509,7 +2540,7 @@ void Callback(CommandBuffer c, HDCamera cam) } if (!hdCamera.frameSettings.SSAORunsAsync()) - m_AmbientOcclusionSystem.Render(cmd, hdCamera, renderContext, m_FrameCount); + m_AmbientOcclusionSystem.Render(cmd, hdCamera, renderContext, m_ShaderVariablesRayTracingCB, m_FrameCount); // Run the contact shadows here as they need the light list HDUtils.CheckRTCreated(m_ContactShadowBuffer); 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 c329a502985..0f491337b7a 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs @@ -291,6 +291,8 @@ static class HDShaderIDs public static readonly int _ShaderVariablesXR = Shader.PropertyToID("ShaderVariablesXR"); public static readonly int _ShaderVariablesVolumetric = Shader.PropertyToID("ShaderVariablesVolumetric"); public static readonly int _ShaderVariablesLightList = Shader.PropertyToID("ShaderVariablesLightList"); + public static readonly int _ShaderVariablesRaytracing = Shader.PropertyToID("ShaderVariablesRaytracing"); + public static readonly int _ShaderVariablesRaytracingLightLoop = Shader.PropertyToID("ShaderVariablesRaytracingLightLoop"); public static readonly int _ShaderVariablesDebugDisplay = Shader.PropertyToID("ShaderVariablesDebugDisplay"); public static readonly int _SSSBufferTexture = Shader.PropertyToID("_SSSBufferTexture"); @@ -455,13 +457,8 @@ static class HDShaderIDs public static readonly int _HorizonZenithShiftScale = Shader.PropertyToID("_HorizonZenithShiftScale"); // Raytracing variables - public static readonly int _RaytracingRayBias = Shader.PropertyToID("_RaytracingRayBias"); public static readonly int _RayTracingLayerMask = Shader.PropertyToID("_RayTracingLayerMask"); - public static readonly int _RaytracingNumSamples = Shader.PropertyToID("_RaytracingNumSamples"); - public static readonly int _RaytracingSampleIndex = Shader.PropertyToID("_RaytracingSampleIndex"); - public static readonly int _RaytracingRayMaxLength = Shader.PropertyToID("_RaytracingRayMaxLength"); public static readonly int _PixelSpreadAngleTangent = Shader.PropertyToID("_PixelSpreadAngleTangent"); - public static readonly int _RaytracingPixelSpreadAngle = Shader.PropertyToID("_RaytracingPixelSpreadAngle"); public static readonly string _RaytracingAccelerationStructureName = "_RaytracingAccelerationStructure"; // Path tracing variables @@ -469,15 +466,10 @@ static class HDShaderIDs public static readonly int _InvViewportScaleBias = Shader.PropertyToID("_InvViewportScaleBias"); // Light Cluster - public static readonly int _MinClusterPos = Shader.PropertyToID("_MinClusterPos"); - public static readonly int _MaxClusterPos = Shader.PropertyToID("_MaxClusterPos"); - public static readonly int _LightPerCellCount = Shader.PropertyToID("_LightPerCellCount"); public static readonly int _LightDatasRT = Shader.PropertyToID("_LightDatasRT"); public static readonly int _EnvLightDatasRT = Shader.PropertyToID("_EnvLightDatasRT"); - public static readonly int _PunctualLightCountRT = Shader.PropertyToID("_PunctualLightCountRT"); - public static readonly int _AreaLightCountRT = Shader.PropertyToID("_AreaLightCountRT"); - public static readonly int _EnvLightCountRT = Shader.PropertyToID("_EnvLightCountRT"); public static readonly int _RaytracingLightCluster = Shader.PropertyToID("_RaytracingLightCluster"); + public static readonly int _RaytracingLightClusterRW = Shader.PropertyToID("_RaytracingLightClusterRW"); // Denoising public static readonly int _HistoryBuffer = Shader.PropertyToID("_HistoryBuffer"); @@ -510,14 +502,8 @@ static class HDShaderIDs public static readonly int _AccumulatedFrameTexture = Shader.PropertyToID("_AccumulatedFrameTexture"); public static readonly int _TemporalAccumuationWeight = Shader.PropertyToID("_TemporalAccumuationWeight"); public static readonly int _SpatialFilterRadius = Shader.PropertyToID("_SpatialFilterRadius"); - public static readonly int _RaytracingReflectionMaxDistance = Shader.PropertyToID("_RaytracingReflectionMaxDistance"); public static readonly int _RaytracingHitDistanceTexture = Shader.PropertyToID("_RaytracingHitDistanceTexture"); - public static readonly int _RaytracingIntensityClamp = Shader.PropertyToID("_RaytracingIntensityClamp"); - public static readonly int _RaytracingPreExposition = Shader.PropertyToID("_RaytracingPreExposition"); - public static readonly int _RaytracingReflectionMinSmoothness = Shader.PropertyToID("_RaytracingReflectionMinSmoothness"); - public static readonly int _RaytracingReflectionSmoothnessFadeStart = Shader.PropertyToID("_RaytracingReflectionSmoothnessFadeStart"); public static readonly int _RaytracingVSNormalTexture = Shader.PropertyToID("_RaytracingVSNormalTexture"); - public static readonly int _RaytracingIncludeSky = Shader.PropertyToID("_RaytracingIncludeSky"); // Shadows public static readonly int _RaytracingTargetAreaLight = Shader.PropertyToID("_RaytracingTargetAreaLight"); @@ -550,7 +536,6 @@ static class HDShaderIDs public static readonly int _RaytracingAOIntensity = Shader.PropertyToID("_RaytracingAOIntensity"); // Ray count - public static readonly int _RayCountEnabled = Shader.PropertyToID("_RayCountEnabled"); public static readonly int _RayCountTexture = Shader.PropertyToID("_RayCountTexture"); public static readonly int _RayCountType = Shader.PropertyToID("_RayCountType"); public static readonly int _InputRayCountTexture = Shader.PropertyToID("_InputRayCountTexture"); @@ -561,10 +546,7 @@ static class HDShaderIDs // Primary Visibility public static readonly int _RaytracingFlagMask = Shader.PropertyToID("_RaytracingFlagMask"); - public static readonly int _RaytracingMinRecursion = Shader.PropertyToID("_RaytracingMinRecursion"); - public static readonly int _RaytracingMaxRecursion = Shader.PropertyToID("_RaytracingMaxRecursion"); public static readonly int _RaytracingPrimaryDebug = Shader.PropertyToID("_RaytracingPrimaryDebug"); - public static readonly int _RaytracingCameraNearPlane = Shader.PropertyToID("_RaytracingCameraNearPlane"); public static readonly int _RaytracingCameraSkyEnabled = Shader.PropertyToID("_RaytracingCameraSkyEnabled"); public static readonly int _RaytracingCameraClearColor = Shader.PropertyToID("_RaytracingCameraClearColor"); @@ -586,7 +568,6 @@ static class HDShaderIDs // Deferred Lighting public static readonly int _RaytracingLitBufferRW = Shader.PropertyToID("_RaytracingLitBufferRW"); - public static readonly int _RaytracingDiffuseRay = Shader.PropertyToID("_RaytracingDiffuseRay"); public static readonly int _RayTracingDiffuseLightingOnly = Shader.PropertyToID("_RayTracingDiffuseLightingOnly"); // Ray binning diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/PathTracing.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/PathTracing.cs index a99363991e8..ba445e3dbad 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/PathTracing.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/PathTracing.cs @@ -229,7 +229,6 @@ void RenderPathTracing(HDCamera hdCamera, CommandBuffer cmd, RTHandle outputText RayTracingAccelerationStructure accelerationStructure = RequestAccelerationStructure(); HDRaytracingLightCluster lightCluster = RequestLightCluster(); LightCluster lightClusterSettings = hdCamera.volumeStack.GetComponent(); - RayTracingSettings rayTracingSettings = hdCamera.volumeStack.GetComponent(); if (!m_SubFrameManager.isRecording) { @@ -255,28 +254,17 @@ void RenderPathTracing(HDCamera hdCamera, CommandBuffer cmd, RTHandle outputText cmd.SetGlobalTexture(HDShaderIDs._OwenScrambledTexture, m_Asset.renderPipelineResources.textures.owenScrambled256Tex); cmd.SetGlobalTexture(HDShaderIDs._ScramblingTexture, m_Asset.renderPipelineResources.textures.scramblingTex); - // Inject the ray generation data - cmd.SetGlobalFloat(HDShaderIDs._RaytracingNumSamples, m_SubFrameManager.subFrameCount); - cmd.SetGlobalFloat(HDShaderIDs._RaytracingMinRecursion, m_PathTracingSettings.minimumDepth.value); - cmd.SetGlobalFloat(HDShaderIDs._RaytracingMaxRecursion, m_PathTracingSettings.maximumDepth.value); - cmd.SetGlobalFloat(HDShaderIDs._RaytracingIntensityClamp, m_PathTracingSettings.maximumIntensity.value); - cmd.SetGlobalFloat(HDShaderIDs._RaytracingRayBias, rayTracingSettings.rayBias.value); - cmd.SetGlobalFloat(HDShaderIDs._RaytracingCameraNearPlane, hdCamera.camera.nearClipPlane); - - // Set the data for the ray generation - cmd.SetGlobalInt(HDShaderIDs._RaytracingSampleIndex, (int)m_SubFrameManager.iteration); - - // Compute an approximate pixel spread angle value (in radians) - cmd.SetGlobalFloat(HDShaderIDs._RaytracingPixelSpreadAngle, GetPixelSpreadAngle(hdCamera.camera.fieldOfView, hdCamera.actualWidth, hdCamera.actualHeight)); + // Update the global constant buffer + m_ShaderVariablesRayTracingCB._RaytracingNumSamples = (int)m_SubFrameManager.subFrameCount; + m_ShaderVariablesRayTracingCB._RaytracingMinRecursion = m_PathTracingSettings.minimumDepth.value; + m_ShaderVariablesRayTracingCB._RaytracingMaxRecursion = m_PathTracingSettings.maximumDepth.value; + m_ShaderVariablesRayTracingCB._RaytracingIntensityClamp = m_PathTracingSettings.maximumIntensity.value; + m_ShaderVariablesRayTracingCB._RaytracingSampleIndex = (int)m_SubFrameManager.iteration; + ConstantBuffer.PushGlobal(cmd, m_ShaderVariablesRayTracingCB, HDShaderIDs._ShaderVariablesRaytracing); // LightLoop data cmd.SetGlobalBuffer(HDShaderIDs._RaytracingLightCluster, lightCluster.GetCluster()); cmd.SetGlobalBuffer(HDShaderIDs._LightDatasRT, lightCluster.GetLightDatas()); - cmd.SetGlobalVector(HDShaderIDs._MinClusterPos, lightCluster.GetMinClusterPos()); - cmd.SetGlobalVector(HDShaderIDs._MaxClusterPos, lightCluster.GetMaxClusterPos()); - cmd.SetGlobalInt(HDShaderIDs._LightPerCellCount, lightClusterSettings.maxNumLightsPercell.value); - cmd.SetGlobalInt(HDShaderIDs._PunctualLightCountRT, lightCluster.GetPunctualLightCount()); - cmd.SetGlobalInt(HDShaderIDs._AreaLightCountRT, lightCluster.GetAreaLightCount()); // Set the data for the ray miss cmd.SetRayTracingIntParam(pathTracingShader, HDShaderIDs._RaytracingCameraSkyEnabled, m_CameraSkyEnabled ? 1 : 0); diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingAmbientOcclusion.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingAmbientOcclusion.cs index ebd651e95a9..1a1937d6113 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingAmbientOcclusion.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingAmbientOcclusion.cs @@ -61,7 +61,7 @@ public void SetDefaultAmbientOcclusionTexture(CommandBuffer cmd) cmd.SetGlobalTexture(HDShaderIDs._AmbientOcclusionTexture, TextureXR.GetBlackTexture()); } - public void RenderAO(HDCamera hdCamera, CommandBuffer cmd, RTHandle outputTexture, ScriptableRenderContext renderContext, int frameCount) + public void RenderAO(HDCamera hdCamera, CommandBuffer cmd, RTHandle outputTexture, ShaderVariablesRaytracing globalCB, ScriptableRenderContext renderContext, int frameCount) { // If any of the previous requirements is missing, the effect is not requested or no acceleration structure, set the default one and leave right away if (!m_RenderPipeline.GetRayTracingState()) @@ -72,7 +72,6 @@ public void RenderAO(HDCamera hdCamera, CommandBuffer cmd, RTHandle outputTextur RayTracingShader aoShader = m_PipelineRayTracingResources.aoRaytracing; var aoSettings = hdCamera.volumeStack.GetComponent(); - RayTracingSettings rayTracingSettings = hdCamera.volumeStack.GetComponent(); RayCountManager rayCountManager = m_RenderPipeline.GetRayCountManager(); using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.RaytracingAmbientOcclusion))) @@ -87,10 +86,9 @@ public void RenderAO(HDCamera hdCamera, CommandBuffer cmd, RTHandle outputTextur cmd.SetRayTracingAccelerationStructure(aoShader, HDShaderIDs._RaytracingAccelerationStructureName, accelerationStructure); // Inject the ray generation data (be careful of the global constant buffer limitation) - cmd.SetGlobalFloat(HDShaderIDs._RaytracingRayBias, rayTracingSettings.rayBias.value); - cmd.SetGlobalFloat(HDShaderIDs._RaytracingRayMaxLength, aoSettings.rayLength.value); - cmd.SetGlobalInt(HDShaderIDs._RaytracingNumSamples, aoSettings.sampleCount.value); - int frameIndex = m_RenderPipeline.RayTracingFrameIndex(hdCamera); + globalCB._RaytracingRayMaxLength = aoSettings.rayLength.value; + globalCB._RaytracingNumSamples = aoSettings.sampleCount.value; + ConstantBuffer.PushGlobal(cmd, globalCB, HDShaderIDs._ShaderVariablesRaytracing); // Set the data for the ray generation cmd.SetRayTracingTextureParam(aoShader, HDShaderIDs._DepthTexture, m_RenderPipeline.sharedRTManager.GetDepthStencilBuffer()); diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingDeferredLightLoop.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingDeferredLightLoop.cs index be5088abae2..1172f0a4958 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingDeferredLightLoop.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingDeferredLightLoop.cs @@ -12,21 +12,14 @@ struct DeferredLightingRTParameters // Generic attributes public bool rayBinning; public LayerMask layerMask; - public float rayBias; - public float maxRayLength; - public float clampValue; - public bool includeSky; public bool diffuseLightingOnly; public bool halfResolution; - public int rayCountFlag; public int rayCountType; - public bool preExpose; // Camera data public int width; public int height; public int viewCount; - public float fov; // Compute buffers public ComputeBuffer rayBinResult; @@ -38,6 +31,8 @@ struct DeferredLightingRTParameters public RayTracingShader gBufferRaytracingRT; public ComputeShader deferredRaytracingCS; public ComputeShader rayBinningCS; + + public ShaderVariablesRaytracing globalCB; } struct DeferredLightingRTResources @@ -187,6 +182,9 @@ static void RenderRaytracingDeferredLighting(CommandBuffer cmd, in DeferredLight BinRays(cmd, parameters, buffers.directionBuffer, texWidth, texHeight); } + // Inject the global parameters + ConstantBuffer.PushGlobal(cmd, parameters.globalCB, HDShaderIDs._ShaderVariablesRaytracing); + // Define the shader pass to use for the reflection pass cmd.SetRayTracingShaderPass(parameters.gBufferRaytracingRT, "GBufferDXR"); @@ -202,18 +200,14 @@ static void RenderRaytracingDeferredLighting(CommandBuffer cmd, in DeferredLight cmd.SetRayTracingAccelerationStructure(parameters.gBufferRaytracingRT, HDShaderIDs._RaytracingAccelerationStructureName, parameters.accelerationStructure); // Set ray count texture - cmd.SetGlobalInt(HDShaderIDs._RayCountEnabled, parameters.rayCountFlag); cmd.SetRayTracingIntParam(parameters.gBufferRaytracingRT, HDShaderIDs._RayCountType, parameters.rayCountType); cmd.SetRayTracingTextureParam(parameters.gBufferRaytracingRT, HDShaderIDs._RayCountTexture, buffers.rayCountTexture); // Bind all input parameter - cmd.SetGlobalFloat(HDShaderIDs._RaytracingRayBias, parameters.rayBias); cmd.SetRayTracingIntParams(parameters.gBufferRaytracingRT, HDShaderIDs._RayTracingLayerMask, parameters.layerMask); - cmd.SetGlobalFloat(HDShaderIDs._RaytracingRayMaxLength, parameters.maxRayLength); cmd.SetRayTracingTextureParam(parameters.gBufferRaytracingRT, HDShaderIDs._DepthTexture, buffers.depthStencilBuffer); cmd.SetRayTracingTextureParam(parameters.gBufferRaytracingRT, HDShaderIDs._NormalBufferTexture, buffers.normalBuffer); cmd.SetRayTracingTextureParam(parameters.gBufferRaytracingRT, HDShaderIDs._RaytracingDirectionBuffer, buffers.directionBuffer); - cmd.SetGlobalFloat(HDShaderIDs._RaytracingPixelSpreadAngle, HDRenderPipeline.GetPixelSpreadAngle(parameters.fov, parameters.width, parameters.height)); // Bind the output textures cmd.SetRayTracingTextureParam(parameters.gBufferRaytracingRT, HDShaderIDs._GBufferTextureRW[0], buffers.gbuffer0); @@ -227,16 +221,12 @@ static void RenderRaytracingDeferredLighting(CommandBuffer cmd, in DeferredLight uint heightResolution = (uint)parameters.height; // Include the sky if required - cmd.SetGlobalInt(HDShaderIDs._RaytracingIncludeSky, parameters.includeSky ? 1 : 0); cmd.SetRayTracingTextureParam(parameters.gBufferRaytracingRT, HDShaderIDs._SkyTexture, buffers.skyTexture); // Only compute diffuse lighting if required cmd.SetGlobalInt(HDShaderIDs._RayTracingDiffuseLightingOnly, parameters.diffuseLightingOnly ? 1 : 0); CoreUtils.SetKeyword(cmd, "MULTI_BOUNCE_INDIRECT", false); - // All rays are diffuse if we are evaluating diffuse lighting only - cmd.SetGlobalInt(HDShaderIDs._RaytracingDiffuseRay, parameters.diffuseLightingOnly ? 1 : 0); - if (parameters.rayBinning) { // Evaluate the dispatch parameters @@ -270,10 +260,6 @@ static void RenderRaytracingDeferredLighting(CommandBuffer cmd, in DeferredLight cmd.SetComputeTextureParam(parameters.deferredRaytracingCS, currentKernel, HDShaderIDs._GBufferTexture[3], buffers.gbuffer3); cmd.SetComputeTextureParam(parameters.deferredRaytracingCS, currentKernel, HDShaderIDs._LightLayersTexture, TextureXR.GetWhiteTexture()); - // Inject the other parameters - cmd.SetGlobalFloat(HDShaderIDs._RaytracingIntensityClamp, parameters.clampValue); - cmd.SetGlobalInt(HDShaderIDs._RaytracingPreExposition, parameters.preExpose ? 1 : 0); - // Bind the output texture cmd.SetComputeTextureParam(parameters.deferredRaytracingCS, currentKernel, HDShaderIDs._RaytracingLitBufferRW, buffers.litBuffer); 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 3c3dc7b7c5e..a557580a22b 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 @@ -114,22 +114,15 @@ DeferredLightingRTParameters PrepareIndirectDiffuseDeferredLightingRTParameters( // Generic attributes deferredParameters.rayBinning = true; deferredParameters.layerMask.value = (int)RayTracingRendererFlag.GlobalIllumination; - deferredParameters.rayBias = rTSettings.rayBias.value; - deferredParameters.maxRayLength = settings.rayLength.value; - deferredParameters.clampValue = settings.clampValue.value; - deferredParameters.includeSky = true; deferredParameters.diffuseLightingOnly = true; deferredParameters.halfResolution = false; - deferredParameters.rayCountFlag = m_RayCountManager.RayCountIsEnabled(); deferredParameters.rayCountType = (int)RayCountValues.DiffuseGI_Deferred; - deferredParameters.preExpose = true; // Camera data deferredParameters.width = hdCamera.actualWidth; deferredParameters.height = hdCamera.actualHeight; deferredParameters.viewCount = hdCamera.viewCount; - deferredParameters.fov = hdCamera.camera.fieldOfView; // Compute buffers deferredParameters.rayBinResult = m_RayBinResult; @@ -149,6 +142,14 @@ DeferredLightingRTParameters PrepareIndirectDiffuseDeferredLightingRTParameters( Debug.LogWarning("Ray binning is not supported with XR single-pass rendering!"); } + deferredParameters.globalCB = m_ShaderVariablesRayTracingCB; + deferredParameters.globalCB._RaytracingIntensityClamp = settings.clampValue.value; + deferredParameters.globalCB._RaytracingPreExposition = 1; + deferredParameters.globalCB._RaytracingDiffuseRay = 1; + deferredParameters.globalCB._RaytracingIncludeSky = 1; + deferredParameters.globalCB._RaytracingRayMaxLength = settings.rayLength.value; + deferredParameters.globalCB._RayTracingDiffuseLightingOnly = deferredParameters.diffuseLightingOnly ? 1 : 0; + return deferredParameters; } @@ -180,9 +181,6 @@ void RenderIndirectDiffusePerformance(HDCamera hdCamera, CommandBuffer cmd, Scri cmd.SetComputeTextureParam(indirectDiffuseCS, currentKernel, HDShaderIDs._DepthTexture, m_SharedRTManager.GetDepthStencilBuffer()); cmd.SetComputeTextureParam(indirectDiffuseCS, currentKernel, HDShaderIDs._NormalBufferTexture, m_SharedRTManager.GetNormalBuffer()); - // Bind all the required scalars - cmd.SetGlobalFloat(HDShaderIDs._RaytracingIntensityClamp, settings.clampValue.value); - // Bind the output buffers cmd.SetComputeTextureParam(indirectDiffuseCS, currentKernel, HDShaderIDs._RaytracingDirectionBuffer, directionBuffer); @@ -246,7 +244,7 @@ void RenderIndirectDiffusePerformance(HDCamera hdCamera, CommandBuffer cmd, Scri void BindRayTracedIndirectDiffuseData(CommandBuffer cmd, HDCamera hdCamera , RayTracingShader indirectDiffuseShader - , GlobalIllumination settings, LightCluster lightClusterSettings, RayTracingSettings rtSettings + , GlobalIllumination settings, LightCluster lightClusterSettings , RTHandle outputLightingBuffer, RTHandle outputHitPointBuffer) { // Grab the acceleration structures and the light cluster to use @@ -263,36 +261,28 @@ void BindRayTracedIndirectDiffuseData(CommandBuffer cmd, HDCamera hdCamera // Inject the ray-tracing sampling data blueNoise.BindDitheredRNGData8SPP(cmd); - // Inject the ray generation data - cmd.SetGlobalFloat(HDShaderIDs._RaytracingRayBias, rtSettings.rayBias.value); - cmd.SetGlobalFloat(HDShaderIDs._RaytracingRayMaxLength, settings.rayLength.value); - cmd.SetGlobalInt(HDShaderIDs._RaytracingNumSamples, settings.sampleCount.value); - // Set the data for the ray generation cmd.SetRayTracingTextureParam(indirectDiffuseShader, HDShaderIDs._IndirectDiffuseTextureRW, outputLightingBuffer); cmd.SetRayTracingTextureParam(indirectDiffuseShader, HDShaderIDs._IndirectDiffuseHitPointTextureRW, outputHitPointBuffer); cmd.SetRayTracingTextureParam(indirectDiffuseShader, HDShaderIDs._DepthTexture, m_SharedRTManager.GetDepthStencilBuffer()); cmd.SetRayTracingTextureParam(indirectDiffuseShader, HDShaderIDs._NormalBufferTexture, m_SharedRTManager.GetNormalBuffer()); - // Set the indirect diffuse parameters - cmd.SetGlobalFloat(HDShaderIDs._RaytracingIntensityClamp, settings.clampValue.value); - // Set ray count texture RayCountManager rayCountManager = GetRayCountManager(); - cmd.SetGlobalInt(HDShaderIDs._RayCountEnabled, rayCountManager.RayCountIsEnabled()); cmd.SetRayTracingTextureParam(indirectDiffuseShader, HDShaderIDs._RayCountTexture, rayCountManager.GetRayCountTexture()); - // Compute the pixel spread value - cmd.SetGlobalFloat(HDShaderIDs._RaytracingPixelSpreadAngle, GetPixelSpreadAngle(hdCamera.camera.fieldOfView, hdCamera.actualWidth, hdCamera.actualHeight)); - // LightLoop data lightCluster.BindLightClusterData(cmd); // Set the data for the ray miss cmd.SetRayTracingTextureParam(indirectDiffuseShader, HDShaderIDs._SkyTexture, m_SkyManager.GetSkyReflection(hdCamera)); - // Set the number of bounces to 1 - cmd.SetGlobalInt(HDShaderIDs._RaytracingMaxRecursion, settings.bounceCount.value); + // Update global constant buffer + m_ShaderVariablesRayTracingCB._RaytracingRayMaxLength = settings.rayLength.value; + m_ShaderVariablesRayTracingCB._RaytracingNumSamples = settings.sampleCount.value; + m_ShaderVariablesRayTracingCB._RaytracingIntensityClamp = settings.clampValue.value; + m_ShaderVariablesRayTracingCB._RaytracingMaxRecursion = settings.bounceCount.value; + ConstantBuffer.PushGlobal(cmd, m_ShaderVariablesRayTracingCB, HDShaderIDs._ShaderVariablesRaytracing); } void RenderIndirectDiffuseQuality(HDCamera hdCamera, CommandBuffer cmd, ScriptableRenderContext renderContext, int frameCount) @@ -300,7 +290,6 @@ void RenderIndirectDiffuseQuality(HDCamera hdCamera, CommandBuffer cmd, Scriptab // First thing to check is: Do we have a valid ray-tracing environment? GlobalIllumination giSettings = hdCamera.volumeStack.GetComponent(); LightCluster lightClusterSettings = hdCamera.volumeStack.GetComponent(); - RayTracingSettings rtSettings = hdCamera.volumeStack.GetComponent(); // Shaders that are used RayTracingShader indirectDiffuseRT = m_Asset.renderPipelineRayTracingResources.indirectDiffuseRaytracingRT; @@ -309,17 +298,19 @@ 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_IndirectDiffuseBuffer0, intermediateBuffer1); + BindRayTracedIndirectDiffuseData(cmd, hdCamera, indirectDiffuseRT, giSettings, lightClusterSettings, m_IndirectDiffuseBuffer0, intermediateBuffer1); // Compute the actual resolution that is needed base on the quality int widthResolution = hdCamera.actualWidth; int heightResolution = hdCamera.actualHeight; + // Only use the shader variant that has multi bounce if the bounce count > 1 CoreUtils.SetKeyword(cmd, "MULTI_BOUNCE_INDIRECT", giSettings.bounceCount.value > 1); // Run the computation - cmd.SetGlobalInt(HDShaderIDs._RayTracingDiffuseLightingOnly, 1); + m_ShaderVariablesRayTracingCB._RayTracingDiffuseLightingOnly = 1; + ConstantBuffer.PushGlobal(cmd, m_ShaderVariablesRayTracingCB, HDShaderIDs._ShaderVariablesRaytracing); cmd.DispatchRays(indirectDiffuseRT, m_RayGenIndirectDiffuseIntegrationName, (uint)widthResolution, (uint)heightResolution, (uint)hdCamera.viewCount); // Disable the keywords we do not need anymore diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingLightCluster.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingLightCluster.cs index e7e1734040d..3f2bf953156 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingLightCluster.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingLightCluster.cs @@ -449,11 +449,8 @@ void BuildLightCluster(HDCamera hdCamera, CommandBuffer cmd) int lightClusterKernel = lightClusterCS.FindKernel(m_LightClusterKernelName); // Inject all the parameters - cmd.SetComputeBufferParam(lightClusterCS, lightClusterKernel, HDShaderIDs._RaytracingLightCluster, m_LightCluster); - cmd.SetComputeVectorParam(lightClusterCS, HDShaderIDs._MinClusterPos, minClusterPos); - cmd.SetComputeVectorParam(lightClusterCS, HDShaderIDs._MaxClusterPos, maxClusterPos); + cmd.SetComputeBufferParam(lightClusterCS, lightClusterKernel, HDShaderIDs._RaytracingLightClusterRW, m_LightCluster); cmd.SetComputeVectorParam(lightClusterCS, _ClusterCellSize, clusterCellSize); - cmd.SetComputeFloatParam(lightClusterCS, HDShaderIDs._LightPerCellCount, HDShadowUtils.Asfloat(numLightsPerCell)); cmd.SetComputeBufferParam(lightClusterCS, lightClusterKernel, _LightVolumes, m_LightVolumeGPUArray); cmd.SetComputeFloatParam(lightClusterCS, _LightVolumeCount, HDShadowUtils.Asfloat(totalLightCount)); @@ -618,10 +615,7 @@ public void EvaluateClusterDebugView(CommandBuffer cmd, HDCamera hdCamera) // Inject all the parameters to the debug compute cmd.SetComputeBufferParam(lightClusterDebugCS, m_LightClusterDebugKernel, HDShaderIDs._RaytracingLightCluster, m_LightCluster); - cmd.SetComputeVectorParam(lightClusterDebugCS, HDShaderIDs._MinClusterPos, minClusterPos); - cmd.SetComputeVectorParam(lightClusterDebugCS, HDShaderIDs._MaxClusterPos, maxClusterPos); cmd.SetComputeVectorParam(lightClusterDebugCS, _ClusterCellSize, clusterCellSize); - cmd.SetComputeIntParam(lightClusterDebugCS, HDShaderIDs._LightPerCellCount, numLightsPerCell); cmd.SetComputeTextureParam(lightClusterDebugCS, m_LightClusterDebugKernel, HDShaderIDs._CameraDepthTexture, m_RenderPipeline.sharedRTManager.GetDepthStencilBuffer()); // Target output texture @@ -640,10 +634,7 @@ public void EvaluateClusterDebugView(CommandBuffer cmd, HDCamera hdCamera) // Bind the parameters m_DebugMaterialProperties.SetBuffer(HDShaderIDs._RaytracingLightCluster, m_LightCluster); - m_DebugMaterialProperties.SetVector(HDShaderIDs._MinClusterPos, minClusterPos); - m_DebugMaterialProperties.SetVector(HDShaderIDs._MaxClusterPos, maxClusterPos); m_DebugMaterialProperties.SetVector(_ClusterCellSize, clusterCellSize); - m_DebugMaterialProperties.SetInt(HDShaderIDs._LightPerCellCount, numLightsPerCell); m_DebugMaterialProperties.SetTexture(HDShaderIDs._CameraDepthTexture, m_RenderPipeline.sharedRTManager.GetDepthTexture()); // Draw the faces @@ -698,6 +689,11 @@ public int GetEnvLightCount() return envLightCount; } + public int GetLightPerCellCount() + { + return numLightsPerCell; + } + void InvalidateCluster() { // Invalidate the cluster's bounds so that we never access the buffer @@ -735,7 +731,14 @@ public void CullForRayTracing(CommandBuffer cmd, HDCamera hdCamera, HDRayTracing // Evaluate the volume of the cluster EvaluateClusterVolume(hdCamera); + } + public void BuildLightClusterBuffer(CommandBuffer cmd, HDCamera hdCamera, HDRayTracingLights rayTracingLights) + { + // If there is no lights to process or no environment not the shader is missing + if (totalLightCount == 0 || rayTracingLights.lightCount == 0 || !m_RenderPipeline.GetRayTracingState()) + return; + // Cull the lights within the evaluated cluster range CullLights(cmd); @@ -772,12 +775,6 @@ public void BindLightClusterData(CommandBuffer cmd) cmd.SetGlobalBuffer(HDShaderIDs._RaytracingLightCluster, GetCluster()); cmd.SetGlobalBuffer(HDShaderIDs._LightDatasRT, GetLightDatas()); cmd.SetGlobalBuffer(HDShaderIDs._EnvLightDatasRT, GetEnvLightDatas()); - cmd.SetGlobalVector(HDShaderIDs._MinClusterPos, GetMinClusterPos()); - cmd.SetGlobalVector(HDShaderIDs._MaxClusterPos, GetMaxClusterPos()); - cmd.SetGlobalInt(HDShaderIDs._LightPerCellCount, numLightsPerCell); - cmd.SetGlobalInt(HDShaderIDs._PunctualLightCountRT, GetPunctualLightCount()); - cmd.SetGlobalInt(HDShaderIDs._AreaLightCountRT, GetAreaLightCount()); - cmd.SetGlobalInt(HDShaderIDs._EnvLightCountRT, GetEnvLightCount()); } } } 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 9e64dcc10cc..98d4d13b064 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 @@ -110,6 +110,8 @@ public partial class HDRenderPipeline RTHandle m_RayTracingIntermediateBufferRGBA3; RTHandle m_RayTracingIntermediateBufferRGBA4; + ShaderVariablesRaytracingLightLoop m_ShaderVariablesRaytracingLightLoopCB = new ShaderVariablesRaytracingLightLoop(); + internal void InitRayTracingManager() { // Init the ray count manager @@ -538,7 +540,7 @@ internal int RayTracingFrameIndex(HDCamera hdCamera) #endif return hdCamera.IsTAAEnabled() ? hdCamera.taaFrameIndex : (int)m_FrameCount % 8; } - + internal bool RayTracingLightClusterRequired(HDCamera hdCamera) { ScreenSpaceReflection reflSettings = hdCamera.volumeStack.GetComponent(); @@ -547,10 +549,10 @@ internal bool RayTracingLightClusterRequired(HDCamera hdCamera) PathTracing pathTracingSettings = hdCamera.volumeStack.GetComponent(); SubSurfaceScattering subSurface = hdCamera.volumeStack.GetComponent(); - return (m_ValidRayTracingState && (reflSettings.rayTracing.value - || giSettings.rayTracing.value - || recursiveSettings.enable.value - || pathTracingSettings.enable.value + return (m_ValidRayTracingState && (reflSettings.rayTracing.value + || giSettings.rayTracing.value + || recursiveSettings.enable.value + || pathTracingSettings.enable.value || subSurface.rayTracing.value)); } @@ -577,9 +579,25 @@ internal void BuildRayTracingLightData(CommandBuffer cmd, HDCamera hdCamera, Deb { m_RayTracingLightCluster.BuildRayTracingLightData(cmd, hdCamera, m_RayTracingLights, debugDisplaySettings); m_ValidRayTracingCluster = true; + + UpdateShaderVariablesRaytracingLightLoopCB(hdCamera, cmd); + + m_RayTracingLightCluster.BuildLightClusterBuffer(cmd, hdCamera, m_RayTracingLights); } } + void UpdateShaderVariablesRaytracingLightLoopCB(HDCamera hdCamera, CommandBuffer cmd) + { + m_ShaderVariablesRaytracingLightLoopCB._MinClusterPos = m_RayTracingLightCluster.GetMinClusterPos(); + m_ShaderVariablesRaytracingLightLoopCB._LightPerCellCount = (uint)m_RayTracingLightCluster.GetLightPerCellCount(); + m_ShaderVariablesRaytracingLightLoopCB._MaxClusterPos = m_RayTracingLightCluster.GetMaxClusterPos(); + m_ShaderVariablesRaytracingLightLoopCB._PunctualLightCountRT = (uint)m_RayTracingLightCluster.GetPunctualLightCount(); + m_ShaderVariablesRaytracingLightLoopCB._AreaLightCountRT = (uint)m_RayTracingLightCluster.GetAreaLightCount(); + m_ShaderVariablesRaytracingLightLoopCB._EnvLightCountRT = (uint)m_RayTracingLightCluster.GetEnvLightCount(); + + ConstantBuffer.PushGlobal(cmd, m_ShaderVariablesRaytracingLightLoopCB, HDShaderIDs._ShaderVariablesRaytracingLightLoop); + } + internal RayTracingAccelerationStructure RequestAccelerationStructure() { if (m_ValidRayTracingState) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingRecursiveRenderer.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingRecursiveRenderer.cs index 95069654878..32d1f876c97 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingRecursiveRenderer.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingRecursiveRenderer.cs @@ -77,14 +77,10 @@ void RaytracingRecursiveRender(HDCamera hdCamera, CommandBuffer cmd, ScriptableR cmd.SetRayTracingTextureParam(forwardShader, HDShaderIDs._OwenScrambledTexture, m_Asset.renderPipelineResources.textures.owenScrambledRGBATex); cmd.SetRayTracingTextureParam(forwardShader, HDShaderIDs._ScramblingTexture, m_Asset.renderPipelineResources.textures.scramblingTex); - // Inject the ray generation data - cmd.SetGlobalFloat(HDShaderIDs._RaytracingRayBias, rtSettings.rayBias.value); - cmd.SetGlobalFloat(HDShaderIDs._RaytracingRayMaxLength, recursiveSettings.rayLength.value); - cmd.SetGlobalFloat(HDShaderIDs._RaytracingMaxRecursion, recursiveSettings.maxDepth.value); - cmd.SetGlobalFloat(HDShaderIDs._RaytracingCameraNearPlane, hdCamera.camera.nearClipPlane); - cmd.SetGlobalFloat(HDShaderIDs._RaytracingReflectionMinSmoothness, recursiveSettings.minSmoothness.value); - - // Set the data for the ray generation + // Update Global Constant Buffer. + m_ShaderVariablesRayTracingCB._RaytracingRayMaxLength = recursiveSettings.rayLength.value; + m_ShaderVariablesRayTracingCB._RaytracingMaxRecursion = recursiveSettings.maxDepth.value; + ConstantBuffer.PushGlobal(cmd, m_ShaderVariablesRayTracingCB, HDShaderIDs._ShaderVariablesRaytracing); // Fecth the temporary buffers we shall be using RTHandle flagBuffer = GetRayTracingBuffer(InternalRayTracingBuffers.R0); @@ -94,12 +90,8 @@ void RaytracingRecursiveRender(HDCamera hdCamera, CommandBuffer cmd, ScriptableR // Set ray count texture RayCountManager rayCountManager = GetRayCountManager(); - cmd.SetGlobalInt(HDShaderIDs._RayCountEnabled, rayCountManager.RayCountIsEnabled()); cmd.SetRayTracingTextureParam(forwardShader, HDShaderIDs._RayCountTexture, rayCountManager.GetRayCountTexture()); - // Compute an approximate pixel spread angle value (in radians) - cmd.SetGlobalFloat(HDShaderIDs._RaytracingPixelSpreadAngle, GetPixelSpreadAngle(hdCamera.camera.fieldOfView, hdCamera.actualWidth, hdCamera.actualHeight)); - // LightLoop data lightCluster.BindLightClusterData(cmd); diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingReflection.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingReflection.cs index d246bfdf661..b285371c2e8 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingReflection.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingReflection.cs @@ -65,8 +65,8 @@ void RenderRayTracedReflections(HDCamera hdCamera, CommandBuffer cmd, RTHandle o } } - void BindRayTracedReflectionData(CommandBuffer cmd, HDCamera hdCamera, RayTracingShader reflectionShader, ScreenSpaceReflection settings, LightCluster lightClusterSettings, RayTracingSettings rtSettings - , RTHandle outputLightingBuffer, RTHandle outputHitPointBuffer) + void BindRayTracedReflectionData(CommandBuffer cmd, HDCamera hdCamera, RayTracingShader reflectionShader, ScreenSpaceReflection settings, LightCluster lightClusterSettings, + RTHandle outputLightingBuffer, RTHandle outputHitPointBuffer) { // Grab the acceleration structures and the light cluster to use RayTracingAccelerationStructure accelerationStructure = RequestAccelerationStructure(); @@ -80,15 +80,14 @@ void BindRayTracedReflectionData(CommandBuffer cmd, HDCamera hdCamera, RayTracin cmd.SetRayTracingAccelerationStructure(reflectionShader, HDShaderIDs._RaytracingAccelerationStructureName, accelerationStructure); // Global reflection parameters - cmd.SetGlobalFloat(HDShaderIDs._RaytracingIntensityClamp, settings.clampValue.value); - cmd.SetGlobalFloat(HDShaderIDs._RaytracingReflectionMinSmoothness, settings.minSmoothness.value); - cmd.SetGlobalFloat(HDShaderIDs._RaytracingReflectionSmoothnessFadeStart, settings.smoothnessFadeStart.value); - cmd.SetGlobalInt(HDShaderIDs._RaytracingIncludeSky, settings.reflectSky.value ? 1 : 0); - + m_ShaderVariablesRayTracingCB._RaytracingIntensityClamp = settings.clampValue.value; + m_ShaderVariablesRayTracingCB._RaytracingIncludeSky = settings.reflectSky.value ? 1 : 0; // Inject the ray generation data - cmd.SetGlobalFloat(HDShaderIDs._RaytracingRayBias, rtSettings.rayBias.value); - cmd.SetGlobalFloat(HDShaderIDs._RaytracingRayMaxLength, settings.rayLength.value); - cmd.SetGlobalInt(HDShaderIDs._RaytracingNumSamples, settings.sampleCount.value); + m_ShaderVariablesRayTracingCB._RaytracingRayMaxLength = settings.rayLength.value; + m_ShaderVariablesRayTracingCB._RaytracingNumSamples = settings.sampleCount.value; + // Set the number of bounces for reflections + m_ShaderVariablesRayTracingCB._RaytracingMaxRecursion = settings.bounceCount.value; + ConstantBuffer.PushGlobal(cmd, m_ShaderVariablesRayTracingCB, HDShaderIDs._ShaderVariablesRaytracing); // Inject the ray-tracing sampling data blueNoise.BindDitheredRNGData8SPP(cmd); @@ -103,12 +102,8 @@ void BindRayTracedReflectionData(CommandBuffer cmd, HDCamera hdCamera, RayTracin // Set ray count tex RayCountManager rayCountManager = GetRayCountManager(); - cmd.SetGlobalInt(HDShaderIDs._RayCountEnabled, rayCountManager.RayCountIsEnabled()); cmd.SetRayTracingTextureParam(reflectionShader, HDShaderIDs._RayCountTexture, rayCountManager.GetRayCountTexture()); - // Compute the pixel spread value - cmd.SetGlobalFloat(HDShaderIDs._RaytracingPixelSpreadAngle, GetPixelSpreadAngle(hdCamera.camera.fieldOfView, hdCamera.actualWidth, hdCamera.actualHeight)); - // Bind the lightLoop data lightCluster.BindLightClusterData(cmd); @@ -119,9 +114,6 @@ void BindRayTracedReflectionData(CommandBuffer cmd, HDCamera hdCamera, RayTracin RenderTargetIdentifier clearCoatMaskTexture = hdCamera.frameSettings.litShaderMode == LitShaderMode.Deferred ? m_GbufferManager.GetBuffersRTI()[2] : TextureXR.GetBlackTexture(); cmd.SetRayTracingTextureParam(reflectionShader, HDShaderIDs._SsrClearCoatMaskTexture, clearCoatMaskTexture); - // Set the number of bounces for reflections - cmd.SetGlobalInt(HDShaderIDs._RaytracingMaxRecursion, settings.bounceCount.value); - // Set the data for the ray miss cmd.SetRayTracingTextureParam(reflectionShader, HDShaderIDs._SkyTexture, m_SkyManager.GetSkyReflection(hdCamera)); } @@ -140,21 +132,14 @@ DeferredLightingRTParameters PrepareReflectionDeferredLightingRTParameters(HDCam // Generic attributes deferredParameters.rayBinning = true; deferredParameters.layerMask.value = (int)RayTracingRendererFlag.Reflection; - deferredParameters.rayBias = rTSettings.rayBias.value; - deferredParameters.maxRayLength = settings.rayLength.value; - deferredParameters.clampValue = settings.clampValue.value; - deferredParameters.includeSky = settings.reflectSky.value; deferredParameters.diffuseLightingOnly = false; deferredParameters.halfResolution = !settings.fullResolution.value; - deferredParameters.rayCountFlag = m_RayCountManager.RayCountIsEnabled(); deferredParameters.rayCountType = (int)RayCountValues.ReflectionDeferred; - deferredParameters.preExpose = false; // Camera data deferredParameters.width = hdCamera.actualWidth; deferredParameters.height = hdCamera.actualHeight; deferredParameters.viewCount = hdCamera.viewCount; - deferredParameters.fov = hdCamera.camera.fieldOfView; // Compute buffers deferredParameters.rayBinResult = m_RayBinResult; @@ -174,6 +159,13 @@ DeferredLightingRTParameters PrepareReflectionDeferredLightingRTParameters(HDCam Debug.LogWarning("Ray binning is not supported with XR single-pass rendering!"); } + deferredParameters.globalCB = m_ShaderVariablesRayTracingCB; + deferredParameters.globalCB._RaytracingRayMaxLength = settings.rayLength.value; + deferredParameters.globalCB._RaytracingIntensityClamp = settings.clampValue.value; + deferredParameters.globalCB._RaytracingIncludeSky = settings.reflectSky.value ? 1 : 0; + deferredParameters.globalCB._RaytracingPreExposition = 0; + deferredParameters.globalCB._RaytracingDiffuseRay = 0; + return deferredParameters; } @@ -228,9 +220,9 @@ void RenderReflectionsPerformance(HDCamera hdCamera, CommandBuffer cmd, RTHandle cmd.SetComputeTextureParam(reflectionShaderCS, currentKernel, HDShaderIDs._StencilTexture, m_SharedRTManager.GetDepthStencilBuffer(), 0, RenderTextureSubElement.Stencil); // Bind all the required scalars - cmd.SetGlobalFloat(HDShaderIDs._RaytracingIntensityClamp, settings.clampValue.value); - cmd.SetGlobalFloat(HDShaderIDs._RaytracingReflectionMinSmoothness, settings.minSmoothness.value); - cmd.SetGlobalInt(HDShaderIDs._RaytracingIncludeSky, settings.reflectSky.value ? 1 : 0); + m_ShaderVariablesRayTracingCB._RaytracingIntensityClamp = settings.clampValue.value; + m_ShaderVariablesRayTracingCB._RaytracingIncludeSky = settings.reflectSky.value ? 1 : 0; + ConstantBuffer.PushGlobal(cmd, m_ShaderVariablesRayTracingCB, HDShaderIDs._ShaderVariablesRaytracing); // Bind the output buffers cmd.SetComputeTextureParam(reflectionShaderCS, currentKernel, HDShaderIDs._RaytracingDirectionBuffer, intermediateBuffer1); @@ -278,8 +270,6 @@ void RenderReflectionsPerformance(HDCamera hdCamera, CommandBuffer cmd, RTHandle cmd.SetComputeTextureParam(reflectionFilter, currentKernel, HDShaderIDs._ScramblingTexture, m_Asset.renderPipelineResources.textures.scramblingTex); cmd.SetComputeIntParam(reflectionFilter, HDShaderIDs._SpatialFilterRadius, settings.upscaleRadius.value); cmd.SetComputeIntParam(reflectionFilter, HDShaderIDs._RaytracingDenoiseRadius, settings.denoise.value ? settings.denoiserRadius.value : 0); - cmd.SetGlobalFloat(HDShaderIDs._RaytracingReflectionMinSmoothness, settings.minSmoothness.value); - cmd.SetGlobalFloat(HDShaderIDs._RaytracingReflectionSmoothnessFadeStart, settings.smoothnessFadeStart.value); numTilesXHR = (texWidth + (areaTileSize - 1)) / areaTileSize; numTilesYHR = (texHeight + (areaTileSize - 1)) / areaTileSize; @@ -328,18 +318,18 @@ void RenderReflectionsQuality(HDCamera hdCamera, CommandBuffer cmd, RTHandle out var settings = hdCamera.volumeStack.GetComponent(); LightCluster lightClusterSettings = hdCamera.volumeStack.GetComponent(); - RayTracingSettings rtSettings = hdCamera.volumeStack.GetComponent(); using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.RaytracingIntegrateReflection))) { // Bind all the required data for ray tracing - BindRayTracedReflectionData(cmd, hdCamera, reflectionShader, settings, lightClusterSettings, rtSettings, intermediateBuffer0, intermediateBuffer1); + BindRayTracedReflectionData(cmd, hdCamera, reflectionShader, settings, lightClusterSettings, intermediateBuffer0, intermediateBuffer1); // Only use the shader variant that has multi bounce if the bounce count > 1 CoreUtils.SetKeyword(cmd, "MULTI_BOUNCE_INDIRECT", settings.bounceCount.value > 1); // We are not in the diffuse only case - cmd.SetGlobalInt(HDShaderIDs._RayTracingDiffuseLightingOnly, 0); + m_ShaderVariablesRayTracingCB._RayTracingDiffuseLightingOnly = 0; + ConstantBuffer.PushGlobal(cmd, m_ShaderVariablesRayTracingCB, HDShaderIDs._ShaderVariablesRaytracing); // Run the computation cmd.DispatchRays(reflectionShader, transparent ? m_RayGenIntegrationTransparentName : m_RayGenIntegrationName, (uint)hdCamera.actualWidth, (uint)hdCamera.actualHeight, (uint)hdCamera.viewCount); diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDReflectionDenoiser.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDReflectionDenoiser.cs index b0cf11ec1a0..88192bfabdc 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDReflectionDenoiser.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDReflectionDenoiser.cs @@ -75,7 +75,6 @@ public void DenoiseBuffer(CommandBuffer cmd, HDCamera hdCamera, int maxKernelSiz cmd.SetComputeTextureParam(m_ReflectionDenoiserCS, s_BilateralFilterHKernel, HDShaderIDs._NormalBufferTexture, m_SharedRTManager.GetNormalBuffer()); cmd.SetComputeTextureParam(m_ReflectionDenoiserCS, s_BilateralFilterHKernel, HDShaderIDs._DenoiseOutputTextureRW, intermediateBuffer1); cmd.SetComputeTextureParam(m_ReflectionDenoiserCS, s_BilateralFilterHKernel, HDShaderIDs._ReflectionFilterMapping, m_ReflectionFilterMapping); - cmd.SetGlobalFloat(HDShaderIDs._RaytracingReflectionMinSmoothness, settings.minSmoothness.value); cmd.DispatchCompute(m_ReflectionDenoiserCS, s_BilateralFilterHKernel, numTilesX, numTilesY, hdCamera.viewCount); // Horizontal pass of the bilateral filter @@ -85,7 +84,6 @@ public void DenoiseBuffer(CommandBuffer cmd, HDCamera hdCamera, int maxKernelSiz cmd.SetComputeTextureParam(m_ReflectionDenoiserCS, s_BilateralFilterVKernel, HDShaderIDs._NormalBufferTexture, m_SharedRTManager.GetNormalBuffer()); cmd.SetComputeTextureParam(m_ReflectionDenoiserCS, s_BilateralFilterVKernel, HDShaderIDs._DenoiseOutputTextureRW, outputSignal); cmd.SetComputeTextureParam(m_ReflectionDenoiserCS, s_BilateralFilterVKernel, HDShaderIDs._ReflectionFilterMapping, m_ReflectionFilterMapping); - cmd.SetGlobalFloat(HDShaderIDs._RaytracingReflectionMinSmoothness, settings.minSmoothness.value); cmd.DispatchCompute(m_ReflectionDenoiserCS, s_BilateralFilterVKernel, numTilesX, numTilesY, hdCamera.viewCount); } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingLightCluster.compute b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingLightCluster.compute index e1529dabe20..a1a1bf1e5c2 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingLightCluster.compute +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingLightCluster.compute @@ -5,8 +5,9 @@ // SRP & HDRP includes #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" -#include "Packages/com.unity.render-pipelines.high-definition\Runtime\ShaderLibrary\ShaderVariables.hlsl" -#include "Packages/com.unity.render-pipelines.high-definition\Runtime\RenderPipeline\Raytracing/HDRaytracingLightCluster.cs.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingLightCluster.cs.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracingLightLoop.hlsl" #define CLUSTER_GROUP_SIZE 8 @@ -15,11 +16,8 @@ StructuredBuffer _LightVolumes; uint _LightVolumeCount; // The target data that this computer shader must fill -RWStructuredBuffer _RaytracingLightCluster; -float3 _MinClusterPos; -float3 _MaxClusterPos; +RWStructuredBuffer _RaytracingLightClusterRW; float3 _ClusterCellSize; -uint _LightPerCellCount; static const float3 CornerSubDirections[8] = { float3(-0.5f, -0.5f, -0.5f), @@ -123,7 +121,7 @@ void RaytracingLightCluster(uint3 threadID : SV_GroupThreadID, uint3 groupId : S if(intersects) { // Flag this light in this cell and increase the light count - _RaytracingLightCluster[cellIndex * cellDataSize + 4 + currentLightCount] = currentLight.lightIndex; + _RaytracingLightClusterRW[cellIndex * cellDataSize + 4 + currentLightCount] = currentLight.lightIndex; currentLightCount++; // Also increase the matching light count @@ -143,10 +141,10 @@ void RaytracingLightCluster(uint3 threadID : SV_GroupThreadID, uint3 groupId : S } // Set the light count for the cell - _RaytracingLightCluster[cellIndex * cellDataSize] = currentLightCount; - _RaytracingLightCluster[cellIndex * cellDataSize + 1] = punctualLightCount; - _RaytracingLightCluster[cellIndex * cellDataSize + 2] = punctualLightCount + areaLightCount; - _RaytracingLightCluster[cellIndex * cellDataSize + 3] = areaLightCount + punctualLightCount + envLightCount; + _RaytracingLightClusterRW[cellIndex * cellDataSize] = currentLightCount; + _RaytracingLightClusterRW[cellIndex * cellDataSize + 1] = punctualLightCount; + _RaytracingLightClusterRW[cellIndex * cellDataSize + 2] = punctualLightCount + areaLightCount; + _RaytracingLightClusterRW[cellIndex * cellDataSize + 3] = areaLightCount + punctualLightCount + envLightCount; } diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.cs new file mode 100644 index 00000000000..1dd95d2a89b --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.cs @@ -0,0 +1,36 @@ +namespace UnityEngine.Rendering.HighDefinition +{ + [GenerateHLSL(needAccessors = false, generateCBuffer = true, constantRegister = (int)ConstantRegister.RayTracing)] + unsafe struct ShaderVariablesRaytracing + { + // Global ray bias used for all trace rays + public float _RaytracingRayBias; + // Maximal ray length for trace ray (in case an other one does not override it) + public float _RaytracingRayMaxLength; + // Number of samples that will be used to evaluate an effect + public int _RaytracingNumSamples; + // Index of the current sample + public int _RaytracingSampleIndex; + // Value used to clamp the intensity of the signal to reduce the signal/noise ratio + public float _RaytracingIntensityClamp; + // Flag that tracks if ray counting is enabled + public int _RayCountEnabled; + // Flag that tracks if a ray traced signal should be pre-exposed + public int _RaytracingPreExposition; + // Near plane distance of the camera used for ray tracing + public float _RaytracingCameraNearPlane; + // Angle of a pixel (used for texture filtering) + public float _RaytracingPixelSpreadAngle; + // Flag that tracks if only diffuse lighting should be computed + public uint _RaytracingDiffuseRay; + // Ray traced reflection Data + public float _RaytracingReflectionMinSmoothness; + public float _RaytracingReflectionSmoothnessFadeStart; + public int _RaytracingIncludeSky; + // Path tracing parameters + public int _RaytracingMinRecursion; + public int _RaytracingMaxRecursion; + // Ray traced indirect diffuse data + public int _RayTracingDiffuseLightingOnly; + } +} diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.cs.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.cs.hlsl new file mode 100644 index 00000000000..0d4fd6a86a1 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.cs.hlsl @@ -0,0 +1,29 @@ +// +// This file was automatically generated. Please don't edit by hand. +// + +#ifndef SHADERVARIABLESRAYTRACING_CS_HLSL +#define SHADERVARIABLESRAYTRACING_CS_HLSL +// Generated from UnityEngine.Rendering.HighDefinition.ShaderVariablesRaytracing +// PackingRules = Exact +GLOBAL_CBUFFER_START(ShaderVariablesRaytracing, b3) + float _RaytracingRayBias; + float _RaytracingRayMaxLength; + int _RaytracingNumSamples; + int _RaytracingSampleIndex; + float _RaytracingIntensityClamp; + int _RayCountEnabled; + int _RaytracingPreExposition; + float _RaytracingCameraNearPlane; + float _RaytracingPixelSpreadAngle; + uint _RaytracingDiffuseRay; + float _RaytracingReflectionMinSmoothness; + float _RaytracingReflectionSmoothnessFadeStart; + int _RaytracingIncludeSky; + int _RaytracingMinRecursion; + int _RaytracingMaxRecursion; + int _RayTracingDiffuseLightingOnly; +CBUFFER_END + + +#endif diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.cs.hlsl.meta b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.cs.hlsl.meta new file mode 100644 index 00000000000..00fcd01f23d --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.cs.hlsl.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 97464d610af37e74bac6dd66d1532218 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.cs.meta b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.cs.meta new file mode 100644 index 00000000000..0ce94c1a611 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2103ac3cc7c4e9b429bc457a4bf0f8db +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.hlsl index 77731365d6f..9ff1710085d 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.hlsl @@ -1,42 +1,10 @@ #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRayTracingManager.cs.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.cs.hlsl" // The target acceleration acceleration structure should only be defined for non compute shaders #ifndef SHADER_STAGE_COMPUTE GLOBAL_RESOURCE(RaytracingAccelerationStructure, _RaytracingAccelerationStructure, RAY_TRACING_ACCELERATION_STRUCTURE_REGISTER); #endif -GLOBAL_CBUFFER_START(UnityRayTracingGlobals, UNITY_RAY_TRACING_GLOBAL_CBUFFER_REGISTER) - // Global ray bias used for all trace rays - float _RaytracingRayBias; - // Maximal ray length for trace ray (in case an other one does not override it) - float _RaytracingRayMaxLength; - // Number of samples that will be used to evaluate an effect - int _RaytracingNumSamples; - // Index of the current sample - int _RaytracingSampleIndex; - // Value used to clamp the intensity of the signal to reduce the signal/noise ratio - float _RaytracingIntensityClamp; - // Flag that tracks if ray counting is enabled - int _RayCountEnabled; - // Flag that tracks if a ray traced signal should be pre-exposed - int _RaytracingPreExposition; - // Near plane distance of the camera used for ray tracing - float _RaytracingCameraNearPlane; - // Angle of a pixel (used for texture filtering) - float _RaytracingPixelSpreadAngle; - // Flag that tracks if only diffuse lighting should be computed - uint _RaytracingDiffuseRay; - // Ray traced reflection Data - float _RaytracingReflectionMaxDistance; - float _RaytracingReflectionMinSmoothness; - float _RaytracingReflectionSmoothnessFadeStart; - int _RaytracingIncludeSky; - // Path tracing parameters - int _RaytracingMinRecursion; - int _RaytracingMaxRecursion; - // Ray traced indirect diffuse data - int _RayTracingDiffuseLightingOnly; -CBUFFER_END - RW_TEXTURE2D_ARRAY(uint, _RayCountTexture); diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracingLightLoop.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracingLightLoop.cs new file mode 100644 index 00000000000..0da49a3a9a0 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracingLightLoop.cs @@ -0,0 +1,13 @@ +namespace UnityEngine.Rendering.HighDefinition +{ + [GenerateHLSL(needAccessors = false, generateCBuffer = true, constantRegister = (int)ConstantRegister.RayTracingLightLoop)] + unsafe struct ShaderVariablesRaytracingLightLoop + { + public Vector3 _MinClusterPos; + public uint _LightPerCellCount; + public Vector3 _MaxClusterPos; + public uint _PunctualLightCountRT; + public uint _AreaLightCountRT; + public uint _EnvLightCountRT; + } +} diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracingLightLoop.cs.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracingLightLoop.cs.hlsl new file mode 100644 index 00000000000..fb1a76af2f1 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracingLightLoop.cs.hlsl @@ -0,0 +1,19 @@ +// +// This file was automatically generated. Please don't edit by hand. +// + +#ifndef SHADERVARIABLESRAYTRACINGLIGHTLOOP_CS_HLSL +#define SHADERVARIABLESRAYTRACINGLIGHTLOOP_CS_HLSL +// Generated from UnityEngine.Rendering.HighDefinition.ShaderVariablesRaytracingLightLoop +// PackingRules = Exact +GLOBAL_CBUFFER_START(ShaderVariablesRaytracingLightLoop, b4) + float3 _MinClusterPos; + uint _LightPerCellCount; + float3 _MaxClusterPos; + uint _PunctualLightCountRT; + uint _AreaLightCountRT; + uint _EnvLightCountRT; +CBUFFER_END + + +#endif diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracingLightLoop.cs.hlsl.meta b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracingLightLoop.cs.hlsl.meta new file mode 100644 index 00000000000..6e113a6d916 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracingLightLoop.cs.hlsl.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 6406914af4a2b9a42ae731cf46f90a89 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracingLightLoop.cs.meta b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracingLightLoop.cs.meta new file mode 100644 index 00000000000..bef77758c46 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracingLightLoop.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9ecef279876c4f94caa6c8bde9d8e297 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracingLightLoop.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracingLightLoop.hlsl index d7ba4435888..07c117c3dc0 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracingLightLoop.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracingLightLoop.hlsl @@ -1,19 +1,10 @@ #ifndef UNITY_SHADER_VARIABLES_RAY_TRACING_LIGHT_LOOP_INCLUDED #define UNITY_SHADER_VARIABLES_RAY_TRACING_LIGHT_LOOP_INCLUDED -#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracingLightLoop.cs.hlsl" -GLOBAL_RESOURCE(StructuredBuffer, _RaytracingLightCluster, RAY_TRACING_LIGHT_CLUSTER_REGISTER); +GLOBAL_RESOURCE(StructuredBuffer, _RaytracingLightCluster, RAY_TRACING_LIGHT_CLUSTER_REGISTER); GLOBAL_RESOURCE(StructuredBuffer, _LightDatasRT, RAY_TRACING_LIGHT_DATA_REGISTER); GLOBAL_RESOURCE(StructuredBuffer, _EnvLightDatasRT, RAY_TRACING_ENV_LIGHT_DATA_REGISTER); -GLOBAL_CBUFFER_START(UnityRayTracingLightLoop, UNITY_RAY_TRACING_LIGHT_LOOP_CBUFFER_REGISTER) - uint _LightPerCellCount; - float3 _MinClusterPos; - float3 _MaxClusterPos; - uint _PunctualLightCountRT; - uint _AreaLightCountRT; - uint _EnvLightCountRT; -CBUFFER_END - -#endif // UNITY_SHADER_VARIABLES_RAY_TRACING_LIGHT_LOOP_INCLUDED \ No newline at end of file +#endif // UNITY_SHADER_VARIABLES_RAY_TRACING_LIGHT_LOOP_INCLUDED 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 e383be28c1b..b17250fb174 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs @@ -6,6 +6,8 @@ enum ConstantRegister Global = 0, XR = 1, PBRSky = 2, + RayTracing = 3, + RayTracingLightLoop = 4, } // We need to keep the number of different constant buffers low. diff --git a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.hlsl b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.hlsl index 00c9dd5a040..6ef4ea2a0f7 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.hlsl @@ -12,11 +12,6 @@ #define GLOBAL_CBUFFER_START(name, reg) CBUFFER_START(name) #endif -// Global Constant Buffers - b registers. Unity supports a maximum of 16 global constant buffers. - // Ray tracing specific constant buffers -#define UNITY_RAY_TRACING_GLOBAL_CBUFFER_REGISTER b3 -#define UNITY_RAY_TRACING_LIGHT_LOOP_CBUFFER_REGISTER b4 - // Global Input Resources - t registers. Unity supports a maximum of 64 global input resources (compute buffers, textures, acceleration structure). #define RAY_TRACING_ACCELERATION_STRUCTURE_REGISTER t0 #define RAY_TRACING_LIGHT_CLUSTER_REGISTER t1