2021-05-06 17:02:10 +02:00
|
|
|
#include "DepthPrepass.h"
|
2023-11-06 22:24:40 +01:00
|
|
|
#include "Graphics/Enums.h"
|
2021-05-06 17:02:10 +02:00
|
|
|
#include "Graphics/Graphics.h"
|
2023-11-05 10:36:01 +01:00
|
|
|
#include "Graphics/Shader.h"
|
2021-05-06 17:02:10 +02:00
|
|
|
#include "Window/Window.h"
|
2022-11-17 16:47:42 +01:00
|
|
|
#include "Component/Camera.h"
|
2023-10-24 15:01:09 +02:00
|
|
|
#include "Component/Mesh.h"
|
2022-11-17 16:47:42 +01:00
|
|
|
#include "Actor/CameraActor.h"
|
2021-05-06 17:02:10 +02:00
|
|
|
#include "Math/Vector.h"
|
|
|
|
|
#include "RenderGraph.h"
|
2023-11-15 17:42:57 +01:00
|
|
|
#include "Graphics/Command.h"
|
2024-05-08 10:51:59 +02:00
|
|
|
#include "Graphics/StaticMeshVertexData.h"
|
2021-05-06 17:02:10 +02:00
|
|
|
|
|
|
|
|
using namespace Seele;
|
|
|
|
|
|
2023-10-24 15:01:09 +02:00
|
|
|
DepthPrepass::DepthPrepass(Gfx::PGraphics graphics, PScene scene)
|
|
|
|
|
: RenderPass(graphics, scene)
|
2021-05-06 17:02:10 +02:00
|
|
|
{
|
2024-04-20 21:35:43 +02:00
|
|
|
depthPrepassLayout = graphics->createPipelineLayout("DepthPrepassLayout");
|
2024-04-19 18:23:36 +02:00
|
|
|
depthPrepassLayout->addDescriptorLayout(viewParamsLayout);
|
2023-11-22 13:18:54 +01:00
|
|
|
if (graphics->supportMeshShading())
|
|
|
|
|
{
|
2024-05-08 10:51:59 +02:00
|
|
|
graphics->getShaderCompiler()->registerRenderPass(depthPrepassLayout, "DepthPass", "MeshletPass", false, false, "", true, true, "MeshletPass");
|
2023-11-22 13:18:54 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-05-08 10:51:59 +02:00
|
|
|
graphics->getShaderCompiler()->registerRenderPass(depthPrepassLayout, "DepthPass", "LegacyPass");
|
2023-11-22 13:18:54 +01:00
|
|
|
}
|
2021-05-06 17:02:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DepthPrepass::~DepthPrepass()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-17 16:47:42 +01:00
|
|
|
void DepthPrepass::beginFrame(const Component::Camera& cam)
|
2021-05-06 17:02:10 +02:00
|
|
|
{
|
2023-11-05 10:36:01 +01:00
|
|
|
RenderPass::beginFrame(cam);
|
2021-05-06 17:02:10 +02:00
|
|
|
}
|
|
|
|
|
|
2022-04-15 23:45:44 +02:00
|
|
|
void DepthPrepass::render()
|
2021-05-06 17:02:10 +02:00
|
|
|
{
|
|
|
|
|
graphics->beginRenderPass(renderPass);
|
2024-04-10 10:23:06 +02:00
|
|
|
Array<Gfx::ORenderCommand> commands;
|
2024-05-08 10:51:59 +02:00
|
|
|
|
|
|
|
|
// Others
|
2021-05-06 17:02:10 +02:00
|
|
|
{
|
2024-05-08 10:51:59 +02:00
|
|
|
Gfx::ShaderPermutation permutation;
|
|
|
|
|
if (graphics->supportMeshShading())
|
2023-10-24 15:01:09 +02:00
|
|
|
{
|
2024-05-08 10:51:59 +02:00
|
|
|
permutation.setTaskFile("MeshletPass");
|
|
|
|
|
permutation.setMeshFile("MeshletPass");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
permutation.setVertexFile("LegacyPass");
|
|
|
|
|
}
|
|
|
|
|
for (VertexData* vertexData : VertexData::getList())
|
|
|
|
|
{
|
|
|
|
|
permutation.setVertexData(vertexData->getTypeName());
|
|
|
|
|
const auto& materials = vertexData->getMaterialData();
|
|
|
|
|
for (const auto& [_, materialData] : materials)
|
2023-11-06 22:24:40 +01:00
|
|
|
{
|
2024-05-08 10:51:59 +02:00
|
|
|
// Create Pipeline(VertexData)
|
|
|
|
|
// Descriptors:
|
|
|
|
|
// ViewData => global, static
|
|
|
|
|
// VertexData => per meshtype
|
|
|
|
|
// SceneData => per material instance
|
|
|
|
|
permutation.setMaterial(materialData.material->getName());
|
|
|
|
|
Gfx::PermutationId id(permutation);
|
2023-10-24 15:01:09 +02:00
|
|
|
|
2024-05-08 10:51:59 +02:00
|
|
|
Gfx::ORenderCommand command = graphics->createRenderCommand("BaseRender");
|
|
|
|
|
command->setViewport(viewport);
|
|
|
|
|
|
|
|
|
|
const Gfx::ShaderCollection* collection = graphics->getShaderCompiler()->findShaders(id);
|
|
|
|
|
assert(collection != nullptr);
|
2023-11-26 11:27:39 +01:00
|
|
|
if (graphics->supportMeshShading())
|
2023-11-06 22:24:40 +01:00
|
|
|
{
|
2024-05-08 10:51:59 +02:00
|
|
|
Gfx::MeshPipelineCreateInfo pipelineInfo;
|
|
|
|
|
pipelineInfo.taskShader = collection->taskShader;
|
|
|
|
|
pipelineInfo.meshShader = collection->meshShader;
|
|
|
|
|
pipelineInfo.fragmentShader = collection->fragmentShader;
|
|
|
|
|
pipelineInfo.pipelineLayout = collection->pipelineLayout;
|
|
|
|
|
pipelineInfo.renderPass = renderPass;
|
|
|
|
|
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_GREATER;
|
|
|
|
|
pipelineInfo.multisampleState.samples = viewport->getSamples();
|
|
|
|
|
pipelineInfo.colorBlend.attachmentCount = 1;
|
|
|
|
|
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
|
|
|
|
|
command->bindPipeline(pipeline);
|
2023-11-06 22:24:40 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-05-08 10:51:59 +02:00
|
|
|
Gfx::LegacyPipelineCreateInfo pipelineInfo;
|
|
|
|
|
pipelineInfo.vertexShader = collection->vertexShader;
|
|
|
|
|
pipelineInfo.fragmentShader = collection->fragmentShader;
|
|
|
|
|
pipelineInfo.pipelineLayout = collection->pipelineLayout;
|
|
|
|
|
pipelineInfo.renderPass = renderPass;
|
|
|
|
|
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_GREATER;
|
|
|
|
|
pipelineInfo.multisampleState.samples = viewport->getSamples();
|
|
|
|
|
pipelineInfo.colorBlend.attachmentCount = 1;
|
|
|
|
|
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
|
|
|
|
|
command->bindPipeline(pipeline);
|
|
|
|
|
}
|
|
|
|
|
command->bindDescriptor(vertexData->getVertexDataSet());
|
|
|
|
|
command->bindDescriptor(viewParamsSet);
|
|
|
|
|
for (const auto& [_, instance] : materialData.instances)
|
|
|
|
|
{
|
|
|
|
|
command->bindDescriptor(vertexData->getInstanceDataSet(), { instance.descriptorOffset, instance.descriptorOffset });
|
|
|
|
|
if (graphics->supportMeshShading())
|
2023-11-06 22:24:40 +01:00
|
|
|
{
|
2024-05-08 10:51:59 +02:00
|
|
|
command->drawMesh(vertexData->getMeshData(instance.meshId).size(), 1, 1);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
command->bindIndexBuffer(vertexData->getIndexBuffer());
|
|
|
|
|
uint32 instanceOffset = 0;
|
|
|
|
|
for (const auto& meshData : vertexData->getMeshData(instance.meshId))
|
2023-11-09 22:15:51 +01:00
|
|
|
{
|
2024-05-08 10:51:59 +02:00
|
|
|
if (meshData.numIndices > 0)
|
|
|
|
|
{
|
|
|
|
|
command->drawIndexed(meshData.numIndices, 1, meshData.firstIndex, meshData.indicesOffset, instanceOffset);
|
|
|
|
|
}
|
|
|
|
|
instanceOffset++;
|
2023-11-09 22:15:51 +01:00
|
|
|
}
|
2023-11-06 22:24:40 +01:00
|
|
|
}
|
|
|
|
|
}
|
2024-05-08 10:51:59 +02:00
|
|
|
commands.add(std::move(command));
|
2023-10-24 15:01:09 +02:00
|
|
|
}
|
|
|
|
|
}
|
2021-11-24 12:10:23 +01:00
|
|
|
}
|
2024-05-08 10:51:59 +02:00
|
|
|
|
2024-04-10 10:23:06 +02:00
|
|
|
graphics->executeCommands(std::move(commands));
|
2021-05-06 17:02:10 +02:00
|
|
|
graphics->endRenderPass();
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-15 23:45:44 +02:00
|
|
|
void DepthPrepass::endFrame()
|
2021-05-06 17:02:10 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DepthPrepass::publishOutputs()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DepthPrepass::createRenderPass()
|
|
|
|
|
{
|
|
|
|
|
}
|