Skip to content

Fixed a bug in the sphere-aabb light cluster (case 1294767). #2920

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,15 @@ bool IntersectRayCone(float3 rayOrigin, float3 rayDirection,
return hit;
}

bool IntersectSphereAABB(float3 position, float radius, float3 aabbMin, float3 aabbMax)
{
float x = max(aabbMin.x, min(position.x, aabbMax.x));
float y = max(aabbMin.y, min(position.y, aabbMax.y));
float z = max(aabbMin.z, min(position.z, aabbMax.z));
float distance2 = ((x - position.x) * (x - position.x) + (y - position.y) * (y - position.y) + (z - position.z) * (z - position.z));
return distance2 < radius * radius;
}

//-----------------------------------------------------------------------------
// Miscellaneous functions
//-----------------------------------------------------------------------------
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 @@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed AOV api in render graph (case 1296605)
- Fixed a small discrepancy in the marker placement in light intensity sliders (case 1299750)
- Fixed issue with VT resolve pass rendergraph errors when opaque and transparent are disabled in frame settings.
- Fixed a bug in the sphere-aabb light cluster (case 1294767).

### Changed
- Removed the material pass probe volumes evaluation mode.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,15 +323,19 @@ void BuildGPULightVolumes(HDCamera hdCamera, HDRayTracingLights rayTracingLights
{
HDProbe currentEnvLight = rayTracingLights.reflectionProbeArray[lightIdx];

// Compute the camera relative position
Vector3 probePositionRWS = currentEnvLight.influenceToWorld.GetColumn(3);
if (ShaderConfig.s_CameraRelativeRendering != 0)
{
probePositionRWS -= hdCamera.camera.transform.position;
}

if (currentEnvLight != null)
{
// If the reflection probe is disabled, we should not be adding it
if (!currentEnvLight.enabled) continue;

// Compute the camera relative position
Vector3 probePositionRWS = currentEnvLight.influenceToWorld.GetColumn(3);
if (ShaderConfig.s_CameraRelativeRendering != 0)
{
probePositionRWS -= hdCamera.camera.transform.position;
}

if (currentEnvLight.influenceVolume.shape == InfluenceShape.Sphere)
{
m_LightVolumesCPUArray[lightIdx + indexOffset].shape = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingLightCluster.cs.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracingLightLoop.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl"

#define CLUSTER_GROUP_SIZE 8

Expand Down Expand Up @@ -78,27 +79,8 @@ void RaytracingLightCluster(uint3 threadID : SV_GroupThreadID, uint3 groupId : S

if (currentLight.shape == 0)
{
// When the shape we are processing is a sphere, the radius is stored in the three channels
float squareRange = currentLight.range.x * currentLight.range.x;

// So basically we need to flag this cell if one of the corners of the cell happens to be in the sphere
for(uint cIdx = 0; cIdx < 8; ++cIdx)
{
// Check if this corner is inside the shphere
float3 dir = currentLight.position - (cellCenterPosition + CornerSubDirections[cIdx] * _ClusterCellSize);
if(dot(dir, dir) <= squareRange)
{
intersects = true;
break;
}
}

// One additional case that we need to check is: Is the light inside the cell?
if (!intersects)
{
float3 distanceToCenter = abs(cellCenterPosition - currentLight.position) * 2.0;
intersects = (distanceToCenter.x < _ClusterCellSize.x) && (distanceToCenter.y < _ClusterCellSize.y) && (distanceToCenter.z < _ClusterCellSize.z);
}
// Do a box sphere intersection
intersects = IntersectSphereAABB(currentLight.position, currentLight.range.x, cellCenterPosition + CornerSubDirections[0] * _ClusterCellSize, cellCenterPosition + CornerSubDirections[7] * _ClusterCellSize);
}
else
{
Expand Down