Fixing Depth culling out of bounds errors

This commit is contained in:
Dynamitos
2024-08-29 11:23:55 +02:00
parent 6eb114e892
commit 0be1a3cbde
9 changed files with 136 additions and 44 deletions
+4 -3
View File
@@ -51,7 +51,7 @@ struct AABB
}
return result;
}
float projectScreenDepth(float4x4 mvp, inout uint2 screenCornerMin, inout uint2 screenCornerMax)
float projectScreenDepth(float4x4 mvp, inout int2 screenCornerMin, inout int2 screenCornerMax)
{
float maxDepth = 0;
float4 corners[8];
@@ -67,8 +67,9 @@ struct AABB
{
float4 clipCorner = mul(mvp, corners[i]);
float4 screenCorner = clipToScreen(clipCorner);
screenCornerMin = uint2(min(screenCornerMin.x, uint(screenCorner.x)), min(screenCornerMin.y, uint(screenCorner.y)));
screenCornerMax = uint2(max(screenCornerMax.x, uint(screenCorner.x)), max(screenCornerMax.y, uint(screenCorner.y)));
int2 screenCoords = int2(clamp(int(screenCorner.x), 0, int(pViewParams.screenDimensions.x)), clamp(int(screenCorner.y), 0, int(pViewParams.screenDimensions.y)));
screenCornerMin = int2(min(screenCornerMin.x, screenCoords.x), min(screenCornerMin.y, screenCoords.y));
screenCornerMax = int2(max(screenCornerMax.x, screenCoords.x), max(screenCornerMax.y, screenCoords.y));
maxDepth = max(maxDepth, screenCorner.z);
}
return maxDepth;