diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/1000_RaytracingQualityKeyword_MaterialQuality_Indirect.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/1000_RaytracingQualityKeyword_MaterialQuality_Indirect.png index a87cea96169..3d4b7d42de0 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/1000_RaytracingQualityKeyword_MaterialQuality_Indirect.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/1000_RaytracingQualityKeyword_MaterialQuality_Indirect.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6d8748b6af687c18fa00fb6524a1a82a7859d49fda4162519c970cb4e050b7f3 -size 432575 +oid sha256:761e6dbe4d93864697cb73984d22a901e0e5d6471322fe8454430b00a77d8d39 +size 450666 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/104_ReflectionsNoisy.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/104_ReflectionsNoisy.png index 762c8311f7a..ea5fddffe99 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/104_ReflectionsNoisy.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/104_ReflectionsNoisy.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7be5a787d8cbc321949eff20b6ec9bb3a5767c8db33e809c2c3b2b713e7a1708 -size 340031 +oid sha256:c7e696963af399af936f126d127fe1bce33e399aae71cc7ec033d958b45ca5ee +size 356758 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/105_ReflectionsAndGlobalIlluminationCollision.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/105_ReflectionsAndGlobalIlluminationCollision.png index e1047d1f74b..a414c966b2f 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/105_ReflectionsAndGlobalIlluminationCollision.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/105_ReflectionsAndGlobalIlluminationCollision.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:51bac42f7daa095863513587b0a3d5ec9a24c51a474ad3466bf03e3889adfdc9 -size 379013 +oid sha256:90ca34c0309aac5ecaa2506ff8afd343965d9302e11884b41a0c159365f7dbb4 +size 386558 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/105_ReflectionsDenoised.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/105_ReflectionsDenoised.png index b89384229a9..7c633d4070d 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/105_ReflectionsDenoised.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/105_ReflectionsDenoised.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:1a44b9302413feea3c35858cf451b677e876975da0baec8d1f2680d58a96ef99 -size 205596 +oid sha256:7a8d534e119f9e1db2a396c554f44f6ef8b70533019bca6bfd179519200d4565 +size 205826 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/105_ReflectionsDenoised2.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/105_ReflectionsDenoised2.png index d776c2b0b9b..6d0b26a1b83 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/105_ReflectionsDenoised2.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/105_ReflectionsDenoised2.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0a4735ce6744354e19f40cb46e15fd28ec769aac7bf3a580a49a9f0b1eeafb87 -size 178762 +oid sha256:75197bae73f1ee283278faedab6fdaa4b97d47d0cc09a83ced35fe6be047e007 +size 178801 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/301_GlobalIlluminationPerfFull.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/301_GlobalIlluminationPerfFull.png index 39ad4ce0c40..aab378f6ab7 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/301_GlobalIlluminationPerfFull.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/301_GlobalIlluminationPerfFull.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:63160d0fc5e425adb8a298dfd92336f92b51dfef63f9a1c05dd0eef956ad3f48 -size 622058 +oid sha256:52a008bfca03536073aabcd4e2305694e49c27263ef568b0059a1eede936aeaf +size 621266 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/301_GlobalIlluminationPerfFullLightLayers.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/301_GlobalIlluminationPerfFullLightLayers.png index 39ad4ce0c40..aab378f6ab7 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/301_GlobalIlluminationPerfFullLightLayers.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/301_GlobalIlluminationPerfFullLightLayers.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:63160d0fc5e425adb8a298dfd92336f92b51dfef63f9a1c05dd0eef956ad3f48 -size 622058 +oid sha256:52a008bfca03536073aabcd4e2305694e49c27263ef568b0059a1eede936aeaf +size 621266 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/302_GlobalIlluminationPerfHalf.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/302_GlobalIlluminationPerfHalf.png index d63cd3700a6..d9e8c6f7abc 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/302_GlobalIlluminationPerfHalf.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/302_GlobalIlluminationPerfHalf.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d3e935806942f1b54b3dfa030253c3c8b439434b594011c31ca6ce23c230ffdc -size 657220 +oid sha256:ac86398161a9b4d42035d466799eaae748d22c8318a3969e6093d3939246ef7f +size 656661 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/303_GlobalIlluminationQuality.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/303_GlobalIlluminationQuality.png index 9829a03623c..447d6ad6a34 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/303_GlobalIlluminationQuality.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/303_GlobalIlluminationQuality.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f7bc00650f032b09b514872e0570b9d6946edf4d41f14bcb84c2f3d1a2ac55f9 -size 693163 +oid sha256:c6749ca479300e16254c14f210b7ba76e5a0edbc29d85a42e294e9bf0f4c8cd7 +size 702655 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/304_GlobalIlluminationDenoised1.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/304_GlobalIlluminationDenoised1.png index ae191206ddc..d5cd64f6a77 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/304_GlobalIlluminationDenoised1.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/304_GlobalIlluminationDenoised1.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:85fed6f3c924666634a011e160a44ff694ce6f61ad351bcb04c3ca8aa7dbca87 -size 599168 +oid sha256:879ffe1743bb871c1daedb938ded7500f38407f21f15a1ea0eaacf9ed18fc959 +size 598892 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/305_GlobalIlluminationDenoisedHalf1.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/305_GlobalIlluminationDenoisedHalf1.png index 3d919bfe544..5a90956e46e 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/305_GlobalIlluminationDenoisedHalf1.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/305_GlobalIlluminationDenoisedHalf1.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:50e7ee059bfd51a9d284ab318cba06f5b2c01479d39ea1342a8dce8ba366384a -size 297860 +oid sha256:28ed15ec1f4318bcff5e0085ef96dc5e34595d8f5c47ee003cd287c82f52f0f6 +size 298098 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/306_GlobalIlluminationDenoised2.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/306_GlobalIlluminationDenoised2.png index d887031e06c..0d5870072dd 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/306_GlobalIlluminationDenoised2.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/306_GlobalIlluminationDenoised2.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f16dae35ccbf6e7a4e2f9856bf741ad59d7b6ee1495b4d8bad37d3c2015213d1 -size 497090 +oid sha256:b4a5b6cbb5ae3c5b29ff677c5dd400e6491bdad7d2812f49ac98a46cdb6d5350 +size 497410 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/307_GlobalIlluminationFog.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/307_GlobalIlluminationFog.png index b427e7509fd..1a9b5e615c3 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/307_GlobalIlluminationFog.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/307_GlobalIlluminationFog.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0c9ec967fdffccb853be2c6bcdb672bcbc4f6166934b4a916d12becbfff5664c -size 462373 +oid sha256:56960999f7916eda04f697df3553179dfbb43944a68f92ab5c48fdc01a12de01 +size 462076 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/7000_QuadChannelTexCoord.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/7000_QuadChannelTexCoord.png index a0b2cb65f00..9b64ac43281 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/7000_QuadChannelTexCoord.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/7000_QuadChannelTexCoord.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9d17dd6f2f3a7ce05914afec2ce442af576c27b62504a6e85423a883674f4bc9 -size 72869 +oid sha256:378d8e1bddf94f0ec9e1064150e2a6b7b61d59fdabf75c9b0fa6d55ceaeb18cd +size 75009 diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 488e34f98ac..5c5b94e900a 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -57,6 +57,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Decreased the minimal Fog Distance value in the Density Volume to 0.05. - Changed the convergence time of ssgi to 16 frames and the preset value - Improved robustness of volumetric sampling in path tracing (case 1295187). +- Changed the clamping approach for RTR and RTGI (in both perf and quality) to improve visual quality. ## [10.3.0] - 2020-12-01 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 70d0866aaf4..091192a6865 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 @@ -84,7 +84,6 @@ DeferredLightingRTParameters PrepareIndirectDiffuseDeferredLightingRTParameters( deferredParameters.raytracingCB._RaytracingIntensityClamp = settings.clampValue; deferredParameters.raytracingCB._RaytracingPreExposition = 1; deferredParameters.raytracingCB._RaytracingIncludeSky = 1; - deferredParameters.raytracingCB._RaytracingPreExposition = 1; deferredParameters.raytracingCB._RaytracingRayMaxLength = settings.rayLength; deferredParameters.raytracingCB._RayTracingDiffuseLightingOnly = 1; diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Deferred/RaytracingDeferred.compute b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Deferred/RaytracingDeferred.compute index b9ebdc3dd89..6e6ed7b63ab 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Deferred/RaytracingDeferred.compute +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Deferred/RaytracingDeferred.compute @@ -62,9 +62,14 @@ void RAYTRACING_DEFERRED(uint3 dispatchThreadId : SV_DispatchThreadID, uint2 gro // If the distance is negative, this means it is a sky pixel or an unlit material if (LOAD_TEXTURE2D_X(_RaytracingDistanceBuffer, currentCoord).x < 0.0) { - float3 newSampleColor = clamp(LOAD_TEXTURE2D_X(_GBufferTexture3, currentCoord).rgb * GetCurrentExposureMultiplier(), 0.0, _RaytracingIntensityClamp) - * (_RaytracingPreExposition ? 1.0 : GetInverseCurrentExposureMultiplier() ); - _RaytracingLitBufferRW[COORD_TEXTURE2D_X(currentCoord)] = float4(newSampleColor, 0.0); + // Convert to HSV space + float3 finalColor = RgbToHsv(LOAD_TEXTURE2D_X(_GBufferTexture3, currentCoord).rgb * GetCurrentExposureMultiplier()); + + // Expose and clamp the final color + finalColor.z = clamp(finalColor.z, 0.0, _RaytracingIntensityClamp); + + // Convert back to HSV space + _RaytracingLitBufferRW[COORD_TEXTURE2D_X(currentCoord)] = float4(HsvToRgb(finalColor) * (_RaytracingPreExposition ? 1.0 : GetInverseCurrentExposureMultiplier()), 0.0); return; } @@ -106,8 +111,23 @@ void RAYTRACING_DEFERRED(uint3 dispatchThreadId : SV_DispatchThreadID, uint2 gro float3 finalColor = (diffuseLighting + specularLighting); // Apply fog attenuation ApplyFogAttenuation(sourcePosInput.positionWS, rayDirection, rayDistance, finalColor, true); - // Expose, clamp and inverse exposure - finalColor = clamp(finalColor * GetCurrentExposureMultiplier(), 0.0, _RaytracingIntensityClamp) * (_RaytracingPreExposition ? 1.0 : GetInverseCurrentExposureMultiplier()); + + // Expose, clamp and inverse exposure. Though depending on the signal nature we go for different clamping strategies + if (_RaytracingPreExposition) + { + // Convert to HSV space + finalColor = RgbToHsv(finalColor * GetCurrentExposureMultiplier()); + + // Expose and clamp the final color + finalColor.z = clamp(finalColor.z, 0.0, _RaytracingIntensityClamp); + + // Convert back to HSV space + finalColor = HsvToRgb(finalColor); + } + else + { + finalColor = clamp(finalColor * GetCurrentExposureMultiplier(), 0.0, _RaytracingIntensityClamp) * GetInverseCurrentExposureMultiplier(); + } _RaytracingLitBufferRW[COORD_TEXTURE2D_X(currentCoord)] = float4(finalColor, 1.0); } diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/IndirectDiffuse/RaytracingIndirectDiffuse.raytrace b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/IndirectDiffuse/RaytracingIndirectDiffuse.raytrace index f2c91a74615..5b3035fae0f 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/IndirectDiffuse/RaytracingIndirectDiffuse.raytrace +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/IndirectDiffuse/RaytracingIndirectDiffuse.raytrace @@ -128,9 +128,14 @@ void RayGenIntegration() // Normalize the value finalColor *= 1.0f / _RaytracingNumSamples; + // Convert to HSV space + finalColor = RgbToHsv(finalColor * GetCurrentExposureMultiplier()); + // Expose and clamp the final color - finalColor = clamp(finalColor * GetCurrentExposureMultiplier(), 0.0, _RaytracingIntensityClamp); + finalColor.z = clamp(finalColor.z, 0.0, _RaytracingIntensityClamp); + // Convert back to HSV space + finalColor = HsvToRgb(finalColor) * GetInverseCurrentExposureMultiplier(); // We store the sampled color and the weight that shall be used for it (1.0f) _IndirectDiffuseTextureRW[COORD_TEXTURE2D_X(currentCoord)] = float4(finalColor, 1.0f); } diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Reflections/RaytracingReflections.raytrace b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Reflections/RaytracingReflections.raytrace index 0e1e2835f1a..069213daa87 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Reflections/RaytracingReflections.raytrace +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Reflections/RaytracingReflections.raytrace @@ -156,16 +156,32 @@ void RayGenIntegration() // Evaluate the ray intersection TraceRay(_RaytracingAccelerationStructure, RAY_FLAG_CULL_BACK_FACING_TRIANGLES, RAYTRACINGRENDERERFLAG_REFLECTION, 0, 1, 0, rayDescriptor, rayIntersection); + // The clamping process is different for the sky and rest + float3 sampleColor = 0.0; + if (rayIntersection.t == _RaytracingRayMaxLength) + { + // Convert to HSV space + sampleColor = RgbToHsv(rayIntersection.color * GetCurrentExposureMultiplier()); + + // Expose and clamp the final color + sampleColor.z = clamp(sampleColor.z, 0.0, _RaytracingIntensityClamp); + + // Convert back to HSV space + sampleColor = HsvToRgb(sampleColor) * GetInverseCurrentExposureMultiplier(); + } + else + { + // Expose and clamp the final color + sampleColor = clamp(rayIntersection.color * GetCurrentExposureMultiplier(), 0.0, _RaytracingIntensityClamp) * GetInverseCurrentExposureMultiplier(); + } + // Contribute to the pixel - finalColor += rayIntersection.color; + finalColor += sampleColor; } // Normalize the value finalColor *= 1.0 / realSampleCount; - // Expose and clamp the final color - finalColor = clamp(finalColor * GetCurrentExposureMultiplier(), 0.0, _RaytracingIntensityClamp) * GetInverseCurrentExposureMultiplier(); - // We also need to compute the fade factor for this sample float weightValue = _RaytracingReflectionSmoothnessFadeStart == _RaytracingReflectionMinSmoothness ? 1.0 : saturate((perceptualSmoothness - _RaytracingReflectionMinSmoothness) / (_RaytracingReflectionSmoothnessFadeStart -_RaytracingReflectionMinSmoothness)); @@ -252,8 +268,24 @@ void RayGenIntegrationTransparent() // Evaluate the ray intersection TraceRay(_RaytracingAccelerationStructure, RAY_FLAG_CULL_BACK_FACING_TRIANGLES, RAYTRACINGRENDERERFLAG_REFLECTION, 0, 1, 0, rayDescriptor, rayIntersection); - // Expose and clamp the final color - float3 finalColor = clamp(rayIntersection.color * GetCurrentExposureMultiplier(), 0.0, _RaytracingIntensityClamp) * GetInverseCurrentExposureMultiplier(); + // The clamping process is different for the sky and rest + float3 finalColor = 0.0; + if (rayIntersection.t == _RaytracingRayMaxLength) + { + // Convert to HSV space + finalColor = RgbToHsv(rayIntersection.color * GetCurrentExposureMultiplier()); + + // Expose and clamp the final color + finalColor.z = clamp(finalColor.z, 0.0, _RaytracingIntensityClamp); + + // Convert back to HSV space + finalColor = HsvToRgb(finalColor) * GetInverseCurrentExposureMultiplier(); + } + else + { + // Expose and clamp the final color + finalColor = clamp(rayIntersection.color * GetCurrentExposureMultiplier(), 0.0, _RaytracingIntensityClamp) * GetInverseCurrentExposureMultiplier(); + } // We store the sampled color and the weight that shall be used for it (1.0) _SsrLightingTextureRW[COORD_TEXTURE2D_X(currentCoord)] = float4(finalColor, 1.0);