diff --git a/res/shaders/MeshletBasePass.slang b/res/shaders/MeshletBasePass.slang index d71f4fa..6c6fde2 100644 --- a/res/shaders/MeshletBasePass.slang +++ b/res/shaders/MeshletBasePass.slang @@ -26,7 +26,7 @@ void taskMain( { head = 0; float3 origin = float3(0, 0, 0); - const float offset = 0.0f; + const float offset = 600.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, @@ -46,7 +46,7 @@ void taskMain( { uint m = mesh.meshletOffset + i; MeshletDescription meshlet = pScene.meshletInfos[m]; - //if(meshlet.bounding.insideFrustum(viewFrustum)) + if(meshlet.bounding.insideFrustum(viewFrustum)) { uint index; InterlockedAdd(head, 1, index); diff --git a/res/shaders/lib/BRDF.slang b/res/shaders/lib/BRDF.slang index db7b14e..88150a4 100644 --- a/res/shaders/lib/BRDF.slang +++ b/res/shaders/lib/BRDF.slang @@ -54,7 +54,7 @@ struct BlinnPhong : IBRDF float3 h = normalize(lightDir_TS + viewDir_TS); float specular = saturate(dot(normal_TS, h)); - return baseColor;//((baseColor * diffuse) + (specularColor * specular)) * lightColor; + return (baseColor * diffuse * lightColor) + (specularColor * specular) * lightColor; } float3 evaluateAmbient() @@ -169,7 +169,7 @@ struct CookTorrance : IBRDF float nDotL = max(dot(n, lightDir_TS), 0.0); float3 result = (k_d * baseColor / PI + specular) * nDotL * lightColor; - return baseColor;//result * ambientOcclusion; + return result * ambientOcclusion; } float3 evaluateAmbient() { diff --git a/res/shaders/lib/Scene.slang b/res/shaders/lib/Scene.slang index 7d98e84..6f06396 100644 --- a/res/shaders/lib/Scene.slang +++ b/res/shaders/lib/Scene.slang @@ -2,7 +2,7 @@ import Bounding; struct MeshletDescription { - AABB bounding; + BoundingSphere bounding; uint32_t vertexCount; uint32_t primitiveCount; uint32_t vertexOffset; @@ -13,7 +13,7 @@ struct MeshletDescription struct MeshData { - AABB bounding; + BoundingSphere bounding; uint32_t numMeshlets; uint32_t meshletOffset; uint32_t firstIndex; diff --git a/src/Editor/Asset/MeshLoader.cpp b/src/Editor/Asset/MeshLoader.cpp index f1f94b4..a5ef027 100644 --- a/src/Editor/Asset/MeshLoader.cpp +++ b/src/Editor/Asset/MeshLoader.cpp @@ -400,6 +400,7 @@ void MeshLoader::loadMaterials(const aiScene* scene, const Mapcreate(); diff --git a/src/Engine/Graphics/RenderPass/DebugPass.cpp b/src/Engine/Graphics/RenderPass/DebugPass.cpp index 4552ca0..ee7da1b 100644 --- a/src/Engine/Graphics/RenderPass/DebugPass.cpp +++ b/src/Engine/Graphics/RenderPass/DebugPass.cpp @@ -121,18 +121,19 @@ void DebugPass::createRenderPass() pipelineLayout = graphics->createPipelineLayout("DebugPassLayout"); pipelineLayout->addDescriptorLayout(viewParamsLayout); - pipelineLayout->create(); ShaderCreateInfo createInfo = { .name = "DebugVertex", .mainModule = "Debug", .entryPoint = "vertexMain", + .rootSignature = pipelineLayout, }; vertexShader = graphics->createVertexShader(createInfo); createInfo.name = "DebugFragment"; createInfo.entryPoint = "fragmentMain"; fragmentShader = graphics->createFragmentShader(createInfo); + pipelineLayout->create(); VertexInputStateCreateInfo inputCreate = { .bindings = { diff --git a/src/Engine/Graphics/VertexData.cpp b/src/Engine/Graphics/VertexData.cpp index a37ad3d..f455e75 100644 --- a/src/Engine/Graphics/VertexData.cpp +++ b/src/Engine/Graphics/VertexData.cpp @@ -46,43 +46,45 @@ void VertexData::updateMesh(PMesh mesh, Component::Transform& transform) }, .data = data, }); - //for (size_t i = 0; i < data.numMeshlets; ++i) - //{ - // auto bounding = meshlets[data.meshletOffset + i].bounding; - // StaticArray 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 }); - //} + for (size_t i = 0; i < data.numMeshlets; ++i) + { + auto bounding = meshlets[data.meshletOffset + i].bounding; + StaticArray corners; + Vector min = bounding.center - bounding.radius * Vector(1, 1, 1); + Vector max = bounding.center + bounding.radius * Vector(1, 1, 1); + corners[0] = transformMatrix * Vector4(min.x, min.y, min.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[3] = transformMatrix * Vector4(min.x, max.y, max.z, 1); + corners[4] = transformMatrix * Vector4(max.x, min.y, min.z, 1); + corners[5] = transformMatrix * Vector4(max.x, min.y, max.z, 1); + corners[6] = transformMatrix * Vector4(max.x, max.y, min.z, 1); + 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[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; referencedInstance->updateDescriptor(); @@ -169,7 +171,7 @@ void VertexData::loadMesh(MeshId id, Array loadedIndices, Array primitiveIndices.resize(primitiveOffset + (m.numPrimitives * 3)); std::memcpy(primitiveIndices.data() + primitiveOffset, m.primitiveLayout, m.numPrimitives * 3 * sizeof(uint8)); meshlets.add(MeshletDescription{ - .bounding = m.boundingBox,//.toSphere(), + .bounding = m.boundingBox.toSphere(), .vertexCount = m.numVertices, .primitiveCount = m.numPrimitives, .vertexOffset = vertexOffset, @@ -178,7 +180,7 @@ void VertexData::loadMesh(MeshId id, Array loadedIndices, Array }); } meshData[id].add(MeshData{ - .bounding = meshAABB,//.toSphere(), + .bounding = meshAABB.toSphere(), .numMeshlets = numMeshlets, .meshletOffset = meshletOffset, .indicesOffset = (uint32)meshOffsets[id], diff --git a/src/Engine/Graphics/VertexData.h b/src/Engine/Graphics/VertexData.h index 9bb4432..2acd2c7 100644 --- a/src/Engine/Graphics/VertexData.h +++ b/src/Engine/Graphics/VertexData.h @@ -33,7 +33,7 @@ public: }; struct MeshData { - AABB bounding; + BoundingSphere bounding; uint32 numMeshlets = 0; uint32 meshletOffset = 0; uint32 firstIndex = 0; @@ -86,7 +86,7 @@ protected: VertexData(); struct MeshletDescription { - AABB bounding; + BoundingSphere bounding; uint32_t vertexCount; uint32_t primitiveCount; uint32_t vertexOffset; diff --git a/src/Engine/Window/GameView.cpp b/src/Engine/Window/GameView.cpp index 2257cc9..757eab4 100644 --- a/src/Engine/Window/GameView.cpp +++ b/src/Engine/Window/GameView.cpp @@ -21,7 +21,7 @@ GameView::GameView(Gfx::PGraphics graphics, PWindow window, const ViewportCreate renderGraph.addPass(new DepthPrepass(graphics, scene)); renderGraph.addPass(new LightCullingPass(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.setViewport(viewport); renderGraph.createRenderPass();