Fixed meshlet culling
This commit is contained in:
+15
-14
@@ -4,25 +4,26 @@ struct DebugVertex
|
|||||||
{
|
{
|
||||||
float3 position;
|
float3 position;
|
||||||
float3 color;
|
float3 color;
|
||||||
}
|
|
||||||
|
|
||||||
struct VertexOutput
|
|
||||||
{
|
|
||||||
float4 clipPosition : SV_Position;
|
|
||||||
float3 color : COLOR0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
[shader("vertex")]
|
struct Params
|
||||||
VertexOutput vertexMain(DebugVertex input)
|
|
||||||
{
|
{
|
||||||
VertexOutput output;
|
float4 pos: SV_Position;
|
||||||
output.clipPosition = mul(pViewParams.projectionMatrix, mul(pViewParams.viewMatrix, float4(input.position, 1.0f)));
|
float3 color: COLOR0;
|
||||||
output.color = input.color;
|
}
|
||||||
return output;
|
|
||||||
|
[shader("vertex")]
|
||||||
|
Params vertexMain(
|
||||||
|
DebugVertex vert
|
||||||
|
){
|
||||||
|
Params result;
|
||||||
|
result.pos = mul(pViewParams.projectionMatrix, mul(pViewParams.viewMatrix, float4(vert.position, 1)));
|
||||||
|
result.color = vert.color;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[shader("pixel")]
|
[shader("pixel")]
|
||||||
float4 fragmentMain(VertexOutput input)
|
float4 fragmentMain(in Params params) : SV_Target
|
||||||
{
|
{
|
||||||
return float4(input.color, 1.0f);
|
return float4(params.color, 1);
|
||||||
}
|
}
|
||||||
@@ -12,7 +12,7 @@ struct MeshPayload
|
|||||||
|
|
||||||
groupshared MeshPayload p;
|
groupshared MeshPayload p;
|
||||||
groupshared uint head;
|
groupshared uint head;
|
||||||
groupshared float4x4 localToClip;
|
groupshared float4x4 localToView;
|
||||||
groupshared Frustum viewFrustum;
|
groupshared Frustum viewFrustum;
|
||||||
|
|
||||||
[numthreads(TASK_GROUP_SIZE, 1, 1)]
|
[numthreads(TASK_GROUP_SIZE, 1, 1)]
|
||||||
@@ -26,19 +26,18 @@ void taskMain(
|
|||||||
if(threadID == 0)
|
if(threadID == 0)
|
||||||
{
|
{
|
||||||
head = 0;
|
head = 0;
|
||||||
localToClip = mul(pViewParams.projectionMatrix, mul(pViewParams.viewMatrix, instance.transformMatrix));
|
localToView = mul(pViewParams.viewMatrix, instance.transformMatrix);
|
||||||
// Left
|
float3 origin = float3(0, 0, 0);
|
||||||
viewFrustum.sides[0].n = float3(1, 0, 0);
|
float3 corners[4] = {
|
||||||
viewFrustum.sides[0].d = -1;
|
screenToView(float4(pViewParams.screenDimensions, -1.0f, 1.0f)).xyz,
|
||||||
// Right
|
screenToView(float4(pViewParams.screenDimensions, -1.0f, 1.0f)).xyz,
|
||||||
viewFrustum.sides[1].n = float3(-1, 0, 0);
|
screenToView(float4(pViewParams.screenDimensions, -1.0f, 1.0f)).xyz,
|
||||||
viewFrustum.sides[1].d = -1;
|
screenToView(float4(pViewParams.screenDimensions, -1.0f, 1.0f)).xyz
|
||||||
// Top
|
};
|
||||||
viewFrustum.sides[2].n = float3(0, -1, 0);
|
viewFrustum.sides[0] = computePlane(origin, corners[2], corners[0]);
|
||||||
viewFrustum.sides[2].d = -1;
|
viewFrustum.sides[1] = computePlane(origin, corners[1], corners[3]);
|
||||||
// Bottom
|
viewFrustum.sides[2] = computePlane(origin, corners[0], corners[1]);
|
||||||
viewFrustum.sides[3].n = float3(0, 1, 0);
|
viewFrustum.sides[3] = computePlane(origin, corners[3], corners[2]);
|
||||||
viewFrustum.sides[3].d = -1;
|
|
||||||
}
|
}
|
||||||
GroupMemoryBarrierWithGroupSync();
|
GroupMemoryBarrierWithGroupSync();
|
||||||
MeshData mesh = pScene.meshData[groupID];
|
MeshData mesh = pScene.meshData[groupID];
|
||||||
@@ -48,7 +47,7 @@ void taskMain(
|
|||||||
{
|
{
|
||||||
uint m = mesh.meshletOffset + i;
|
uint m = mesh.meshletOffset + i;
|
||||||
MeshletDescription meshlet = pScene.meshletInfos[m];
|
MeshletDescription meshlet = pScene.meshletInfos[m];
|
||||||
//if(meshlet.boundingBox.insideFrustum(localToClip, viewFrustum))
|
if(meshlet.bounding.insideFrustum(localToView, viewFrustum))
|
||||||
{
|
{
|
||||||
uint index;
|
uint index;
|
||||||
InterlockedAdd(head, 1, index);
|
InterlockedAdd(head, 1, index);
|
||||||
|
|||||||
@@ -11,17 +11,20 @@ struct BoundingSphere
|
|||||||
{
|
{
|
||||||
return centerRadius.w;
|
return centerRadius.w;
|
||||||
}
|
}
|
||||||
bool pointInside(float3 p)
|
|
||||||
{
|
|
||||||
if(abs(getCenter() - p) > getRadius())
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool insideFrustum(float4x4 transform, Frustum frustum)
|
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)
|
for(int i = 0; i < 8; ++i)
|
||||||
{
|
{
|
||||||
float3 adjusted = corners[i].xyz / corners[i].w;
|
float3 adjusted = corners[i].xyz / corners[i].w;
|
||||||
if(frustum.pointInside(adjusted))
|
if(frustum.pointInside(corners[i].xyz))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import Common;
|
|||||||
import VertexData;
|
import VertexData;
|
||||||
import MaterialParameter;
|
import MaterialParameter;
|
||||||
|
|
||||||
struct StaticMeshVertexData : IVertexData
|
struct DebugVertexData : IVertexData
|
||||||
{
|
{
|
||||||
VertexAttributes getAttributes(uint index)
|
VertexAttributes getAttributes(uint index)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ struct ColorBlendState
|
|||||||
SeBlendFactor srcAlphaBlendFactor = Gfx::SE_BLEND_FACTOR_SRC_ALPHA;
|
SeBlendFactor srcAlphaBlendFactor = Gfx::SE_BLEND_FACTOR_SRC_ALPHA;
|
||||||
SeBlendFactor dstAlphaBlendFactor = Gfx::SE_BLEND_FACTOR_SRC_ALPHA;
|
SeBlendFactor dstAlphaBlendFactor = Gfx::SE_BLEND_FACTOR_SRC_ALPHA;
|
||||||
SeBlendOp alphaBlendOp = Gfx::SE_BLEND_OP_ADD;
|
SeBlendOp alphaBlendOp = Gfx::SE_BLEND_OP_ADD;
|
||||||
SeColorComponentFlags colorWriteMask = 0;
|
SeColorComponentFlags colorWriteMask = Gfx::SE_COLOR_COMPONENT_R_BIT | Gfx::SE_COLOR_COMPONENT_G_BIT | Gfx::SE_COLOR_COMPONENT_B_BIT | Gfx::SE_COLOR_COMPONENT_A_BIT;
|
||||||
};
|
};
|
||||||
uint32 logicOpEnable;
|
uint32 logicOpEnable;
|
||||||
SeLogicOp logicOp = Gfx::SE_LOGIC_OP_OR;
|
SeLogicOp logicOp = Gfx::SE_LOGIC_OP_OR;
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ void BasePass::render()
|
|||||||
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||||
depthAttachment.getTexture()->pipelineBarrier(
|
depthAttachment.getTexture()->pipelineBarrier(
|
||||||
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
|
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
|
||||||
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT);
|
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT, Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT);
|
||||||
|
|
||||||
descriptorSets[INDEX_VIEW_PARAMS] = viewParamsSet;
|
descriptorSets[INDEX_VIEW_PARAMS] = viewParamsSet;
|
||||||
descriptorSets[INDEX_LIGHT_ENV] = scene->getLightEnvironment()->getDescriptorSet();
|
descriptorSets[INDEX_LIGHT_ENV] = scene->getLightEnvironment()->getDescriptorSet();
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ void DebugPass::render()
|
|||||||
renderCommand->draw((uint32)gDebugVertices.size(), 1, 0, 0);
|
renderCommand->draw((uint32)gDebugVertices.size(), 1, 0, 0);
|
||||||
graphics->executeCommands(Array{renderCommand});
|
graphics->executeCommands(Array{renderCommand});
|
||||||
graphics->endRenderPass();
|
graphics->endRenderPass();
|
||||||
|
gDebugVertices.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DebugPass::endFrame()
|
void DebugPass::endFrame()
|
||||||
@@ -80,15 +81,41 @@ void DebugPass::createRenderPass()
|
|||||||
.depthAttachment = depthAttachment,
|
.depthAttachment = depthAttachment,
|
||||||
};
|
};
|
||||||
|
|
||||||
Gfx::SubPassDependency dependency = {
|
Array<Gfx::SubPassDependency> dependency = {
|
||||||
.srcSubpass = ~0U,
|
{
|
||||||
.dstSubpass = 0,
|
.srcSubpass = ~0U,
|
||||||
.srcStage = Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
|
.dstSubpass = 0,
|
||||||
.dstStage = Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT,
|
.srcStage = Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
|
||||||
.srcAccess = Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
|
.dstStage = Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT,
|
||||||
.dstAccess = Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
|
.srcAccess = Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
|
||||||
|
.dstAccess = Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.srcSubpass = ~0U,
|
||||||
|
.dstSubpass = 0,
|
||||||
|
.srcStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
|
||||||
|
.dstStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
|
||||||
|
.srcAccess = Gfx::SE_ACCESS_NONE,
|
||||||
|
.dstAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.srcSubpass = 0,
|
||||||
|
.dstSubpass = ~0U,
|
||||||
|
.srcStage = Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT,
|
||||||
|
.dstStage = Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
|
||||||
|
.srcAccess = Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
|
||||||
|
.dstAccess = Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.srcSubpass = 0,
|
||||||
|
.dstSubpass = ~0U,
|
||||||
|
.srcStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
|
||||||
|
.dstStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
|
||||||
|
.srcAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
|
||||||
|
.dstAccess = Gfx::SE_ACCESS_NONE,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
renderPass = graphics->createRenderPass(std::move(layout), {dependency}, viewport);
|
renderPass = graphics->createRenderPass(std::move(layout), dependency, viewport);
|
||||||
|
|
||||||
Gfx::OPipelineLayout pipelineLayout = graphics->createPipelineLayout();
|
Gfx::OPipelineLayout pipelineLayout = graphics->createPipelineLayout();
|
||||||
pipelineLayout->addDescriptorLayout(0, viewParamsLayout);
|
pipelineLayout->addDescriptorLayout(0, viewParamsLayout);
|
||||||
@@ -138,5 +165,7 @@ void DebugPass::createRenderPass()
|
|||||||
gfxInfo.topology = Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_LIST;
|
gfxInfo.topology = Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_LIST;
|
||||||
gfxInfo.pipelineLayout = std::move(pipelineLayout);
|
gfxInfo.pipelineLayout = std::move(pipelineLayout);
|
||||||
gfxInfo.renderPass = renderPass;
|
gfxInfo.renderPass = renderPass;
|
||||||
|
gfxInfo.colorBlend.attachmentCount = 1;
|
||||||
|
gfxInfo.rasterizationState.lineWidth = 5.f;
|
||||||
pipeline = graphics->createGraphicsPipeline(std::move(gfxInfo));
|
pipeline = graphics->createGraphicsPipeline(std::move(gfxInfo));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ void LightCullingPass::beginFrame(const Component::Camera& cam)
|
|||||||
void LightCullingPass::render()
|
void LightCullingPass::render()
|
||||||
{
|
{
|
||||||
depthAttachment->pipelineBarrier(
|
depthAttachment->pipelineBarrier(
|
||||||
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT | Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT,
|
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
|
||||||
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
||||||
depthAttachment->transferOwnership(Gfx::QueueType::COMPUTE);
|
depthAttachment->transferOwnership(Gfx::QueueType::COMPUTE);
|
||||||
cullingDescriptorSet->updateTexture(0, depthAttachment);
|
cullingDescriptorSet->updateTexture(0, depthAttachment);
|
||||||
@@ -70,6 +70,7 @@ void LightCullingPass::render()
|
|||||||
Array<Gfx::PComputeCommand> commands = {computeCommand};
|
Array<Gfx::PComputeCommand> commands = {computeCommand};
|
||||||
//std::cout << "Execute" << std::endl;
|
//std::cout << "Execute" << std::endl;
|
||||||
graphics->executeCommands(commands);
|
graphics->executeCommands(commands);
|
||||||
|
graphics->waitDeviceIdle();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LightCullingPass::endFrame()
|
void LightCullingPass::endFrame()
|
||||||
|
|||||||
@@ -44,6 +44,43 @@ void VertexData::updateMesh(PMesh mesh, Component::Transform& transform)
|
|||||||
},
|
},
|
||||||
.data = data,
|
.data = data,
|
||||||
});
|
});
|
||||||
|
for (size_t i = 0; i < data.numMeshlets; ++i)
|
||||||
|
{
|
||||||
|
auto bounding = meshlets[data.meshletOffset + i].bounding;
|
||||||
|
StaticArray<Vector, 8> corners;
|
||||||
|
corners[0] = transform.toMatrix() * Vector4(bounding.min.x, bounding.min.y, bounding.min.z, 1);
|
||||||
|
corners[1] = transform.toMatrix() * Vector4(bounding.min.x, bounding.min.y, bounding.max.z, 1);
|
||||||
|
corners[2] = transform.toMatrix() * Vector4(bounding.min.x, bounding.max.y, bounding.min.z, 1);
|
||||||
|
corners[3] = transform.toMatrix() * Vector4(bounding.min.x, bounding.max.y, bounding.max.z, 1);
|
||||||
|
corners[4] = transform.toMatrix() * Vector4(bounding.max.x, bounding.min.y, bounding.min.z, 1);
|
||||||
|
corners[5] = transform.toMatrix() * Vector4(bounding.max.x, bounding.min.y, bounding.max.z, 1);
|
||||||
|
corners[6] = transform.toMatrix() * Vector4(bounding.max.x, bounding.max.y, bounding.min.z, 1);
|
||||||
|
corners[7] = transform.toMatrix() * Vector4(bounding.max.x, bounding.max.y, bounding.max.z, 1);
|
||||||
|
addDebugVertex(DebugVertex{ .position = corners[0], .color = meshlets[data.meshletOffset + i].color });
|
||||||
|
addDebugVertex(DebugVertex{ .position = corners[1], .color = meshlets[data.meshletOffset + i].color });
|
||||||
|
addDebugVertex(DebugVertex{ .position = corners[0], .color = meshlets[data.meshletOffset + i].color });
|
||||||
|
addDebugVertex(DebugVertex{ .position = corners[2], .color = meshlets[data.meshletOffset + i].color });
|
||||||
|
addDebugVertex(DebugVertex{ .position = corners[1], .color = meshlets[data.meshletOffset + i].color });
|
||||||
|
addDebugVertex(DebugVertex{ .position = corners[3], .color = meshlets[data.meshletOffset + i].color });
|
||||||
|
addDebugVertex(DebugVertex{ .position = corners[2], .color = meshlets[data.meshletOffset + i].color });
|
||||||
|
addDebugVertex(DebugVertex{ .position = corners[3], .color = meshlets[data.meshletOffset + i].color });
|
||||||
|
addDebugVertex(DebugVertex{ .position = corners[0], .color = meshlets[data.meshletOffset + i].color });
|
||||||
|
addDebugVertex(DebugVertex{ .position = corners[4], .color = meshlets[data.meshletOffset + i].color });
|
||||||
|
addDebugVertex(DebugVertex{ .position = corners[1], .color = meshlets[data.meshletOffset + i].color });
|
||||||
|
addDebugVertex(DebugVertex{ .position = corners[5], .color = meshlets[data.meshletOffset + i].color });
|
||||||
|
addDebugVertex(DebugVertex{ .position = corners[2], .color = meshlets[data.meshletOffset + i].color });
|
||||||
|
addDebugVertex(DebugVertex{ .position = corners[6], .color = meshlets[data.meshletOffset + i].color });
|
||||||
|
addDebugVertex(DebugVertex{ .position = corners[3], .color = meshlets[data.meshletOffset + i].color });
|
||||||
|
addDebugVertex(DebugVertex{ .position = corners[7], .color = meshlets[data.meshletOffset + i].color });
|
||||||
|
addDebugVertex(DebugVertex{ .position = corners[4], .color = meshlets[data.meshletOffset + i].color });
|
||||||
|
addDebugVertex(DebugVertex{ .position = corners[5], .color = meshlets[data.meshletOffset + i].color });
|
||||||
|
addDebugVertex(DebugVertex{ .position = corners[4], .color = meshlets[data.meshletOffset + i].color });
|
||||||
|
addDebugVertex(DebugVertex{ .position = corners[6], .color = meshlets[data.meshletOffset + i].color });
|
||||||
|
addDebugVertex(DebugVertex{ .position = corners[6], .color = meshlets[data.meshletOffset + i].color });
|
||||||
|
addDebugVertex(DebugVertex{ .position = corners[7], .color = meshlets[data.meshletOffset + i].color });
|
||||||
|
addDebugVertex(DebugVertex{ .position = corners[5], .color = meshlets[data.meshletOffset + i].color });
|
||||||
|
addDebugVertex(DebugVertex{ .position = corners[7], .color = meshlets[data.meshletOffset + i].color });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
matInstanceData.materialInstance = referencedInstance;
|
matInstanceData.materialInstance = referencedInstance;
|
||||||
referencedInstance->updateDescriptor();
|
referencedInstance->updateDescriptor();
|
||||||
@@ -127,7 +164,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{
|
||||||
.boundingBox = m.boundingBox,
|
.bounding = m.boundingBox,
|
||||||
.vertexCount = m.numVertices,
|
.vertexCount = m.numVertices,
|
||||||
.primitiveCount = m.numPrimitives,
|
.primitiveCount = m.numPrimitives,
|
||||||
.vertexOffset = vertexOffset,
|
.vertexOffset = vertexOffset,
|
||||||
@@ -136,7 +173,7 @@ void VertexData::loadMesh(MeshId id, Array<uint32> loadedIndices, Array<Meshlet>
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
meshData[id].add(MeshData{
|
meshData[id].add(MeshData{
|
||||||
.boundingBox = meshAABB,
|
.bounding = meshAABB,
|
||||||
.numMeshlets = numMeshlets,
|
.numMeshlets = numMeshlets,
|
||||||
.meshletOffset = meshletOffset,
|
.meshletOffset = meshletOffset,
|
||||||
.indicesOffset = (uint32)meshOffsets[id],
|
.indicesOffset = (uint32)meshOffsets[id],
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public:
|
|||||||
};
|
};
|
||||||
struct MeshData
|
struct MeshData
|
||||||
{
|
{
|
||||||
AABB boundingBox;
|
AABB bounding;
|
||||||
uint32 numMeshlets = 0;
|
uint32 numMeshlets = 0;
|
||||||
uint32 meshletOffset = 0;
|
uint32 meshletOffset = 0;
|
||||||
uint32 firstIndex = 0;
|
uint32 firstIndex = 0;
|
||||||
@@ -85,7 +85,7 @@ protected:
|
|||||||
VertexData();
|
VertexData();
|
||||||
struct MeshletDescription
|
struct MeshletDescription
|
||||||
{
|
{
|
||||||
AABB boundingBox;
|
AABB bounding;
|
||||||
uint32_t vertexCount;
|
uint32_t vertexCount;
|
||||||
uint32_t primitiveCount;
|
uint32_t primitiveCount;
|
||||||
uint32_t vertexOffset;
|
uint32_t vertexOffset;
|
||||||
|
|||||||
@@ -10,10 +10,6 @@ VkBool32 Seele::Vulkan::debugCallback(
|
|||||||
void* pUserData)
|
void* pUserData)
|
||||||
{
|
{
|
||||||
std::cerr << pCallbackData->pMessage << std::endl;
|
std::cerr << pCallbackData->pMessage << std::endl;
|
||||||
if ((messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) || (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT))
|
|
||||||
{
|
|
||||||
return VK_FALSE;
|
|
||||||
}
|
|
||||||
return VK_FALSE;
|
return VK_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -430,7 +430,7 @@ void Graphics::setupDebugCallback()
|
|||||||
.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT,
|
.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT,
|
||||||
.pNext = nullptr,
|
.pNext = nullptr,
|
||||||
.flags = 0,
|
.flags = 0,
|
||||||
.messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT,
|
.messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT| VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT,
|
||||||
.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT,
|
.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT,
|
||||||
.pfnUserCallback = &debugCallback,
|
.pfnUserCallback = &debugCallback,
|
||||||
.pUserData = nullptr,
|
.pUserData = nullptr,
|
||||||
|
|||||||
@@ -5,12 +5,39 @@
|
|||||||
#include "Graphics/DebugVertex.h"
|
#include "Graphics/DebugVertex.h"
|
||||||
namespace Seele
|
namespace Seele
|
||||||
{
|
{
|
||||||
|
struct BoundingSphere
|
||||||
|
{
|
||||||
|
Vector center;
|
||||||
|
float radius;
|
||||||
|
};
|
||||||
struct AABB
|
struct AABB
|
||||||
{
|
{
|
||||||
Vector min = Vector(std::numeric_limits<float>::max());
|
Vector min = Vector(std::numeric_limits<float>::max());
|
||||||
float pad0; // So that it can be used directly in shaders
|
float pad0; // So that it can be used directly in shaders
|
||||||
Vector max = Vector(std::numeric_limits<float>::lowest());// cause of reasons
|
Vector max = Vector(std::numeric_limits<float>::lowest());// cause of reasons
|
||||||
float pad1;
|
float pad1;
|
||||||
|
BoundingSphere toSphere() const
|
||||||
|
{
|
||||||
|
Vector center = (min + max) / 2.f;
|
||||||
|
StaticArray<Vector, 8> corners;
|
||||||
|
corners[0] = Vector(min.x, min.y, min.z);
|
||||||
|
corners[1] = Vector(min.x, min.y, max.z);
|
||||||
|
corners[2] = Vector(min.x, max.y, min.z);
|
||||||
|
corners[3] = Vector(min.x, max.y, max.z);
|
||||||
|
corners[4] = Vector(max.x, min.y, min.z);
|
||||||
|
corners[5] = Vector(max.x, min.y, max.z);
|
||||||
|
corners[6] = Vector(max.x, max.y, min.z);
|
||||||
|
corners[7] = Vector(max.x, max.y, max.z);
|
||||||
|
float radius = 0;
|
||||||
|
for (const auto& corner : corners)
|
||||||
|
{
|
||||||
|
radius = std::max<float>(radius, glm::length(center - corner));
|
||||||
|
}
|
||||||
|
return BoundingSphere{
|
||||||
|
.center = center,
|
||||||
|
.radius = radius,
|
||||||
|
};
|
||||||
|
}
|
||||||
void visualize(Array<DebugVertex>& vertices) const
|
void visualize(Array<DebugVertex>& vertices) const
|
||||||
{
|
{
|
||||||
StaticArray<DebugVertex, 8> corners;
|
StaticArray<DebugVertex, 8> corners;
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ GameView::GameView(Gfx::PGraphics graphics, PWindow window, const ViewportCreate
|
|||||||
, renderGraph(RenderGraphBuilder::build(
|
, renderGraph(RenderGraphBuilder::build(
|
||||||
DepthPrepass(graphics, scene),
|
DepthPrepass(graphics, scene),
|
||||||
LightCullingPass(graphics, scene),
|
LightCullingPass(graphics, scene),
|
||||||
BasePass(graphics, scene)
|
BasePass(graphics, scene),
|
||||||
//DebugPass(graphics, scene),
|
DebugPass(graphics, scene)
|
||||||
//SkyboxRenderPass(graphics, scene)
|
//SkyboxRenderPass(graphics, scene)
|
||||||
))
|
))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -35,8 +35,8 @@ protected:
|
|||||||
RenderGraph<
|
RenderGraph<
|
||||||
DepthPrepass,
|
DepthPrepass,
|
||||||
LightCullingPass,
|
LightCullingPass,
|
||||||
BasePass
|
BasePass,
|
||||||
//DebugPass,
|
DebugPass
|
||||||
//SkyboxRenderPass
|
//SkyboxRenderPass
|
||||||
> renderGraph;
|
> renderGraph;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user