CULLING FINALLY WORKS

This commit is contained in:
Dynamitos
2024-05-05 08:31:40 +02:00
parent 87b72dcd84
commit 05bb1d0cee
7 changed files with 32 additions and 25 deletions
+2 -2
View File
@@ -25,8 +25,8 @@ void taskMain(
if(threadID == 0)
{
head = 0;
float3 origin = float3(0, 0, 0);
const float offset = 600.0f;
float3 origin = viewToModel(instance.inverseTransformMatrix, float4(0, 0, 0, 1)).xyz;
const float offset = 0.0f;
float3 corners[4] = {
screenToModel(instance.inverseTransformMatrix, float4(offset, offset, -1.0f, 1.0f)).xyz,
screenToModel(instance.inverseTransformMatrix, float4(pViewParams.screenDimensions.x - offset, offset, -1.0f, 1.0f)).xyz,
+13 -13
View File
@@ -31,24 +31,24 @@ struct AABB
float pad0;
float3 max;
float pad1;
// modified version from https://learnopengl.com/Guest-Articles/2021/Scene/Frustum-Culling
bool insideFrustum(Frustum frustum)
{
float3 corners[8];
corners[0] = float3(min.x, min.y, min.z);
corners[1] = float3(min.x, min.y, max.z);
corners[2] = float3(min.x, max.y, min.z);
corners[3] = float3(min.x, max.y, max.z);
corners[4] = float3(max.x, min.y, min.z);
corners[5] = float3(max.x, min.y, max.z);
corners[6] = float3(max.x, max.y, min.z);
corners[7] = float3(max.x, max.y, max.z);
for(int i = 0; i < 8; ++i)
float3 center = (min + max) * 0.5;
float3 extents = float3(max.x - center.x, max.y - center.y, max.z - center.z);
bool result = true;
for(int i = 0; i < 4 && result; ++i)
{
if(frustum.pointInside(corners[i]))
const float r = extents.x * abs(frustum.sides[i].n.x)
+ extents.y * abs(frustum.sides[i].n.y)
+ extents.z * abs(frustum.sides[i].n.z);
const float signedDistance = dot(frustum.sides[i].n, center) - frustum.sides[i].d;
if(signedDistance < -r)
{
return true;
result = false;
}
}
return false;
return result;
}
};
+7
View File
@@ -31,6 +31,13 @@ float4 viewToWorld(float4 view)
return world;
}
float4 viewToModel(float4x4 inverseTransform, float4 view)
{
float4 world = viewToWorld(view);
return worldToModel(inverseTransform, world);
}
float4 clipToView(float4 clip)
{
float4 view = mul(pViewParams.inverseProjection, clip);
+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;