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 6d923c7542f..8d030ac66a7 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:8f3a24f6ea0b842b92d60f8861aca86ef97ce40e6e623957d4ba872329aff5c3 -size 711101 +oid sha256:aac01db715099d9297a2dee658254e78fdbbab52ff7db7220cd9be947898a14c +size 599333 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 7ffa578d419..ca5d76123f1 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:2915d603aec4e5f53185af0c2a5d63b35c89350e1475175669d3ac6ca130b2ae -size 722724 +oid sha256:7cc0faaf96d6ea0683e54b89eac60f97ade6e3614d623a9ebda10e6ca23576e6 +size 625581 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 e48a96ed8c5..bd1910ebdb2 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:fa29bd47ad10cf2e79b15d2181d3e5b830265325ded7d3d03d19e1107d06a34b -size 615660 +oid sha256:0b48328480958ea08ffb3a65d9bfd18fc10b624391ad5635981d370c1befd2d5 +size 577614 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 0dc2f5d6dc8..575505962c3 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:12239f3763e07d3fc94a2f0e382807133c9877a66e9ae028240eba8d17544ff3 -size 299717 +oid sha256:bcc0642f1d3192589d6ac4b76aaa0059c0f49ff1339ce973ddf17bc12b3b76b8 +size 286768 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 d5a904e86fd..1a33d2ce59b 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:f7e74af3f66fe6a68aafa294b330ba3ea80d81f7b04c2752237644b2ec909469 -size 455049 +oid sha256:df87d5cd113e5fe9e1e0816af04f30fb50ab72eeb458e08ed81c102c36648c86 +size 440024 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 6a4ce62b873..363e1782022 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:46564a00ec45507d7ebc051eb4a6920389f177c42e5ee14d82ed2e025877b062 -size 450476 +oid sha256:3335b34b77409b0816584855dd877250f12fad0e2876494b1047cd9126fb1a33 +size 411751 diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index edc031712eb..4a9051920f4 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -138,6 +138,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Added an API in HDRP to override the camera within the rendering of a frame (mainly for custom pass). - Added more custom pass API functions, mainly to render objects from another camera. - Added support for transparent Unlit in path tracing. +- Added a minimal lit used for RTGI in peformance mode. ### Fixed - Fix when rescale probe all direction below zero (1219246) @@ -640,6 +641,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed an exception due to the color pyramid not allocated when SSGI is enabled. - Fixed an issue with the first Depth history was incorrectly copied. - Fixed path traced DoF focusing issue +- Fix an issue with the half resolution Mode (performance) +- Fix an issue with the color intensity of emissive for performance rtgi ### Changed - Improve MIP selection for decals on Transparents @@ -776,6 +779,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Increase limit for max numbers of lights in UX - Removed direct use of BSDFData in the path tracing pass, delegated to the material instead. - Pre-warm the RTHandle system to reduce the amount of memory allocations and the total memory needed at all points. +- DXR: Only read the geometric attributes that are required using the share pass info and shader graph defines. +- DXR: Dispatch binned rays in 1D instead of 2D. ## [7.1.1] - 2019-09-05 diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Fabric/FabricRaytracing.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/Fabric/FabricRaytracing.hlsl index 630961565d9..24ed4b641ba 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Fabric/FabricRaytracing.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Fabric/FabricRaytracing.hlsl @@ -39,12 +39,6 @@ void FitToStandardLit( SurfaceData surfaceData outStandardlit.fresnel0 = surfaceData.specularColor; outStandardlit.coatMask = 0.0; outStandardlit.emissiveAndBaked = builtinData.bakeDiffuseLighting * surfaceData.ambientOcclusion + builtinData.emissiveColor; -#ifdef LIGHT_LAYERS - outStandardlit.renderingLayers = builtinData.renderingLayers; -#endif -#ifdef SHADOWS_SHADOWMASK - outStandardlit.shadowMasks = BUILTIN_DATA_SHADOW_MASK; -#endif outStandardlit.isUnlit = 0; } #endif diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Hair/HairRayTracing.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/Hair/HairRayTracing.hlsl index 05ed7fa24b2..a1d27f3acce 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Hair/HairRayTracing.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Hair/HairRayTracing.hlsl @@ -39,12 +39,6 @@ void FitToStandardLit( SurfaceData surfaceData outStandardlit.fresnel0 = DEFAULT_HAIR_SPECULAR_VALUE; outStandardlit.coatMask = 0.0; outStandardlit.emissiveAndBaked = builtinData.bakeDiffuseLighting * surfaceData.ambientOcclusion + builtinData.emissiveColor; -#ifdef LIGHT_LAYERS - outStandardlit.renderingLayers = builtinData.renderingLayers; -#endif -#ifdef SHADOWS_SHADOWMASK - outStandardlit.shadowMasks = BUILTIN_DATA_SHADOW_MASK; -#endif outStandardlit.isUnlit = 0; } #endif diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader index e98d6d808b2..5772cba5b5a 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader @@ -909,6 +909,7 @@ Shader "HDRP/LayeredLit" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracingLightLoop.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitSharePass.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingIntersection.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl" @@ -949,6 +950,7 @@ Shader "HDRP/LayeredLit" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracingLightLoop.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitSharePass.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingIntersection.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl" @@ -986,6 +988,7 @@ Shader "HDRP/LayeredLit" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracingLightLoop.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitSharePass.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Deferred/RaytracingIntersectonGBuffer.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" @@ -1014,6 +1017,7 @@ Shader "HDRP/LayeredLit" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitSharePass.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingIntersection.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" @@ -1044,6 +1048,7 @@ Shader "HDRP/LayeredLit" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitSharePass.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/SubSurface/RaytracingIntersectionSubSurface.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" @@ -1083,6 +1088,7 @@ Shader "HDRP/LayeredLit" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracingLightLoop.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitSharePass.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingIntersection.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl" diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader index 4b1422c2cd5..c3e36141c79 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader @@ -949,6 +949,7 @@ Shader "HDRP/Lit" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracingLightLoop.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitSharePass.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingIntersection.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl" @@ -989,6 +990,7 @@ Shader "HDRP/Lit" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracingLightLoop.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitSharePass.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingIntersection.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl" @@ -1016,6 +1018,7 @@ Shader "HDRP/Lit" #pragma multi_compile _ DEBUG_DISPLAY #pragma multi_compile _ LIGHTMAP_ON #pragma multi_compile _ DIRLIGHTMAP_COMBINED + #pragma multi_compile _ MINIMAL_GBUFFER #define SHADERPASS SHADERPASS_RAYTRACING_GBUFFER @@ -1026,6 +1029,7 @@ Shader "HDRP/Lit" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracingLightLoop.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitSharePass.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Deferred/RaytracingIntersectonGBuffer.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" @@ -1055,6 +1059,7 @@ Shader "HDRP/Lit" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitSharePass.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingIntersection.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" @@ -1086,6 +1091,7 @@ Shader "HDRP/Lit" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitSharePass.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/SubSurface/RaytracingIntersectionSubSurface.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" @@ -1121,6 +1127,7 @@ Shader "HDRP/Lit" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracingLightLoop.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitSharePass.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingIntersection.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl" diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitRaytracing.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitRaytracing.hlsl index bfca68a34d1..aba0471ebd6 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitRaytracing.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitRaytracing.hlsl @@ -63,12 +63,6 @@ void FitToStandardLit( SurfaceData surfaceData outStandardlit.perceptualRoughness = PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness); outStandardlit.coatMask = HasFlag(surfaceData.materialFeatures, MATERIALFEATUREFLAGS_LIT_CLEAR_COAT) ? surfaceData.coatMask : 0.0; outStandardlit.emissiveAndBaked = builtinData.bakeDiffuseLighting * surfaceData.ambientOcclusion + builtinData.emissiveColor; -#ifdef LIGHT_LAYERS - outStandardlit.renderingLayers = builtinData.renderingLayers; -#endif -#ifdef SHADOWS_SHADOWMASK - outStandardlit.shadowMasks = BUILTIN_DATA_SHADOW_MASK; -#endif outStandardlit.isUnlit = 0; } #endif diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/StackLit/StackLitRayTracing.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/StackLit/StackLitRayTracing.hlsl index 7b6533b507e..4dfb050514d 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/StackLit/StackLitRayTracing.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/StackLit/StackLitRayTracing.hlsl @@ -63,12 +63,6 @@ void FitToStandardLit( SurfaceData surfaceData outStandardlit.fresnel0 = HasFlag(surfaceData.materialFeatures, MATERIALFEATUREFLAGS_STACK_LIT_SPECULAR_COLOR) ? surfaceData.specularColor : ComputeFresnel0(surfaceData.baseColor, surfaceData.metallic, IorToFresnel0(surfaceData.dielectricIor)); outStandardlit.coatMask = surfaceData.coatMask; outStandardlit.emissiveAndBaked = builtinData.bakeDiffuseLighting * surfaceData.ambientOcclusion + builtinData.emissiveColor; -#ifdef LIGHT_LAYERS - outStandardlit.renderingLayers = builtinData.renderingLayers; -#endif -#ifdef SHADOWS_SHADOWMASK - outStandardlit.shadowMasks = BUILTIN_DATA_SHADOW_MASK; -#endif outStandardlit.isUnlit = 0; } #endif diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/StandardLit/StandardLit.cs b/com.unity.render-pipelines.high-definition/Runtime/Material/StandardLit/StandardLit.cs deleted file mode 100644 index 2d8add1939a..00000000000 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/StandardLit/StandardLit.cs +++ /dev/null @@ -1,36 +0,0 @@ -namespace UnityEngine.Rendering.HighDefinition -{ - partial class StandardLit - { - //----------------------------------------------------------------------------- - // BSDFData - //----------------------------------------------------------------------------- - [GenerateHLSL] - public struct StandardBSDFData - { - // GBuffer0 - public Vector3 baseColor; - public float specularOcclusion; - - // GBuffer1 - public Vector3 normalWS; - public float perceptualRoughness; - - // Gbuffer2 - public Vector3 fresnel0; - public float coatMask; - - // Gbuffer3 - public Vector3 emissiveAndBaked; - - // Gbuffer4 - public uint renderingLayers; - - // Gbuffer5 - public Vector4 shadowMasks; - - // Lighting flag - public uint isUnlit; - } - } -} diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/StandardLit/StandardLit.cs.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/StandardLit/StandardLit.cs.hlsl deleted file mode 100644 index 2265485f701..00000000000 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/StandardLit/StandardLit.cs.hlsl +++ /dev/null @@ -1,67 +0,0 @@ -// -// This file was automatically generated. Please don't edit by hand. -// - -#ifndef STANDARDLIT_CS_HLSL -#define STANDARDLIT_CS_HLSL -// Generated from UnityEngine.Rendering.HighDefinition.StandardLit+StandardBSDFData -// PackingRules = Exact -struct StandardBSDFData -{ - float3 baseColor; - float specularOcclusion; - float3 normalWS; - float perceptualRoughness; - float3 fresnel0; - float coatMask; - float3 emissiveAndBaked; - uint renderingLayers; - float4 shadowMasks; - uint isUnlit; -}; - -// -// Accessors for UnityEngine.Rendering.HighDefinition.StandardLit+StandardBSDFData -// -float3 GetBaseColor(StandardBSDFData value) -{ - return value.baseColor; -} -float GetSpecularOcclusion(StandardBSDFData value) -{ - return value.specularOcclusion; -} -float3 GetNormalWS(StandardBSDFData value) -{ - return value.normalWS; -} -float GetPerceptualRoughness(StandardBSDFData value) -{ - return value.perceptualRoughness; -} -float3 GetFresnel0(StandardBSDFData value) -{ - return value.fresnel0; -} -float GetCoatMask(StandardBSDFData value) -{ - return value.coatMask; -} -float3 GetEmissiveAndBaked(StandardBSDFData value) -{ - return value.emissiveAndBaked; -} -uint GetRenderingLayers(StandardBSDFData value) -{ - return value.renderingLayers; -} -float4 GetShadowMasks(StandardBSDFData value) -{ - return value.shadowMasks; -} -uint GetIsUnlit(StandardBSDFData value) -{ - return value.isUnlit; -} - -#endif diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/StandardLit/StandardLit.cs.hlsl.meta b/com.unity.render-pipelines.high-definition/Runtime/Material/StandardLit/StandardLit.cs.hlsl.meta deleted file mode 100644 index 9bc2e74a182..00000000000 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/StandardLit/StandardLit.cs.hlsl.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: 3f2b190f8114f234f91613fd3a9cb00b -ShaderImporter: - externalObjects: {} - defaultTextures: [] - nonModifiableTextures: [] - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/StandardLit/StandardLit.cs.meta b/com.unity.render-pipelines.high-definition/Runtime/Material/StandardLit/StandardLit.cs.meta deleted file mode 100644 index 1bf82daea3b..00000000000 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/StandardLit/StandardLit.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: c16b34e935aae02438c6003d04c360b5 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/StandardLit/StandardLit.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/StandardLit/StandardLit.hlsl index 93a6762cffd..250c17025eb 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/StandardLit/StandardLit.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/StandardLit/StandardLit.hlsl @@ -1,16 +1,12 @@ -#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/StandardLit/StandardLit.cs.hlsl" +#ifndef STANDARD_LIT_HLSL +#define STANDARD_LIT_HLSL +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RayTracingCommon.hlsl" void EncodeIntoStandardGBuffer( StandardBSDFData standardBSDFData , out GBufferType0 outGBuffer0 , out GBufferType1 outGBuffer1 , out GBufferType2 outGBuffer2 , out GBufferType3 outGBuffer3 -#if GBUFFERMATERIAL_COUNT > 4 - , out GBufferType4 outGBuffer4 -#endif -#if GBUFFERMATERIAL_COUNT > 5 - , out GBufferType5 outGBuffer5 -#endif ) { // GBuffer0 @@ -29,12 +25,5 @@ void EncodeIntoStandardGBuffer( StandardBSDFData standardBSDFData // GBuffer3 outGBuffer3 = float4(standardBSDFData.emissiveAndBaked, 0.0); outGBuffer3 *= GetCurrentExposureMultiplier(); - -#ifdef LIGHT_LAYERS - OUT_GBUFFER_LIGHT_LAYERS = float4(0.0, 0.0, 0.0, standardBSDFData.renderingLayers / 255.0); -#endif - -#ifdef SHADOWS_SHADOWMASK - OUT_GBUFFER_SHADOWMASK = standardBSDFData.shadowMask; -#endif } +#endif // STANDARD_LIT_HLSL \ No newline at end of file diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.shader index 2e282274290..8777c765c85 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.shader @@ -458,6 +458,7 @@ Shader "HDRP/Unlit" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/ShaderPass/UnlitSharePass.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingIntersection.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.hlsl" @@ -485,6 +486,7 @@ Shader "HDRP/Unlit" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/ShaderPass/UnlitSharePass.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingIntersection.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.hlsl" @@ -516,6 +518,7 @@ Shader "HDRP/Unlit" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/ShaderPass/UnlitSharePass.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Deferred/RaytracingIntersectonGBuffer.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/NormalBuffer.hlsl" @@ -548,6 +551,7 @@ Shader "HDRP/Unlit" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/ShaderPass/UnlitSharePass.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingIntersection.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.hlsl" @@ -576,6 +580,7 @@ Shader "HDRP/Unlit" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/ShaderPass/UnlitSharePass.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingIntersection.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.hlsl" 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 6db4c395dec..40fd8925915 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs @@ -579,7 +579,8 @@ static class HDShaderIDs public static readonly int _RayBinResult = Shader.PropertyToID("_RayBinResult"); public static readonly int _RayBinSizeResult = Shader.PropertyToID("_RayBinSizeResult"); public static readonly int _RayBinTileCountX = Shader.PropertyToID("_RayBinTileCountX"); - + public static readonly int _BufferSizeX = Shader.PropertyToID("_BufferSizeX"); + // Sub Surface public static readonly int _ThroughputTextureRW = Shader.PropertyToID("_ThroughputTextureRW"); public static readonly int _NormalTextureRW = Shader.PropertyToID("_NormalTextureRW"); 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 1172f0a4958..f61a1627e1a 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 @@ -225,18 +225,20 @@ static void RenderRaytracingDeferredLighting(CommandBuffer cmd, in DeferredLight // Only compute diffuse lighting if required cmd.SetGlobalInt(HDShaderIDs._RayTracingDiffuseLightingOnly, parameters.diffuseLightingOnly ? 1 : 0); - CoreUtils.SetKeyword(cmd, "MULTI_BOUNCE_INDIRECT", false); + CoreUtils.SetKeyword(cmd, "MINIMAL_GBUFFER", parameters.diffuseLightingOnly); if (parameters.rayBinning) { // Evaluate the dispatch parameters int numTilesRayBinX = (texWidth + (binningTileSize - 1)) / binningTileSize; int numTilesRayBinY = (texHeight + (binningTileSize - 1)) / binningTileSize; - int bufferSizeX = numTilesRayBinX * binningTileSize; int bufferSizeY = numTilesRayBinY * binningTileSize; + cmd.SetRayTracingIntParam(parameters.gBufferRaytracingRT, HDShaderIDs._BufferSizeX, bufferSizeX); - cmd.DispatchRays(parameters.gBufferRaytracingRT, m_RayGenGBufferBinned, (uint)bufferSizeX, (uint)bufferSizeY, 1); + // A really nice tip is to dispatch the rays as a 1D array instead of 2D, the performance difference has been measured. + uint dispatchSize = (uint)(bufferSizeX * bufferSizeY); + cmd.DispatchRays(parameters.gBufferRaytracingRT, m_RayGenGBufferBinned, dispatchSize, 1, 1); } else { @@ -244,6 +246,8 @@ static void RenderRaytracingDeferredLighting(CommandBuffer cmd, in DeferredLight cmd.DispatchRays(parameters.gBufferRaytracingRT, m_RayGenGBuffer, widthResolution, heightResolution, (uint)parameters.viewCount); } + CoreUtils.SetKeyword(cmd, "MINIMAL_GBUFFER", false); + // Now let's do the deferred shading pass on the samples int currentKernel = parameters.deferredRaytracingCS.FindKernel(parameters.halfResolution ? "RaytracingDeferredHalf" : "RaytracingDeferred"); 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 730c9c4ff81..3d23a25dba5 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 @@ -115,7 +115,7 @@ DeferredLightingRTParameters PrepareIndirectDiffuseDeferredLightingRTParameters( deferredParameters.layerMask.value = (int)RayTracingRendererFlag.GlobalIllumination; deferredParameters.diffuseLightingOnly = true; - deferredParameters.halfResolution = false; + deferredParameters.halfResolution = !settings.fullResolution.value; deferredParameters.rayCountType = (int)RayCountValues.DiffuseGI_Deferred; // Camera data @@ -184,8 +184,8 @@ void RenderIndirectDiffusePerformance(HDCamera hdCamera, CommandBuffer cmd, Scri cmd.SetComputeTextureParam(indirectDiffuseCS, currentKernel, HDShaderIDs._RaytracingDirectionBuffer, directionBuffer); // Texture dimensions - int texWidth = hdCamera.actualWidth; - int texHeight = hdCamera.actualHeight; + int texWidth = settings.fullResolution.value ? hdCamera.actualWidth : hdCamera.actualWidth / 2; + int texHeight = settings.fullResolution.value ? hdCamera.actualHeight : hdCamera.actualHeight / 2; // Evaluate the dispatch parameters int areaTileSize = 8; diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Deferred/RaytracingGBuffer.raytrace b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Deferred/RaytracingGBuffer.raytrace index c787ce98bcb..8cb14537cb3 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Deferred/RaytracingGBuffer.raytrace +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Deferred/RaytracingGBuffer.raytrace @@ -48,8 +48,6 @@ RW_TEXTURE2D_X(float4, _GBufferTexture0RW); RW_TEXTURE2D_X(float4, _GBufferTexture1RW); RW_TEXTURE2D_X(float4, _GBufferTexture2RW); RW_TEXTURE2D_X(float4, _GBufferTexture3RW); // Bake lighting and/or emissive -RW_TEXTURE2D_X(float4, _GBufferTexture4RW); // Light layer or shadow mask -RW_TEXTURE2D_X(float4, _GBufferTexture5RW); // shadow mask int _RaytracingHalfResolution; uint _RayTracingLayerMask; @@ -60,8 +58,8 @@ void MissShaderGBuffer(inout RayIntersectionGBuffer rayIntersection : SV_RayPayl { if (_RaytracingIncludeSky != 0) { - rayIntersection.gBufferData.gbuffer3 = SAMPLE_TEXTURECUBE_ARRAY_LOD(_SkyTexture, s_trilinear_clamp_sampler, rayIntersection.incidentDirection, 0.0f, 0); - ApplyFogAttenuation(WorldRayOrigin(), WorldRayDirection(), rayIntersection.gBufferData.gbuffer3.xyz); + rayIntersection.gbuffer3 = SAMPLE_TEXTURECUBE_ARRAY_LOD(_SkyTexture, s_trilinear_clamp_sampler, WorldRayDirection(), 0.0f, 0); + ApplyFogAttenuation(WorldRayOrigin(), WorldRayDirection(), rayIntersection.gbuffer3.xyz); } rayIntersection.t = -1.0; } @@ -126,35 +124,27 @@ void RayGenGBuffer() // Create and init the RayIntersection structure for this RayIntersectionGBuffer rayIntersection; - rayIntersection.origin = rayOrigin; rayIntersection.t = -1.0; - rayIntersection.incidentDirection = rayDescriptor.Direction; - rayIntersection.gBufferData.gbuffer0 = float4(0.0, 0.0, 0.0, 0.0); - rayIntersection.gBufferData.gbuffer1 = float4(0.0, 0.0, 0.0, 0.0); - rayIntersection.gBufferData.gbuffer2 = float4(0.0, 0.0, 0.0, 0.0); - rayIntersection.gBufferData.gbuffer3 = float4(0.0, 0.0, 0.0, 0.0); - - // In order to achieve filtering for the textures, we need to compute the spread angle of the pixel - float roughness = PerceptualRoughnessToRoughness(normalData.perceptualRoughness); - rayIntersection.cone.spreadAngle = _RaytracingPixelSpreadAngle + roughnessToSpreadAngle(_RaytracingDiffuseRay ? 1.0 : roughness); - float distanceToCamera = length(posInput.positionWS); - rayIntersection.cone.width = distanceToCamera * _RaytracingPixelSpreadAngle; + rayIntersection.gbuffer0 = float4(0.0, 0.0, 0.0, 0.0); + rayIntersection.gbuffer1 = float4(0.0, 0.0, 0.0, 0.0); + rayIntersection.gbuffer2 = float4(0.0, 0.0, 0.0, 0.0); + rayIntersection.gbuffer3 = float4(0.0, 0.0, 0.0, 0.0); // Evaluate the ray visibility term and PDF TraceRay(_RaytracingAccelerationStructure, RAY_FLAG_CULL_BACK_FACING_TRIANGLES, _RayTracingLayerMask, 0, 1, 0, rayDescriptor, rayIntersection); // Output the gbuffer - _GBufferTexture0RW[COORD_TEXTURE2D_X(currentPixelCoord)] = float4(LinearToSRGB(rayIntersection.gBufferData.gbuffer0.xyz), rayIntersection.gBufferData.gbuffer0.w); - _GBufferTexture1RW[COORD_TEXTURE2D_X(currentPixelCoord)] = float4(rayIntersection.gBufferData.gbuffer1); - _GBufferTexture2RW[COORD_TEXTURE2D_X(currentPixelCoord)] = float4(rayIntersection.gBufferData.gbuffer2); - _GBufferTexture3RW[COORD_TEXTURE2D_X(currentPixelCoord)] = float4(rayIntersection.gBufferData.gbuffer3); + _GBufferTexture0RW[COORD_TEXTURE2D_X(currentPixelCoord)] = float4(LinearToSRGB(rayIntersection.gbuffer0.xyz), rayIntersection.gbuffer0.w); + _GBufferTexture1RW[COORD_TEXTURE2D_X(currentPixelCoord)] = float4(rayIntersection.gbuffer1); + _GBufferTexture2RW[COORD_TEXTURE2D_X(currentPixelCoord)] = float4(rayIntersection.gbuffer2); + _GBufferTexture3RW[COORD_TEXTURE2D_X(currentPixelCoord)] = float4(rayIntersection.gbuffer3); _RaytracingDistanceBuffer[COORD_TEXTURE2D_X(currentPixelCoord)] = rayIntersection.t; } StructuredBuffer _RayBinResult; StructuredBuffer _RayBinSizeResult; uint _RayBinTileCountX; - +uint _BufferSizeX; #define RAY_BINNING_TILE_SIZE 16 [shader("raygeneration")] @@ -162,10 +152,9 @@ void RayGenGBufferBinned() { // Grab the dimensions of the current raytrace shader uint3 LaunchIndex = DispatchRaysIndex(); - uint3 LaunchDim = DispatchRaysDimensions(); // Pixel coordinate of the current pixel - uint2 currentBinIndex = uint2(LaunchIndex.x, LaunchIndex.y); + uint2 currentBinIndex = uint2(LaunchIndex.x % _BufferSizeX, LaunchIndex.x / _BufferSizeX); // Compute the various local/tile coordinates uint2 localTileCoordinate = uint2(currentBinIndex.x % RAY_BINNING_TILE_SIZE, currentBinIndex.y % RAY_BINNING_TILE_SIZE); @@ -232,33 +221,19 @@ void RayGenGBufferBinned() // Create and init the RayIntersection structure for this RayIntersectionGBuffer rayIntersection; - rayIntersection.origin = rayOrigin; rayIntersection.t = -1.0; - rayIntersection.incidentDirection = rayDescriptor.Direction; - rayIntersection.gBufferData.gbuffer0 = float4(0.0, 0.0, 0.0, 0.0); - rayIntersection.gBufferData.gbuffer1 = float4(0.0, 0.0, 0.0, 0.0); - rayIntersection.gBufferData.gbuffer2 = float4(0.0, 0.0, 0.0, 0.0); - rayIntersection.gBufferData.gbuffer3 = float4(0.0, 0.0, 0.0, 0.0); - - // In order to achieve filtering for the textures, we need to compute the spread angle of the pixel - float roughness = PerceptualRoughnessToRoughness(normalData.perceptualRoughness); - rayIntersection.cone.spreadAngle = _RaytracingPixelSpreadAngle + roughnessToSpreadAngle(_RaytracingDiffuseRay ? 1.0 : roughness); - rayIntersection.cone.width = distanceToCamera * _RaytracingPixelSpreadAngle; + rayIntersection.gbuffer0 = float4(0.0, 0.0, 0.0, 0.0); + rayIntersection.gbuffer1 = float4(0.0, 0.0, 0.0, 0.0); + rayIntersection.gbuffer2 = float4(0.0, 0.0, 0.0, 0.0); + rayIntersection.gbuffer3 = float4(0.0, 0.0, 0.0, 0.0); // Evaluate the ray visibility term and PDF TraceRay(_RaytracingAccelerationStructure, RAY_FLAG_CULL_BACK_FACING_TRIANGLES, _RayTracingLayerMask, 0, 1, 0, rayDescriptor, rayIntersection); // Output the gbuffer - _GBufferTexture0RW[COORD_TEXTURE2D_X(currentPixelCoord)] = float4(LinearToSRGB(rayIntersection.gBufferData.gbuffer0.xyz), rayIntersection.gBufferData.gbuffer0.w); - _GBufferTexture1RW[COORD_TEXTURE2D_X(currentPixelCoord)] = float4(rayIntersection.gBufferData.gbuffer1); - _GBufferTexture2RW[COORD_TEXTURE2D_X(currentPixelCoord)] = float4(rayIntersection.gBufferData.gbuffer2); - _GBufferTexture3RW[COORD_TEXTURE2D_X(currentPixelCoord)] = float4(rayIntersection.gBufferData.gbuffer3); + _GBufferTexture0RW[COORD_TEXTURE2D_X(currentPixelCoord)] = float4(LinearToSRGB(rayIntersection.gbuffer0.xyz), rayIntersection.gbuffer0.w); + _GBufferTexture1RW[COORD_TEXTURE2D_X(currentPixelCoord)] = float4(rayIntersection.gbuffer1); + _GBufferTexture2RW[COORD_TEXTURE2D_X(currentPixelCoord)] = float4(rayIntersection.gbuffer2); + _GBufferTexture3RW[COORD_TEXTURE2D_X(currentPixelCoord)] = float4(rayIntersection.gbuffer3); _RaytracingDistanceBuffer[COORD_TEXTURE2D_X(currentPixelCoord)] = rayIntersection.t; -} - -[shader("closesthit")] -void ClosestHitMain(inout RayIntersectionGBuffer rayIntersection : SV_RayPayload, AttributeData attributeData : SV_IntersectionAttributes) -{ - rayIntersection.gBufferData.gbuffer3 = float4(0.0, 0.0, 0.0, 1.0); - rayIntersection.t = -1.0; -} +} \ No newline at end of file diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Deferred/RaytracingIntersectonGBuffer.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Deferred/RaytracingIntersectonGBuffer.hlsl index 00c378c99c9..325a2fea02a 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Deferred/RaytracingIntersectonGBuffer.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Deferred/RaytracingIntersectonGBuffer.hlsl @@ -2,27 +2,12 @@ #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialGBufferMacros.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/RaytracingMaterialGBufferMacros.hlsl" -struct RaytracingGBuffer +// Structure that defines the current state of the intersection +struct RayIntersectionGBuffer { + float t; GBufferType0 gbuffer0; GBufferType1 gbuffer1; GBufferType2 gbuffer2; GBufferType3 gbuffer3; - GBufferType4 gbuffer4; - GBufferType5 gbuffer5; -}; - -// Structure that defines the current state of the intersection -struct RayIntersectionGBuffer -{ - // Origin of the current ray - float3 origin; - // Direction of the current ray - float3 incidentDirection; - // Distance of the intersection - float t; - // Cone representation of the ray - RayCone cone; - // Gbuffer packed - RaytracingGBuffer gBufferData; -}; +}; \ No newline at end of file diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Denoising/TemporalFilter.compute b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Denoising/TemporalFilter.compute index 95ac80f6e83..1ad471d2d4f 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Denoising/TemporalFilter.compute +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Denoising/TemporalFilter.compute @@ -227,7 +227,7 @@ void TEMPORAL_ACCUMULATION(uint3 dispatchThreadId : SV_DispatchThreadID, uint2 g else { // Otherwise we compute the accumulation factor - accumulationFactor = sampleCount > 8.0 ? 1.0 : (sampleCount / (sampleCount + 1.0)); + accumulationFactor = sampleCount >= 8.0 ? 0.93 : (sampleCount / (sampleCount + 1.0)); // Update the sample count sampleCount = min(sampleCount + 1.0, 8.0); } diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RayTracingCommon.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RayTracingCommon.hlsl index cbcdc238ad5..51b7f2edb5d 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RayTracingCommon.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RayTracingCommon.hlsl @@ -1,3 +1,5 @@ +#ifndef RAY_TRACING_COMMON_HLSL +#define RAY_TRACING_COMMON_HLSL // This array converts an index to the local coordinate shift of the half resolution texture static const uint2 HalfResIndexToCoordinateShift[4] = { uint2(0,0), uint2(1, 0), uint2(0, 1), uint2(1, 1) }; @@ -8,7 +10,7 @@ float roughnessToSpreadAngle(float roughness) return roughness * PI/8; } -#define USE_RAY_CONE_LOD +// #define USE_RAY_CONE_LOD float computeBaseTextureLOD(float3 viewWS, float3 normalWS, @@ -31,3 +33,20 @@ float computeTargetTextureLOD(Texture2D targetTexture, float baseLambda) return max(0.0, baseLambda + 0.5 * log2(texWidth * texHeight)); } + +// The standard lit data used for paking intersection data for deferred lighting (for ray tracing) +struct StandardBSDFData +{ + float3 baseColor; + float specularOcclusion; + float3 normalWS; + float perceptualRoughness; + float3 fresnel0; + float coatMask; + float3 emissiveAndBaked; + uint renderingLayers; + float4 shadowMasks; + uint isUnlit; +}; + +#endif // RAY_TRACING_COMMON_HLSL \ No newline at end of file diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingFragInputs.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingFragInputs.hlsl index f91e69761a7..189b8fb48a4 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingFragInputs.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingFragInputs.hlsl @@ -2,7 +2,7 @@ void BuildFragInputsFromIntersection(IntersectionVertex currentVertex, float3 incidentDirection, out FragInputs outFragInputs) { outFragInputs.positionSS = float4(0.0, 0.0, 0.0, 0.0); - outFragInputs.positionRWS = mul(ObjectToWorld3x4(), float4(currentVertex.positionOS, 1.0)).xyz - _WorldSpaceCameraPos; + outFragInputs.positionRWS = WorldRayOrigin() + WorldRayDirection() * RayTCurrent() - _WorldSpaceCameraPos; outFragInputs.texCoord0 = float4(currentVertex.texCoord0, 0.0, 0.0); outFragInputs.texCoord1 = float4(currentVertex.texCoord1, 0.0, 0.0); outFragInputs.texCoord2 = float4(currentVertex.texCoord2, 0.0, 0.0); @@ -14,4 +14,4 @@ void BuildFragInputsFromIntersection(IntersectionVertex currentVertex, float3 in outFragInputs.tangentToWorld = BuildTangentToWorld(tangentWS, normalWS); outFragInputs.isFrontFace = dot(incidentDirection, outFragInputs.tangentToWorld[2]) < 0.0f; -} +} \ No newline at end of file diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingIntersection.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingIntersection.hlsl index c11eb338359..fac60b05de3 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingIntersection.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingIntersection.hlsl @@ -48,8 +48,6 @@ struct AttributeData // Structure to fill for intersections struct IntersectionVertex { - // Object space position of the vertex - float3 positionOS; // Object space normal of the vertex float3 normalOS; // Object space tangent of the vertex @@ -59,27 +57,58 @@ struct IntersectionVertex float2 texCoord1; float2 texCoord2; float2 texCoord3; - // Vertex color float4 color; + +#ifdef USE_RAY_CONE_LOD // Value used for LOD sampling float triangleArea; float texCoord0Area; float texCoord1Area; float texCoord2Area; float texCoord3Area; +#endif }; // Fetch the intersetion vertex data for the target vertex void FetchIntersectionVertex(uint vertexIndex, out IntersectionVertex outVertex) { - outVertex.positionOS = UnityRayTracingFetchVertexAttribute3(vertexIndex, kVertexAttributePosition); outVertex.normalOS = UnityRayTracingFetchVertexAttribute3(vertexIndex, kVertexAttributeNormal); + + #ifdef ATTRIBUTES_NEED_TANGENT outVertex.tangentOS = UnityRayTracingFetchVertexAttribute4(vertexIndex, kVertexAttributeTangent); + #else + outVertex.tangentOS = 0.0; + #endif + + #ifdef ATTRIBUTES_NEED_TEXCOORD0 outVertex.texCoord0 = UnityRayTracingFetchVertexAttribute2(vertexIndex, kVertexAttributeTexCoord0); + #else + outVertex.texCoord0 = 0.0; + #endif + + #ifdef ATTRIBUTES_NEED_TEXCOORD1 outVertex.texCoord1 = UnityRayTracingFetchVertexAttribute2(vertexIndex, kVertexAttributeTexCoord1); + #else + outVertex.texCoord1 = 0.0; + #endif + + #ifdef ATTRIBUTES_NEED_TEXCOORD2 outVertex.texCoord2 = UnityRayTracingFetchVertexAttribute2(vertexIndex, kVertexAttributeTexCoord2); + #else + outVertex.texCoord2 = 0.0; + #endif + + #ifdef ATTRIBUTES_NEED_TEXCOORD3 outVertex.texCoord3 = UnityRayTracingFetchVertexAttribute2(vertexIndex, kVertexAttributeTexCoord3); + #else + outVertex.texCoord3 = 0.0; + #endif + + #ifdef ATTRIBUTES_NEED_COLOR outVertex.color = UnityRayTracingFetchVertexAttribute4(vertexIndex, kVertexAttributeColor); + #else + outVertex.color = 0.0; + #endif } void GetCurrentIntersectionVertex(AttributeData attributeData, out IntersectionVertex outVertex) @@ -97,21 +126,52 @@ void GetCurrentIntersectionVertex(AttributeData attributeData, out IntersectionV float3 barycentricCoordinates = float3(1.0 - attributeData.barycentrics.x - attributeData.barycentrics.y, attributeData.barycentrics.x, attributeData.barycentrics.y); // Interpolate all the data - outVertex.positionOS = INTERPOLATE_RAYTRACING_ATTRIBUTE(v0.positionOS, v1.positionOS, v2.positionOS, barycentricCoordinates); outVertex.normalOS = INTERPOLATE_RAYTRACING_ATTRIBUTE(v0.normalOS, v1.normalOS, v2.normalOS, barycentricCoordinates); + + #ifdef ATTRIBUTES_NEED_TANGENT outVertex.tangentOS = INTERPOLATE_RAYTRACING_ATTRIBUTE(v0.tangentOS, v1.tangentOS, v2.tangentOS, barycentricCoordinates); + #else + outVertex.tangentOS = 0.0; + #endif + + #ifdef ATTRIBUTES_NEED_TEXCOORD0 outVertex.texCoord0 = INTERPOLATE_RAYTRACING_ATTRIBUTE(v0.texCoord0, v1.texCoord0, v2.texCoord0, barycentricCoordinates); + #else + outVertex.texCoord0 = 0.0; + #endif + + #ifdef ATTRIBUTES_NEED_TEXCOORD1 outVertex.texCoord1 = INTERPOLATE_RAYTRACING_ATTRIBUTE(v0.texCoord1, v1.texCoord1, v2.texCoord1, barycentricCoordinates); + #else + outVertex.texCoord1 = 0.0; + #endif + + #ifdef ATTRIBUTES_NEED_TEXCOORD2 outVertex.texCoord2 = INTERPOLATE_RAYTRACING_ATTRIBUTE(v0.texCoord2, v1.texCoord2, v2.texCoord2, barycentricCoordinates); + #else + outVertex.texCoord2 = 0.0; + #endif + + #ifdef ATTRIBUTES_NEED_TEXCOORD3 outVertex.texCoord3 = INTERPOLATE_RAYTRACING_ATTRIBUTE(v0.texCoord3, v1.texCoord3, v2.texCoord3, barycentricCoordinates); + #else + outVertex.texCoord3 = 0.0; + #endif + + #ifdef ATTRIBUTES_NEED_COLOR outVertex.color = INTERPOLATE_RAYTRACING_ATTRIBUTE(v0.color, v1.color, v2.color, barycentricCoordinates); + #else + outVertex.color = 0.0; + #endif +#ifdef USE_RAY_CONE_LOD // Compute the lambda value (area computed in object space) outVertex.triangleArea = length(cross(v1.positionOS - v0.positionOS, v2.positionOS - v0.positionOS)); outVertex.texCoord0Area = abs((v1.texCoord0.x - v0.texCoord0.x) * (v2.texCoord0.y - v0.texCoord0.y) - (v2.texCoord0.x - v0.texCoord0.x) * (v1.texCoord0.y - v0.texCoord0.y)); outVertex.texCoord1Area = abs((v1.texCoord1.x - v0.texCoord1.x) * (v2.texCoord1.y - v0.texCoord1.y) - (v2.texCoord1.x - v0.texCoord1.x) * (v1.texCoord1.y - v0.texCoord1.y)); outVertex.texCoord2Area = abs((v1.texCoord2.x - v0.texCoord2.x) * (v2.texCoord2.y - v0.texCoord2.y) - (v2.texCoord2.x - v0.texCoord2.x) * (v1.texCoord2.y - v0.texCoord2.y)); outVertex.texCoord3Area = abs((v1.texCoord3.x - v0.texCoord3.x) * (v2.texCoord3.y - v0.texCoord3.y) - (v2.texCoord3.x - v0.texCoord3.x) * (v1.texCoord3.y - v0.texCoord3.y)); +#endif } #endif // UNITY_RAYTRACING_INTERSECTION_INCLUDED diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingReflectionFilter.compute b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingReflectionFilter.compute index 8513f42f8d6..ee10a7fe067 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingReflectionFilter.compute +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingReflectionFilter.compute @@ -73,18 +73,17 @@ void REFLECTION_INTEGRATION_UPSCALE(uint3 dispatchThreadId : SV_DispatchThreadID if (depth == UNITY_RAW_FAR_CLIP_VALUE || perceptualSmoothness < _RaytracingReflectionMinSmoothness) return; - // Fetch the normal WS - float3 normalWS = normalData.normalWS; - // Compute the world space position PositionInputs posInput = GetPositionInput(targetCoord, _ScreenSize.zw, depth, UNITY_MATRIX_I_VP, UNITY_MATRIX_V); - float3 positionWS = GetAbsolutePositionWS(posInput.positionWS); // Compute the view in world space - float3 viewWS = normalize(_WorldSpaceCameraPos - positionWS); + const float3 viewWS = normalize(-posInput.positionWS); + + // Compute NdotV and clamp it + const float NdotV = saturate(dot(viewWS, normalData.normalWS)); // Compute the reflected direction for this view direction - float3 reflDir = reflect(-viewWS, normalWS); + float3 reflDir = reflect(-viewWS, normalData.normalWS); // Initialize the output pixels float4 resultSum = float4(0.0 ,0.0, 0.0, 0.0); @@ -142,7 +141,7 @@ void REFLECTION_INTEGRATION_UPSCALE(uint3 dispatchThreadId : SV_DispatchThreadID float4 directionPDF = _SsrHitPointTexture[COORD_TEXTURE2D_X(sampleCoord)]; // If this direction is under the candidate surface, then it is not valid - if(dot(directionPDF.xyz, normalWS) <= 0.0f) continue; + if(dot(directionPDF.xyz, normalData.normalWS) <= 0.0f) continue; // If this direction is not in the hemisphere of the reflected view direction, then it is not valid if(dot(directionPDF.xyz, reflDir) <= 0.0f) continue; @@ -153,9 +152,8 @@ void REFLECTION_INTEGRATION_UPSCALE(uint3 dispatchThreadId : SV_DispatchThreadID { // Compute the brdf of this sample float3 H = normalize(directionPDF.xyz + viewWS); - float NdotH = dot(normalWS, H); - float NdotL = dot(directionPDF.xyz, normalWS); - float NdotV = dot(viewWS, normalWS); + float NdotH = dot(normalData.normalWS, H); + float NdotL = dot(directionPDF.xyz, normalData.normalWS); float localBRDF = D_GGX(NdotH, roughness) * V_SmithJointGGX(NdotL, NdotV, roughness) * NdotL; weight = localBRDF * directionPDF.w; } diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassRaytracingGBuffer.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassRaytracingGBuffer.hlsl index 7a20c2225c3..962b866422b 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassRaytracingGBuffer.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassRaytracingGBuffer.hlsl @@ -9,15 +9,9 @@ void ClosestHitGBuffer(inout RayIntersectionGBuffer rayIntersectionGbuffer : SV_ GetCurrentIntersectionVertex(attributeData, currentVertex); // Build the Frag inputs from the intersection vertice + const float3 incidentDir = WorldRayDirection(); FragInputs fragInput; - BuildFragInputsFromIntersection(currentVertex, rayIntersectionGbuffer.incidentDirection, fragInput); - - // Compute the view vector - float3 viewWS = -rayIntersectionGbuffer.incidentDirection; - - // Make sure to add the additional travel distance - float travelDistance = length(GetAbsolutePositionWS(fragInput.positionRWS) - rayIntersectionGbuffer.origin); - rayIntersectionGbuffer.cone.width += travelDistance * rayIntersectionGbuffer.cone.spreadAngle; + BuildFragInputsFromIntersection(currentVertex, incidentDir, fragInput); PositionInputs posInput; posInput.positionWS = fragInput.positionRWS; @@ -27,23 +21,29 @@ void ClosestHitGBuffer(inout RayIntersectionGBuffer rayIntersectionGbuffer : SV_ SurfaceData surfaceData; BuiltinData builtinData; bool isVisible; - GetSurfaceAndBuiltinData(fragInput, viewWS, posInput, surfaceData, builtinData, currentVertex, rayIntersectionGbuffer.cone, isVisible); - - // Sometimes, we only want to use the diffuse when we compute the indirect diffuse - if (_RayTracingDiffuseLightingOnly) - { - builtinData.bakeDiffuseLighting = float3(0.0, 0.0, 0.0); - builtinData.backBakeDiffuseLighting = float3(0.0, 0.0, 0.0); - } - + RayCone cone; + cone.width = 0.0; + cone.spreadAngle = 0.0; + GetSurfaceAndBuiltinData(fragInput, -incidentDir, posInput, surfaceData, builtinData, currentVertex, cone, isVisible); + // First we pack the data into the standard bsdf data StandardBSDFData standardLitData; ZERO_INITIALIZE(StandardBSDFData, standardLitData); FitToStandardLit(surfaceData, builtinData, posInput.positionSS, standardLitData); - + +#ifdef MINIMAL_GBUFFER + // Override all the parameters that we do not require for our minimal lit version + standardLitData.specularOcclusion = 1.0; + standardLitData.perceptualRoughness = 1.0; + standardLitData.normalWS = fragInput.tangentToWorld[2]; + standardLitData.fresnel0 = 0.0; + standardLitData.coatMask = 0.0; + standardLitData.emissiveAndBaked = builtinData.emissiveColor; +#endif + // Then export it to the gbuffer - ENCODE_TO_STANDARD_GBUFFER(standardLitData, rayIntersectionGbuffer.gBufferData.gbuffer); - rayIntersectionGbuffer.t = standardLitData.isUnlit != 0 ? -1 : travelDistance; + EncodeIntoStandardGBuffer(standardLitData, rayIntersectionGbuffer.gbuffer0, rayIntersectionGbuffer.gbuffer1, rayIntersectionGbuffer.gbuffer2, rayIntersectionGbuffer.gbuffer3); + rayIntersectionGbuffer.t = standardLitData.isUnlit != 0 ? -1 : RayTCurrent(); } // Generic function that handles the reflection code @@ -58,11 +58,9 @@ void AnyHitGBuffer(inout RayIntersectionGBuffer rayIntersectionGbuffer : SV_RayP GetCurrentIntersectionVertex(attributeData, currentVertex); // Build the Frag inputs from the intersection vertice + const float3 incidentDir = WorldRayDirection(); FragInputs fragInput; - BuildFragInputsFromIntersection(currentVertex, rayIntersectionGbuffer.incidentDirection, fragInput); - - // Compute the view vector - float3 viewWS = -rayIntersectionGbuffer.incidentDirection; + BuildFragInputsFromIntersection(currentVertex, incidentDir, fragInput); PositionInputs posInput; posInput.positionWS = fragInput.positionRWS; @@ -72,7 +70,10 @@ void AnyHitGBuffer(inout RayIntersectionGBuffer rayIntersectionGbuffer : SV_RayP SurfaceData surfaceData; BuiltinData builtinData; bool isVisible; - GetSurfaceAndBuiltinData(fragInput, viewWS, posInput, surfaceData, builtinData, currentVertex, rayIntersectionGbuffer.cone, isVisible); + RayCone cone; + cone.width = 0.0; + cone.spreadAngle = 0.0; + GetSurfaceAndBuiltinData(fragInput, -incidentDir, posInput, surfaceData, builtinData, currentVertex, cone, isVisible); // If this fella should be culled, then we cull it if(!isVisible) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassRaytracingVisibility.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassRaytracingVisibility.hlsl index cd5f4af829f..648edea6da2 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassRaytracingVisibility.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassRaytracingVisibility.hlsl @@ -17,7 +17,8 @@ void ClosestHitVisibility(inout RayIntersection rayIntersection : SV_RayPayload, rayIntersection.t = RayTCurrent(); // Compute the velocity of the itnersection - float3 previousPositionWS = TransformPreviousObjectToWorld(currentVertex.positionOS); + float3 positionOS = ObjectRayOrigin() + ObjectRayDirection() * rayIntersection.t; + float3 previousPositionWS = TransformPreviousObjectToWorld(positionOS); rayIntersection.velocity = saturate(length(previousPositionWS - fragInput.positionRWS)); } @@ -50,7 +51,8 @@ void AnyHitVisibility(inout RayIntersection rayIntersection : SV_RayPayload, Att GetSurfaceAndBuiltinData(fragInput, viewWS, posInput, surfaceData, builtinData, currentVertex, rayIntersection.cone, isVisible); #if defined(TRANSPARENT_COLOR_SHADOW) && defined(_SURFACE_TYPE_TRANSPARENT) // Compute the velocity of the itnersection - float3 previousPositionWS = TransformPreviousObjectToWorld(currentVertex.positionOS); + float3 positionOS = ObjectRayOrigin() + ObjectRayDirection() * rayIntersection.t; + float3 previousPositionWS = TransformPreviousObjectToWorld(positionOS); rayIntersection.velocity = saturate(length(previousPositionWS - fragInput.positionRWS)); #if HAS_REFRACTION