Fixed meshlet culling

This commit is contained in:
Dynamitos
2024-03-31 10:21:09 +02:00
parent 82baf898a6
commit 578320cf07
16 changed files with 160 additions and 67 deletions
+13 -10
View File
@@ -11,17 +11,20 @@ struct BoundingSphere
{
return centerRadius.w;
}
bool pointInside(float3 p)
{
if(abs(getCenter() - p) > getRadius())
{
return false;
}
return true;
}
bool insideFrustum(float4x4 transform, Frustum frustum)
{
float3 transformed = mul(transform, float4(getCenter(), 1)).xyz;
float maxScale = max(max(transform[0][0], transform[1][1]), transform[2][2]);
float scaledRange = getRadius() * maxScale;
bool result = true;
for(int i = 0; i < 4 && result; ++i)
{
if(dot(frustum.sides[i].n, transformed) - frustum.sides[i].d < scaledRange)
{
result = false;
}
}
return result;
}
};
@@ -45,7 +48,7 @@ struct AABB
for(int i = 0; i < 8; ++i)
{
float3 adjusted = corners[i].xyz / corners[i].w;
if(frustum.pointInside(adjusted))
if(frustum.pointInside(corners[i].xyz))
{
return true;
}
+1 -1
View File
@@ -2,7 +2,7 @@ import Common;
import VertexData;
import MaterialParameter;
struct StaticMeshVertexData : IVertexData
struct DebugVertexData : IVertexData
{
VertexAttributes getAttributes(uint index)
{
+2 -2
View File
@@ -2,7 +2,7 @@ import Bounding;
struct MeshletDescription
{
BoundingSphere bounding;
AABB bounding;
uint32_t vertexCount;
uint32_t primitiveCount;
uint32_t vertexOffset;
@@ -13,7 +13,7 @@ struct MeshletDescription
struct MeshData
{
BoundingSphere bounding;
AABB bounding;
uint32_t numMeshlets;
uint32_t meshletOffset;
uint32_t firstIndex;