Skip to content

Commit

Permalink
[HDRP][Path Tracing] Fixed issues with path-traced volumetrics (light…
Browse files Browse the repository at this point in the history
… anim dirtiness, truncated volume shafts) #2771
  • Loading branch information
eturquin authored and sebastienlagarde committed Jan 12, 2021
1 parent 6385ad8 commit c170333
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@ float3x3 RotationFromAxisAngle(float3 A, float sinAngle, float cosAngle)

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

return (d >= 0);
float sqrtDet = sqrt(det);
roots.x = (-b - sign(a) * sqrtDet) / (2.0 * a);
roots.y = (-b + sign(a) * sqrtDet) / (2.0 * a);

return (det >= 0.0);
}

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

tEntr = min(roots.x, roots.y);
tExit = max(roots.x, roots.y);
tEntr = roots.x;
tExit = roots.y;
float3 pEntr = o + tEntr * d;
float3 pExit = o + tExit * d;

Expand Down
1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Fixed
- Fixed issue where some ShaderGraph generated shaders were not SRP compatible because of UnityPerMaterial cbuffer layout mismatches (case 1292501)
- Fixed computation of geometric normal in path tracing (case 1293029).
- Fixed issues with path-traced volumetric scattering (cases 1295222, 1295234).

### Changed
- Now reflection probes cannot have SSAO, SSGI, SSR, ray tracing effects or volumetric reprojection.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,13 @@ private void CheckDirtiness(HDCamera hdCamera)
return;
}

// Check light or geometry transforms dirtiness
if (m_TransformDirty)
{
m_TransformDirty = false;
ResetPathTracing();
}

// Check lights dirtiness
if (m_CacheLightCount != m_RayTracingLights.lightCount)
{
Expand All @@ -208,10 +215,9 @@ private void CheckDirtiness(HDCamera hdCamera)

// Check geometry dirtiness
ulong accelSize = m_CurrentRAS.GetSize();
if (accelSize != m_CacheAccelSize || m_TransformDirty)
if (accelSize != m_CacheAccelSize)
{
m_CacheAccelSize = accelSize;
m_TransformDirty = false;
ResetPathTracing();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,10 @@ void RaytracingManagerCleanupNonRenderGraphResources()
if (instanceFlag == 0) return AccelerationStructureStatus.Added;

// Add it to the acceleration structure
m_TransformDirty |= currentRenderer.transform.hasChanged;
m_CurrentRAS.AddInstance(currentRenderer, subMeshMask: subMeshFlagArray, subMeshTransparencyFlags: subMeshCutoffArray, enableTriangleCulling: singleSided, mask: instanceFlag);

// Indicates that a transform has changed in our scene (mesh or light)
m_TransformDirty |= currentRenderer.transform.hasChanged;
currentRenderer.transform.hasChanged = false;

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

// Indicates that a transform has changed in our scene (mesh or light)
m_TransformDirty |= hdLight.transform.hasChanged;
hdLight.transform.hasChanged = false;

switch (hdLight.type)
{
case HDLightType.Directional:
Expand Down

0 comments on commit c170333

Please sign in to comment.