Skip to content

Commit

Permalink
Better voxel tracing normal computation
Browse files Browse the repository at this point in the history
  • Loading branch information
cfnptr committed Feb 2, 2025
1 parent a18212a commit b371847
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions resources/shaders/common/voxel-tracing.gsl
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,10 @@ void raycastVoxel(VoxelTraceConsts consts, inout VoxelTraceData data)
}
float3 computeVoxelNormal(VoxelTraceData data)
{
float3 normal = data.traceOrigin - (float3(data.voxelPosition) + 0.5f);
float3 absNormal = abs(normal);
float maxNormal = max(max(absNormal.x, absNormal.y), absNormal.z);
if (maxNormal == absNormal.x) normal = float3(sign(normal.x), 0.0f, 0.0f);
else if (maxNormal == absNormal.y) normal = float3(0.0f, sign(normal.y), 0.0f);
else normal = float3(0.0f, 0.0f, sign(normal.z));
float3 normal;
float3 surfacePos = data.traceOrigin - (float3(data.voxelPosition) + 0.5f);
int32 index = getLowest(abs(abs(surfacePos) - 0.5f));
normal[index] = surfacePos[index] > 0.0f ? 1.0f : -1.0f;
return normal;
}

Expand Down

0 comments on commit b371847

Please sign in to comment.