CULLING FINALLY WORKS
This commit is contained in:
@@ -25,8 +25,8 @@ void taskMain(
|
|||||||
if(threadID == 0)
|
if(threadID == 0)
|
||||||
{
|
{
|
||||||
head = 0;
|
head = 0;
|
||||||
float3 origin = float3(0, 0, 0);
|
float3 origin = viewToModel(instance.inverseTransformMatrix, float4(0, 0, 0, 1)).xyz;
|
||||||
const float offset = 600.0f;
|
const float offset = 0.0f;
|
||||||
float3 corners[4] = {
|
float3 corners[4] = {
|
||||||
screenToModel(instance.inverseTransformMatrix, float4(offset, offset, -1.0f, 1.0f)).xyz,
|
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,
|
screenToModel(instance.inverseTransformMatrix, float4(pViewParams.screenDimensions.x - offset, offset, -1.0f, 1.0f)).xyz,
|
||||||
|
|||||||
@@ -31,24 +31,24 @@ struct AABB
|
|||||||
float pad0;
|
float pad0;
|
||||||
float3 max;
|
float3 max;
|
||||||
float pad1;
|
float pad1;
|
||||||
|
// modified version from https://learnopengl.com/Guest-Articles/2021/Scene/Frustum-Culling
|
||||||
bool insideFrustum(Frustum frustum)
|
bool insideFrustum(Frustum frustum)
|
||||||
{
|
{
|
||||||
float3 corners[8];
|
float3 center = (min + max) * 0.5;
|
||||||
corners[0] = float3(min.x, min.y, min.z);
|
float3 extents = float3(max.x - center.x, max.y - center.y, max.z - center.z);
|
||||||
corners[1] = float3(min.x, min.y, max.z);
|
bool result = true;
|
||||||
corners[2] = float3(min.x, max.y, min.z);
|
for(int i = 0; i < 4 && result; ++i)
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
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;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -31,6 +31,13 @@ float4 viewToWorld(float4 view)
|
|||||||
return world;
|
return world;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float4 viewToModel(float4x4 inverseTransform, float4 view)
|
||||||
|
{
|
||||||
|
float4 world = viewToWorld(view);
|
||||||
|
|
||||||
|
return worldToModel(inverseTransform, world);
|
||||||
|
}
|
||||||
|
|
||||||
float4 clipToView(float4 clip)
|
float4 clipToView(float4 clip)
|
||||||
{
|
{
|
||||||
float4 view = mul(pViewParams.inverseProjection, clip);
|
float4 view = mul(pViewParams.inverseProjection, clip);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import Bounding;
|
|||||||
|
|
||||||
struct MeshletDescription
|
struct MeshletDescription
|
||||||
{
|
{
|
||||||
BoundingSphere bounding;
|
AABB bounding;
|
||||||
uint32_t vertexCount;
|
uint32_t vertexCount;
|
||||||
uint32_t primitiveCount;
|
uint32_t primitiveCount;
|
||||||
uint32_t vertexOffset;
|
uint32_t vertexOffset;
|
||||||
@@ -13,7 +13,7 @@ struct MeshletDescription
|
|||||||
|
|
||||||
struct MeshData
|
struct MeshData
|
||||||
{
|
{
|
||||||
BoundingSphere bounding;
|
AABB bounding;
|
||||||
uint32_t numMeshlets;
|
uint32_t numMeshlets;
|
||||||
uint32_t meshletOffset;
|
uint32_t meshletOffset;
|
||||||
uint32_t firstIndex;
|
uint32_t firstIndex;
|
||||||
|
|||||||
@@ -46,12 +46,12 @@ void VertexData::updateMesh(PMesh mesh, Component::Transform& transform)
|
|||||||
},
|
},
|
||||||
.data = data,
|
.data = data,
|
||||||
});
|
});
|
||||||
for (size_t i = 0; i < data.numMeshlets; ++i)
|
for (size_t i = 0; i < 0; ++i)
|
||||||
{
|
{
|
||||||
auto bounding = meshlets[data.meshletOffset + i].bounding;
|
auto bounding = meshlets[data.meshletOffset + i].bounding;
|
||||||
StaticArray<Vector, 8> corners;
|
StaticArray<Vector, 8> corners;
|
||||||
Vector min = bounding.center - bounding.radius * Vector(1, 1, 1);
|
Vector min = bounding.min;//bounding.center - bounding.radius * Vector(1, 1, 1);
|
||||||
Vector max = bounding.center + bounding.radius * Vector(1, 1, 1);
|
Vector max = bounding.max;//bounding.center + bounding.radius * Vector(1, 1, 1);
|
||||||
corners[0] = transformMatrix * Vector4(min.x, min.y, min.z, 1);
|
corners[0] = transformMatrix * Vector4(min.x, min.y, min.z, 1);
|
||||||
corners[1] = transformMatrix * Vector4(min.x, min.y, max.z, 1);
|
corners[1] = transformMatrix * Vector4(min.x, min.y, max.z, 1);
|
||||||
corners[2] = transformMatrix * Vector4(min.x, max.y, min.z, 1);
|
corners[2] = transformMatrix * Vector4(min.x, max.y, min.z, 1);
|
||||||
@@ -171,7 +171,7 @@ void VertexData::loadMesh(MeshId id, Array<uint32> loadedIndices, Array<Meshlet>
|
|||||||
primitiveIndices.resize(primitiveOffset + (m.numPrimitives * 3));
|
primitiveIndices.resize(primitiveOffset + (m.numPrimitives * 3));
|
||||||
std::memcpy(primitiveIndices.data() + primitiveOffset, m.primitiveLayout, m.numPrimitives * 3 * sizeof(uint8));
|
std::memcpy(primitiveIndices.data() + primitiveOffset, m.primitiveLayout, m.numPrimitives * 3 * sizeof(uint8));
|
||||||
meshlets.add(MeshletDescription{
|
meshlets.add(MeshletDescription{
|
||||||
.bounding = m.boundingBox.toSphere(),
|
.bounding = m.boundingBox,//.toSphere(),
|
||||||
.vertexCount = m.numVertices,
|
.vertexCount = m.numVertices,
|
||||||
.primitiveCount = m.numPrimitives,
|
.primitiveCount = m.numPrimitives,
|
||||||
.vertexOffset = vertexOffset,
|
.vertexOffset = vertexOffset,
|
||||||
@@ -180,7 +180,7 @@ void VertexData::loadMesh(MeshId id, Array<uint32> loadedIndices, Array<Meshlet>
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
meshData[id].add(MeshData{
|
meshData[id].add(MeshData{
|
||||||
.bounding = meshAABB.toSphere(),
|
.bounding = meshAABB,//.toSphere(),
|
||||||
.numMeshlets = numMeshlets,
|
.numMeshlets = numMeshlets,
|
||||||
.meshletOffset = meshletOffset,
|
.meshletOffset = meshletOffset,
|
||||||
.indicesOffset = (uint32)meshOffsets[id],
|
.indicesOffset = (uint32)meshOffsets[id],
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public:
|
|||||||
};
|
};
|
||||||
struct MeshData
|
struct MeshData
|
||||||
{
|
{
|
||||||
BoundingSphere bounding;
|
AABB bounding;
|
||||||
uint32 numMeshlets = 0;
|
uint32 numMeshlets = 0;
|
||||||
uint32 meshletOffset = 0;
|
uint32 meshletOffset = 0;
|
||||||
uint32 firstIndex = 0;
|
uint32 firstIndex = 0;
|
||||||
@@ -86,7 +86,7 @@ protected:
|
|||||||
VertexData();
|
VertexData();
|
||||||
struct MeshletDescription
|
struct MeshletDescription
|
||||||
{
|
{
|
||||||
BoundingSphere bounding;
|
AABB bounding;
|
||||||
uint32_t vertexCount;
|
uint32_t vertexCount;
|
||||||
uint32_t primitiveCount;
|
uint32_t primitiveCount;
|
||||||
uint32_t vertexOffset;
|
uint32_t vertexOffset;
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ GameView::GameView(Gfx::PGraphics graphics, PWindow window, const ViewportCreate
|
|||||||
renderGraph.addPass(new DepthPrepass(graphics, scene));
|
renderGraph.addPass(new DepthPrepass(graphics, scene));
|
||||||
renderGraph.addPass(new LightCullingPass(graphics, scene));
|
renderGraph.addPass(new LightCullingPass(graphics, scene));
|
||||||
renderGraph.addPass(new BasePass(graphics, scene));
|
renderGraph.addPass(new BasePass(graphics, scene));
|
||||||
renderGraph.addPass(new DebugPass(graphics, scene));
|
//renderGraph.addPass(new DebugPass(graphics, scene));
|
||||||
//renderGraph.addPass(new SkyboxRenderPass(graphics, scene));
|
//renderGraph.addPass(new SkyboxRenderPass(graphics, scene));
|
||||||
renderGraph.setViewport(viewport);
|
renderGraph.setViewport(viewport);
|
||||||
renderGraph.createRenderPass();
|
renderGraph.createRenderPass();
|
||||||
|
|||||||
Reference in New Issue
Block a user