Skip to content

Commit c170333

Browse files
eturquinsebastienlagarde
authored andcommitted
[HDRP][Path Tracing] Fixed issues with path-traced volumetrics (light anim dirtiness, truncated volume shafts) #2771
1 parent 6385ad8 commit c170333

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,16 @@ float3x3 RotationFromAxisAngle(float3 A, float sinAngle, float cosAngle)
2929

3030
// Solves the quadratic equation of the form: a*t^2 + b*t + c = 0.
3131
// Returns 'false' if there are no real roots, 'true' otherwise.
32-
// Numerically stable.
33-
// Ref: Numerical Recipes in C++ (3rd Edition)
32+
// Ensures that roots.x <= roots.y.
3433
bool SolveQuadraticEquation(float a, float b, float c, out float2 roots)
3534
{
36-
float d = b * b - 4 * a * c;
37-
float q = -0.5 * (b + CopySign(sqrt(d), b));
38-
roots = float2(c / q, q / a);
35+
float det = Sq(b) - 4.0 * a * c;
3936

40-
return (d >= 0);
37+
float sqrtDet = sqrt(det);
38+
roots.x = (-b - sign(a) * sqrtDet) / (2.0 * a);
39+
roots.y = (-b + sign(a) * sqrtDet) / (2.0 * a);
40+
41+
return (det >= 0.0);
4142
}
4243

4344
//-----------------------------------------------------------------------------
@@ -159,8 +160,8 @@ bool IntersectRayCone(float3 rayOrigin, float3 rayDirection,
159160
// Check whether we have at least 1 root.
160161
bool hit = SolveQuadraticEquation(a, 2 * b, c, roots);
161162

162-
tEntr = min(roots.x, roots.y);
163-
tExit = max(roots.x, roots.y);
163+
tEntr = roots.x;
164+
tExit = roots.y;
164165
float3 pEntr = o + tEntr * d;
165166
float3 pExit = o + tExit * d;
166167

com.unity.render-pipelines.high-definition/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1212
### Fixed
1313
- Fixed issue where some ShaderGraph generated shaders were not SRP compatible because of UnityPerMaterial cbuffer layout mismatches (case 1292501)
1414
- Fixed computation of geometric normal in path tracing (case 1293029).
15+
- Fixed issues with path-traced volumetric scattering (cases 1295222, 1295234).
1516

1617
### Changed
1718
- Now reflection probes cannot have SSAO, SSGI, SSR, ray tracing effects or volumetric reprojection.

com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/PathTracing.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,13 @@ private void CheckDirtiness(HDCamera hdCamera)
198198
return;
199199
}
200200

201+
// Check light or geometry transforms dirtiness
202+
if (m_TransformDirty)
203+
{
204+
m_TransformDirty = false;
205+
ResetPathTracing();
206+
}
207+
201208
// Check lights dirtiness
202209
if (m_CacheLightCount != m_RayTracingLights.lightCount)
203210
{
@@ -208,10 +215,9 @@ private void CheckDirtiness(HDCamera hdCamera)
208215

209216
// Check geometry dirtiness
210217
ulong accelSize = m_CurrentRAS.GetSize();
211-
if (accelSize != m_CacheAccelSize || m_TransformDirty)
218+
if (accelSize != m_CacheAccelSize)
212219
{
213220
m_CacheAccelSize = accelSize;
214-
m_TransformDirty = false;
215221
ResetPathTracing();
216222
}
217223
}

com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingManager.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,10 @@ AccelerationStructureStatus AddInstanceToRAS(Renderer currentRenderer,
341341
if (instanceFlag == 0) return AccelerationStructureStatus.Added;
342342

343343
// Add it to the acceleration structure
344-
m_TransformDirty |= currentRenderer.transform.hasChanged;
345344
m_CurrentRAS.AddInstance(currentRenderer, subMeshMask: subMeshFlagArray, subMeshTransparencyFlags: subMeshCutoffArray, enableTriangleCulling: singleSided, mask: instanceFlag);
345+
346+
// Indicates that a transform has changed in our scene (mesh or light)
347+
m_TransformDirty |= currentRenderer.transform.hasChanged;
346348
currentRenderer.transform.hasChanged = false;
347349

348350
// return the status
@@ -387,6 +389,10 @@ internal void BuildRayTracingAccelerationStructure(HDCamera hdCamera)
387389
m_RayTracedShadowsRequired |= (hdLight.useRayTracedShadows && screenSpaceShadowsSupported);
388390
m_RayTracedContactShadowsRequired |= (hdLight.useContactShadow.@override && hdLight.rayTraceContactShadow);
389391

392+
// Indicates that a transform has changed in our scene (mesh or light)
393+
m_TransformDirty |= hdLight.transform.hasChanged;
394+
hdLight.transform.hasChanged = false;
395+
390396
switch (hdLight.type)
391397
{
392398
case HDLightType.Directional:

0 commit comments

Comments
 (0)