Normal mapping doesnt work

This commit is contained in:
Dynamitos
2024-05-15 15:27:13 +02:00
parent 2762f9e729
commit 7690434f2b
33 changed files with 761 additions and 661 deletions
+17 -11
View File
@@ -40,6 +40,7 @@ void DebugPass::beginFrame(const Component::Camera& cam)
},
.vertexSize = sizeof(DebugVertex),
.numVertices = (uint32)gDebugVertices.size(),
.name = "DebugVertices",
};
debugVertices = graphics->createVertexBuffer(vertexBufferInfo);
@@ -48,15 +49,18 @@ void DebugPass::beginFrame(const Component::Camera& cam)
void DebugPass::render()
{
graphics->beginRenderPass(renderPass);
Gfx::ORenderCommand renderCommand = graphics->createRenderCommand("DebugRender");
renderCommand->setViewport(viewport);
renderCommand->bindPipeline(pipeline);
renderCommand->bindDescriptor(viewParamsSet);
renderCommand->bindVertexBuffer({ debugVertices });
renderCommand->draw((uint32)gDebugVertices.size(), 1, 0, 0);
Array<Gfx::ORenderCommand> commands;
commands.add(std::move(renderCommand));
graphics->executeCommands({std::move(commands)});
if (gDebugVertices.size() > 0)
{
Gfx::ORenderCommand renderCommand = graphics->createRenderCommand("DebugRender");
renderCommand->setViewport(viewport);
renderCommand->bindPipeline(pipeline);
renderCommand->bindDescriptor(viewParamsSet);
renderCommand->bindVertexBuffer({ debugVertices });
renderCommand->draw((uint32)gDebugVertices.size(), 1, 0, 0);
Array<Gfx::ORenderCommand> commands;
commands.add(std::move(renderCommand));
graphics->executeCommands({ std::move(commands) });
}
graphics->endRenderPass();
gDebugVertices.clear();
}
@@ -75,9 +79,11 @@ void DebugPass::createRenderPass()
Gfx::RenderTargetAttachment baseColorAttachment = resources->requestRenderTarget("BASEPASS_COLOR");
baseColorAttachment.setLoadOp(Gfx::SE_ATTACHMENT_LOAD_OP_LOAD);
baseColorAttachment.setInitialLayout(Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
baseColorAttachment.setInitialLayout(Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
Gfx::RenderTargetAttachment depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH");
depthAttachment.setLoadOp(Gfx::SE_ATTACHMENT_LOAD_OP_LOAD);
depthAttachment.setInitialLayout(Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
depthAttachment.setFinalLayout(Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
Gfx::RenderTargetLayout layout = Gfx::RenderTargetLayout{
.colorAttachments = {baseColorAttachment},
.depthAttachment = depthAttachment,
@@ -97,7 +103,7 @@ void DebugPass::createRenderPass()
.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,
.srcAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
.dstAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
},
{
@@ -114,7 +120,7 @@ void DebugPass::createRenderPass()
.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,
.dstAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
},
};
renderPass = graphics->createRenderPass(std::move(layout), dependency, viewport);
@@ -13,12 +13,12 @@ LightCullingPass::LightCullingPass(Gfx::PGraphics graphics, PScene scene)
{
}
LightCullingPass::~LightCullingPass()
LightCullingPass::~LightCullingPass()
{
}
void LightCullingPass::beginFrame(const Component::Camera& cam)
void LightCullingPass::beginFrame(const Component::Camera& cam)
{
RenderPass::beginFrame(cam);
@@ -31,10 +31,12 @@ void LightCullingPass::beginFrame(const Component::Camera& cam)
Gfx::SE_ACCESS_MEMORY_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT
);
uint32 reset = 0;
DataSource counterReset = {
.size = sizeof(uint32),
.data = (uint8*)&reset,
.owner = Gfx::QueueType::COMPUTE
ShaderBufferCreateInfo counterReset = {
.sourceData = {
.size = sizeof(uint32),
.data = (uint8*)&reset,
.owner = Gfx::QueueType::COMPUTE
}
};
oLightIndexCounter->updateContents(counterReset);
tLightIndexCounter->updateContents(counterReset);
@@ -49,7 +51,7 @@ void LightCullingPass::beginFrame(const Component::Camera& cam)
cullingDescriptorSet = cullingDescriptorLayout->allocateDescriptorSet();
}
void LightCullingPass::render()
void LightCullingPass::render()
{
depthAttachment->transferOwnership(Gfx::QueueType::COMPUTE);
cullingDescriptorSet->updateTexture(0, depthAttachment);
@@ -70,11 +72,11 @@ void LightCullingPass::render()
graphics->executeCommands(std::move(commands));
}
void LightCullingPass::endFrame()
void LightCullingPass::endFrame()
{
}
void LightCullingPass::publishOutputs()
void LightCullingPass::publishOutputs()
{
setupFrustums();
uint32_t viewportWidth = viewport->getWidth();
@@ -100,22 +102,22 @@ void LightCullingPass::publishOutputs()
cullingDescriptorLayout = graphics->createDescriptorLayout("pCullingParams");
//DepthTexture
cullingDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 0, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE,});
cullingDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{ .binding = 0, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE, });
//o_lightIndexCounter
cullingDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 1, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, .access = Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT});
cullingDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{ .binding = 1, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, .access = Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT });
//t_lightIndexCounter
cullingDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 2, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, .access = Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT});
cullingDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{ .binding = 2, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, .access = Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT });
//o_lightIndexList
cullingDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 3, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, .access = Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT});
cullingDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{ .binding = 3, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, .access = Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT });
//t_lightIndexList
cullingDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 4, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, .access = Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT});
cullingDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{ .binding = 4, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, .access = Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT });
//o_lightGrid
cullingDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 5, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE, .access = Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT});
cullingDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{ .binding = 5, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE, .access = Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT });
//t_lightGrid
cullingDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 6, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE, .access = Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT});
cullingDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{ .binding = 6, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE, .access = Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT });
cullingDescriptorLayout->create();
lightEnv = scene->getLightEnvironment();
cullingLayout = graphics->createPipelineLayout("CullingLayout");
@@ -123,7 +125,7 @@ void LightCullingPass::publishOutputs()
cullingLayout->addDescriptorLayout(dispatchParamsLayout);
cullingLayout->addDescriptorLayout(cullingDescriptorLayout);
cullingLayout->addDescriptorLayout(lightEnv->getDescriptorLayout());
ShaderCreateInfo createInfo = {
.name = "Culling",
.mainModule = "LightCulling",
@@ -154,9 +156,9 @@ void LightCullingPass::publishOutputs()
tLightIndexCounter = graphics->createShaderBuffer(structInfo);
structInfo = {
.sourceData = {
.size = (uint32)sizeof(uint32)
* dispatchParams.numThreadGroups.x
* dispatchParams.numThreadGroups.y
.size = (uint32)sizeof(uint32)
* dispatchParams.numThreadGroups.x
* dispatchParams.numThreadGroups.y
* dispatchParams.numThreadGroups.z * 8192,
.data = nullptr,
.owner = Gfx::QueueType::COMPUTE
@@ -169,7 +171,7 @@ void LightCullingPass::publishOutputs()
tLightIndexList = graphics->createShaderBuffer(structInfo);
resources->registerBufferOutput("LIGHTCULLING_OLIGHTLIST", oLightIndexList);
resources->registerBufferOutput("LIGHTCULLING_TLIGHTLIST", tLightIndexList);
TextureCreateInfo textureInfo = {
.format = Gfx::SE_FORMAT_R32G32_UINT,
.width = dispatchParams.numThreadGroups.x,
@@ -178,7 +180,7 @@ void LightCullingPass::publishOutputs()
};
oLightGrid = graphics->createTexture2D(textureInfo);
tLightGrid = graphics->createTexture2D(textureInfo);
resources->registerTextureOutput("LIGHTCULLING_OLIGHTGRID", Gfx::PTexture2D(oLightGrid));
resources->registerTextureOutput("LIGHTCULLING_TLIGHTGRID", Gfx::PTexture2D(tLightGrid));
}
@@ -197,14 +199,14 @@ void LightCullingPass::setupFrustums()
glm::uvec3 numThreads = glm::ceil(glm::vec3(viewportWidth / (float)BLOCK_SIZE, viewportHeight / (float)BLOCK_SIZE, 1));
glm::uvec3 numThreadGroups = glm::ceil(glm::vec3(numThreads.x / (float)BLOCK_SIZE, numThreads.y / (float)BLOCK_SIZE, 1));
RenderPass::beginFrame(Component::Camera());
dispatchParams.numThreads = numThreads;
dispatchParams.numThreadGroups = numThreadGroups;
dispatchParamsLayout = graphics->createDescriptorLayout("pDispatchParams");
dispatchParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 0, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER, });
dispatchParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 1, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, .access = Gfx::SE_DESCRIPTOR_ACCESS_WRITE_ONLY_BIT });
dispatchParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{ .binding = 0, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER, });
dispatchParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{ .binding = 1, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, .access = Gfx::SE_DESCRIPTOR_ACCESS_WRITE_ONLY_BIT });
frustumLayout = graphics->createPipelineLayout("FrustumLayout");
frustumLayout->addDescriptorLayout(viewParamsLayout);
frustumLayout->addDescriptorLayout(dispatchParamsLayout);
@@ -224,17 +226,17 @@ void LightCullingPass::setupFrustums()
pipelineInfo.computeShader = frustumShader;
pipelineInfo.pipelineLayout = frustumLayout;
frustumPipeline = graphics->createComputePipeline(pipelineInfo);
Gfx::OUniformBuffer frustumDispatchParamsBuffer = graphics->createUniformBuffer(UniformBufferCreateInfo{
.sourceData = {
.size = sizeof(DispatchParams),
.data = (uint8*) & dispatchParams,
.data = (uint8*)&dispatchParams,
.owner = Gfx::QueueType::COMPUTE
},
.dynamic = false,
.name = "FrustumDispatch"
});
});
frustumBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
.sourceData = {
.size = sizeof(Frustum) * numThreads.x * numThreads.y * numThreads.z,
@@ -244,13 +246,13 @@ void LightCullingPass::setupFrustums()
.numElements = numThreads.x * numThreads.y * numThreads.z,
.dynamic = false,
.name = "FrustumBuffer"
});
});
Gfx::PDescriptorSet dispatchParamsSet = dispatchParamsLayout->allocateDescriptorSet();
dispatchParamsSet->updateBuffer(0, frustumDispatchParamsBuffer);
dispatchParamsSet->updateBuffer(1, frustumBuffer);
dispatchParamsSet->writeChanges();
Gfx::OComputeCommand command = graphics->createComputeCommand("FrustumCommand");
command->bindPipeline(frustumPipeline);
command->bindDescriptor({ viewParamsSet, dispatchParamsSet });
@@ -258,6 +260,6 @@ void LightCullingPass::setupFrustums()
Array<Gfx::OComputeCommand> commands;
commands.add(std::move(command));
graphics->executeCommands(std::move(commands));
frustumBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
frustumBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
}