Trying to fix mesh culling
This commit is contained in:
@@ -26,7 +26,7 @@ void taskMain(
|
|||||||
{
|
{
|
||||||
head = 0;
|
head = 0;
|
||||||
float3 origin = float3(0, 0, 0);
|
float3 origin = float3(0, 0, 0);
|
||||||
const float offset = 0.0f;
|
const float offset = 600.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,
|
||||||
@@ -46,7 +46,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.bounding.insideFrustum(viewFrustum))
|
if(meshlet.bounding.insideFrustum(viewFrustum))
|
||||||
{
|
{
|
||||||
uint index;
|
uint index;
|
||||||
InterlockedAdd(head, 1, index);
|
InterlockedAdd(head, 1, index);
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ struct BlinnPhong : IBRDF
|
|||||||
float3 h = normalize(lightDir_TS + viewDir_TS);
|
float3 h = normalize(lightDir_TS + viewDir_TS);
|
||||||
float specular = saturate(dot(normal_TS, h));
|
float specular = saturate(dot(normal_TS, h));
|
||||||
|
|
||||||
return baseColor;//((baseColor * diffuse) + (specularColor * specular)) * lightColor;
|
return (baseColor * diffuse * lightColor) + (specularColor * specular) * lightColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
float3 evaluateAmbient()
|
float3 evaluateAmbient()
|
||||||
@@ -169,7 +169,7 @@ struct CookTorrance : IBRDF
|
|||||||
float nDotL = max(dot(n, lightDir_TS), 0.0);
|
float nDotL = max(dot(n, lightDir_TS), 0.0);
|
||||||
|
|
||||||
float3 result = (k_d * baseColor / PI + specular) * nDotL * lightColor;
|
float3 result = (k_d * baseColor / PI + specular) * nDotL * lightColor;
|
||||||
return baseColor;//result * ambientOcclusion;
|
return result * ambientOcclusion;
|
||||||
}
|
}
|
||||||
float3 evaluateAmbient()
|
float3 evaluateAmbient()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import Bounding;
|
|||||||
|
|
||||||
struct MeshletDescription
|
struct MeshletDescription
|
||||||
{
|
{
|
||||||
AABB bounding;
|
BoundingSphere 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
|
||||||
{
|
{
|
||||||
AABB bounding;
|
BoundingSphere bounding;
|
||||||
uint32_t numMeshlets;
|
uint32_t numMeshlets;
|
||||||
uint32_t meshletOffset;
|
uint32_t meshletOffset;
|
||||||
uint32_t firstIndex;
|
uint32_t firstIndex;
|
||||||
|
|||||||
@@ -400,6 +400,7 @@ void MeshLoader::loadMaterials(const aiScene* scene, const Map<std::string, PTex
|
|||||||
brdf.profile = "CelShading";
|
brdf.profile = "CelShading";
|
||||||
break;
|
break;
|
||||||
case aiShadingMode_CookTorrance:
|
case aiShadingMode_CookTorrance:
|
||||||
|
default:
|
||||||
brdf.profile = "CookTorrance";
|
brdf.profile = "CookTorrance";
|
||||||
brdf.variables["roughness"] = outputRoughness;
|
brdf.variables["roughness"] = outputRoughness;
|
||||||
brdf.variables["metallic"] = outputMetallic;
|
brdf.variables["metallic"] = outputMetallic;
|
||||||
@@ -408,8 +409,6 @@ void MeshLoader::loadMaterials(const aiScene* scene, const Map<std::string, PTex
|
|||||||
brdf.variables["ambientOcclusion"] = outputAmbient;
|
brdf.variables["ambientOcclusion"] = outputAmbient;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
throw std::logic_error("Todo");
|
|
||||||
};
|
};
|
||||||
|
|
||||||
materialLayout->create();
|
materialLayout->create();
|
||||||
|
|||||||
@@ -121,18 +121,19 @@ void DebugPass::createRenderPass()
|
|||||||
|
|
||||||
pipelineLayout = graphics->createPipelineLayout("DebugPassLayout");
|
pipelineLayout = graphics->createPipelineLayout("DebugPassLayout");
|
||||||
pipelineLayout->addDescriptorLayout(viewParamsLayout);
|
pipelineLayout->addDescriptorLayout(viewParamsLayout);
|
||||||
pipelineLayout->create();
|
|
||||||
|
|
||||||
ShaderCreateInfo createInfo = {
|
ShaderCreateInfo createInfo = {
|
||||||
.name = "DebugVertex",
|
.name = "DebugVertex",
|
||||||
.mainModule = "Debug",
|
.mainModule = "Debug",
|
||||||
.entryPoint = "vertexMain",
|
.entryPoint = "vertexMain",
|
||||||
|
.rootSignature = pipelineLayout,
|
||||||
};
|
};
|
||||||
vertexShader = graphics->createVertexShader(createInfo);
|
vertexShader = graphics->createVertexShader(createInfo);
|
||||||
|
|
||||||
createInfo.name = "DebugFragment";
|
createInfo.name = "DebugFragment";
|
||||||
createInfo.entryPoint = "fragmentMain";
|
createInfo.entryPoint = "fragmentMain";
|
||||||
fragmentShader = graphics->createFragmentShader(createInfo);
|
fragmentShader = graphics->createFragmentShader(createInfo);
|
||||||
|
pipelineLayout->create();
|
||||||
|
|
||||||
VertexInputStateCreateInfo inputCreate = {
|
VertexInputStateCreateInfo inputCreate = {
|
||||||
.bindings = {
|
.bindings = {
|
||||||
|
|||||||
@@ -46,43 +46,45 @@ 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 < data.numMeshlets; ++i)
|
||||||
//{
|
{
|
||||||
// auto bounding = meshlets[data.meshletOffset + i].bounding;
|
auto bounding = meshlets[data.meshletOffset + i].bounding;
|
||||||
// StaticArray<Vector, 8> corners;
|
StaticArray<Vector, 8> corners;
|
||||||
// corners[0] = transform.toMatrix() * Vector4(bounding.min.x, bounding.min.y, bounding.min.z, 1);
|
Vector min = bounding.center - bounding.radius * Vector(1, 1, 1);
|
||||||
// corners[1] = transform.toMatrix() * Vector4(bounding.min.x, bounding.min.y, bounding.max.z, 1);
|
Vector max = bounding.center + bounding.radius * Vector(1, 1, 1);
|
||||||
// corners[2] = transform.toMatrix() * Vector4(bounding.min.x, bounding.max.y, bounding.min.z, 1);
|
corners[0] = transformMatrix * Vector4(min.x, min.y, min.z, 1);
|
||||||
// corners[3] = transform.toMatrix() * Vector4(bounding.min.x, bounding.max.y, bounding.max.z, 1);
|
corners[1] = transformMatrix * Vector4(min.x, min.y, max.z, 1);
|
||||||
// corners[4] = transform.toMatrix() * Vector4(bounding.max.x, bounding.min.y, bounding.min.z, 1);
|
corners[2] = transformMatrix * Vector4(min.x, max.y, min.z, 1);
|
||||||
// corners[5] = transform.toMatrix() * Vector4(bounding.max.x, bounding.min.y, bounding.max.z, 1);
|
corners[3] = transformMatrix * Vector4(min.x, max.y, max.z, 1);
|
||||||
// corners[6] = transform.toMatrix() * Vector4(bounding.max.x, bounding.max.y, bounding.min.z, 1);
|
corners[4] = transformMatrix * Vector4(max.x, min.y, min.z, 1);
|
||||||
// corners[7] = transform.toMatrix() * Vector4(bounding.max.x, bounding.max.y, bounding.max.z, 1);
|
corners[5] = transformMatrix * Vector4(max.x, min.y, max.z, 1);
|
||||||
// addDebugVertex(DebugVertex{ .position = corners[0], .color = meshlets[data.meshletOffset + i].color });
|
corners[6] = transformMatrix * Vector4(max.x, max.y, min.z, 1);
|
||||||
// addDebugVertex(DebugVertex{ .position = corners[1], .color = meshlets[data.meshletOffset + i].color });
|
corners[7] = transformMatrix * Vector4(max.x, max.y, max.z, 1);
|
||||||
// addDebugVertex(DebugVertex{ .position = corners[0], .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[1], .color = meshlets[data.meshletOffset + i].color });
|
addDebugVertex(DebugVertex{ .position = corners[0], .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[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[3], .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[4], .color = meshlets[data.meshletOffset + i].color });
|
addDebugVertex(DebugVertex{ .position = corners[3], .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[5], .color = meshlets[data.meshletOffset + i].color });
|
addDebugVertex(DebugVertex{ .position = corners[4], .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[6], .color = meshlets[data.meshletOffset + i].color });
|
addDebugVertex(DebugVertex{ .position = corners[5], .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[7], .color = meshlets[data.meshletOffset + i].color });
|
addDebugVertex(DebugVertex{ .position = corners[6], .color = meshlets[data.meshletOffset + i].color });
|
||||||
// addDebugVertex(DebugVertex{ .position = corners[4], .color = meshlets[data.meshletOffset + i].color });
|
addDebugVertex(DebugVertex{ .position = corners[3], .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 });
|
||||||
// addDebugVertex(DebugVertex{ .position = corners[4], .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[5], .color = meshlets[data.meshletOffset + i].color });
|
||||||
// addDebugVertex(DebugVertex{ .position = corners[6], .color = meshlets[data.meshletOffset + i].color });
|
addDebugVertex(DebugVertex{ .position = corners[4], .color = meshlets[data.meshletOffset + i].color });
|
||||||
// addDebugVertex(DebugVertex{ .position = corners[7], .color = meshlets[data.meshletOffset + i].color });
|
addDebugVertex(DebugVertex{ .position = corners[6], .color = meshlets[data.meshletOffset + i].color });
|
||||||
// addDebugVertex(DebugVertex{ .position = corners[5], .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[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();
|
||||||
@@ -169,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,
|
||||||
@@ -178,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
|
||||||
{
|
{
|
||||||
AABB bounding;
|
BoundingSphere 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
|
||||||
{
|
{
|
||||||
AABB bounding;
|
BoundingSphere 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