diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/1000_RaytracingQualityKeyword_PathTracer_Default.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/1000_RaytracingQualityKeyword_PathTracer_Default.png index 510a66bdae4..58f3ec3b244 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/1000_RaytracingQualityKeyword_PathTracer_Default.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/1000_RaytracingQualityKeyword_PathTracer_Default.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:08b57a5a118c31de7a0b88921a96aab1fe7f029eeed3e4bcd5e04d13067cb1a5 -size 594548 +oid sha256:8ceb91cb624b7c428911efde6befd0b903cb4a4c0c6f429715f378c0096428f9 +size 593509 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5001_PathTracing.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5001_PathTracing.png index d955c665188..c78283a6402 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5001_PathTracing.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5001_PathTracing.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:60972ed3fac11868812d547e46e20cb41c22bbe11e38433a69e14ee1eaf8160c -size 594959 +oid sha256:292d270609c93cd8db32588523ab4d477fa693fd8e7c81d0590ce1133b3296fb +size 595404 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5006_PathTracing_DoF.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5006_PathTracing_DoF.png index 9f615549e99..afe33c09740 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5006_PathTracing_DoF.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5006_PathTracing_DoF.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f0d0ee8840624839d44e46b03d4fb624dee9a7f889b78a064f21f788bb734d01 -size 582422 +oid sha256:4a1be4770d57a043a2c05efdfa1b8034bc05213e4e9d377ed97d7d0effe31d6e +size 581407 diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 8aed6165458..1d3371790d0 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed couple samplers that had the wrong name in raytracing code - VFX : Debug material view were rendering pink for albedo. (case 1290752) - VFX: Fixed LPPV with lit particles in deferred (case 1293608) +- Fixed computation of geometric normal in path tracing (case 1293029). ### Changed - Removed the material pass probe volumes evaluation mode. 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 0f1cfacb0c8..a644452386c 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 @@ -174,4 +174,15 @@ void GetCurrentIntersectionVertex(AttributeData attributeData, out IntersectionV #endif } +// Compute the proper world space geometric normal from the intersected triangle +void GetCurrentIntersectionGeometricNormal(AttributeData attributeData, out float3 geomNormalWS) +{ + uint3 triangleIndices = UnityRayTracingFetchTriangleIndices(PrimitiveIndex()); + float3 p0 = UnityRayTracingFetchVertexAttribute3(triangleIndices.x, kVertexAttributePosition); + float3 p1 = UnityRayTracingFetchVertexAttribute3(triangleIndices.y, kVertexAttributePosition); + float3 p2 = UnityRayTracingFetchVertexAttribute3(triangleIndices.z, kVertexAttributePosition); + + geomNormalWS = normalize(mul(cross(p1 - p0, p2 - p0), (float3x3)WorldToObject3x4())); +} + #endif // UNITY_RAYTRACING_INTERSECTION_INCLUDED diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassPathTracing.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassPathTracing.hlsl index 4bfe1991715..ca9b6f809b6 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassPathTracing.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassPathTracing.hlsl @@ -54,6 +54,11 @@ void ComputeSurfaceScattering(inout PathIntersection pathIntersection : SV_RayPa posInput.positionWS = fragInput.positionRWS; posInput.positionSS = pathIntersection.pixelCoord; + // For path tracing, we want the front-facing test to be performed on the actual geometric normal + float3 geomNormal; + GetCurrentIntersectionGeometricNormal(attributeData, geomNormal); + fragInput.isFrontFace = dot(WorldRayDirection(), geomNormal) < 0.0; + // Build the surfacedata and builtindata SurfaceData surfaceData; BuiltinData builtinData; @@ -75,7 +80,11 @@ void ComputeSurfaceScattering(inout PathIntersection pathIntersection : SV_RayPa #ifndef SHADER_UNLIT - // Let's compute the world space position (the non-camera relative one if camera relative rendering is enabled) + // Override the geometric normal (otherwise, it is merely the non-mapped smooth normal) + // Also make sure that it is in the same hemisphere as the shading normal (which may have been flipped) + bsdfData.geomNormalWS = dot(bsdfData.normalWS, geomNormal) > 0.0 ? geomNormal : -geomNormal; + + // Compute the world space position (the non-camera relative one if camera relative rendering is enabled) float3 shadingPosition = fragInput.positionRWS; // Get current path throughput