2026-04-12 20:49:02 +02:00
|
|
|
#include "FluidRenderPass.h"
|
|
|
|
|
#include "Component/Transform.h"
|
|
|
|
|
#include "Graphics/Command.h"
|
2026-04-15 16:56:19 +02:00
|
|
|
#include "Graphics/Descriptor.h"
|
2026-04-12 20:49:02 +02:00
|
|
|
#include "Graphics/Enums.h"
|
|
|
|
|
#include "Graphics/Graphics.h"
|
|
|
|
|
#include "Graphics/Initializer.h"
|
|
|
|
|
#include "Graphics/RenderTarget.h"
|
|
|
|
|
#include "Graphics/Shader.h"
|
2026-04-15 16:56:19 +02:00
|
|
|
#include "Math/Matrix.h"
|
2026-04-12 20:49:02 +02:00
|
|
|
#include "Scene/LightEnvironment.h"
|
|
|
|
|
#include "Scene/Scene.h"
|
2026-04-15 16:56:19 +02:00
|
|
|
#include "Scene/FluidScene.h"
|
2026-04-12 20:49:02 +02:00
|
|
|
|
|
|
|
|
using namespace Seele;
|
|
|
|
|
|
|
|
|
|
FluidRenderPass::FluidRenderPass(Gfx::PGraphics graphics, PScene scene) : RenderPass(graphics), scene(scene) {
|
|
|
|
|
pipelineLayout = graphics->createPipelineLayout("FluidPipelineLayout");
|
|
|
|
|
descriptorLayout = graphics->createDescriptorLayout("params");
|
2026-04-15 16:56:19 +02:00
|
|
|
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
|
|
|
|
.name = "transform",
|
|
|
|
|
.uniformLength = sizeof(Matrix4),
|
|
|
|
|
});
|
2026-04-12 20:49:02 +02:00
|
|
|
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
|
|
|
|
.name = "vertexBuffer",
|
|
|
|
|
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
|
|
|
|
});
|
|
|
|
|
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
|
|
|
|
.name = "normalBuffer",
|
|
|
|
|
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
|
|
|
|
});
|
|
|
|
|
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
|
|
|
|
.name = "indexBuffer",
|
|
|
|
|
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
|
|
|
|
});
|
|
|
|
|
descriptorLayout->create();
|
|
|
|
|
pipelineLayout->addDescriptorLayout(viewParamsLayout);
|
|
|
|
|
pipelineLayout->addDescriptorLayout(descriptorLayout);
|
|
|
|
|
pipelineLayout->addDescriptorLayout(scene->getLightEnvironment()->getDescriptorLayout());
|
|
|
|
|
|
|
|
|
|
graphics->beginShaderCompilation(ShaderCompilationInfo{
|
|
|
|
|
.name = "Fluid",
|
|
|
|
|
.modules = {"Render"},
|
|
|
|
|
.entryPoints = {{"vertexMain", "Render"}, {"fragmentMain", "Render"}},
|
|
|
|
|
.rootSignature = pipelineLayout,
|
|
|
|
|
});
|
|
|
|
|
pipelineLayout->create();
|
|
|
|
|
vertexShader = graphics->createVertexShader({0});
|
|
|
|
|
fragmentShader = graphics->createFragmentShader({1});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FluidRenderPass::~FluidRenderPass() {}
|
|
|
|
|
|
|
|
|
|
void FluidRenderPass::beginFrame(const Seele::Component::Camera& camera, const Seele::Component::Transform& transform) {
|
|
|
|
|
updateViewParameters(camera, transform);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FluidRenderPass::render() {
|
|
|
|
|
viewParamsSet = createViewParamsSet();
|
|
|
|
|
graphics->beginRenderPass(renderPass);
|
|
|
|
|
descriptorLayout->reset();
|
|
|
|
|
for (const auto& [id, data] : scene->getFluidScene()->getFluidDataMap()) {
|
|
|
|
|
descriptorSet = descriptorLayout->allocateDescriptorSet();
|
2026-04-15 16:56:19 +02:00
|
|
|
Matrix4 transformMatrix = data.transform.toMatrix();
|
|
|
|
|
descriptorSet->updateConstants("transform", 0, &transformMatrix);
|
2026-04-12 20:49:02 +02:00
|
|
|
descriptorSet->updateBuffer("vertexBuffer", 0, data.vertexBuffer);
|
|
|
|
|
descriptorSet->updateBuffer("normalBuffer", 0, data.normalBuffer);
|
|
|
|
|
descriptorSet->updateBuffer("indexBuffer", 0, data.indexBuffer);
|
|
|
|
|
descriptorSet->writeChanges();
|
|
|
|
|
Gfx::ORenderCommand renderCommand = graphics->createRenderCommand();
|
|
|
|
|
renderCommand->setViewport(viewport);
|
|
|
|
|
renderCommand->bindPipeline(pipeline);
|
|
|
|
|
renderCommand->bindDescriptor(viewParamsSet);
|
|
|
|
|
renderCommand->bindDescriptor(descriptorSet);
|
|
|
|
|
renderCommand->bindDescriptor(scene->getLightEnvironment()->getDescriptorSet());
|
|
|
|
|
renderCommand->drawIndirect(data.surfaceCountBuffer, 0, 1, 0);
|
|
|
|
|
graphics->executeCommands(std::move(renderCommand));
|
|
|
|
|
}
|
|
|
|
|
graphics->endRenderPass();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FluidRenderPass::endFrame() {}
|
|
|
|
|
|
|
|
|
|
void FluidRenderPass::publishOutputs() {
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-15 16:56:19 +02:00
|
|
|
|
2026-04-12 20:49:02 +02:00
|
|
|
void FluidRenderPass::createRenderPass() {
|
2026-04-12 21:39:31 +02:00
|
|
|
colorAttachment = resources->requestRenderTarget("BASEPASS_COLOR");
|
|
|
|
|
colorAttachment.setLoadOp(Gfx::SE_ATTACHMENT_LOAD_OP_LOAD);
|
|
|
|
|
colorAttachment.setInitialLayout(Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
|
|
|
|
|
depthAttachment = resources->requestRenderTarget("BASEPASS_DEPTH");
|
|
|
|
|
depthAttachment.setLoadOp(Gfx::SE_ATTACHMENT_LOAD_OP_LOAD);
|
|
|
|
|
depthAttachment.setInitialLayout(Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
|
2026-04-12 20:49:02 +02:00
|
|
|
Gfx::RenderTargetLayout layout = Gfx::RenderTargetLayout{
|
|
|
|
|
.colorAttachments = {colorAttachment},
|
|
|
|
|
.depthAttachment = depthAttachment,
|
|
|
|
|
};
|
|
|
|
|
Array<Gfx::SubPassDependency> dependency = {
|
|
|
|
|
{
|
|
|
|
|
.srcSubpass = ~0U,
|
|
|
|
|
.dstSubpass = 0,
|
|
|
|
|
.srcStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT |
|
|
|
|
|
Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
|
|
|
|
|
.dstStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT |
|
|
|
|
|
Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
|
|
|
|
|
.srcAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
|
|
|
|
|
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
|
|
|
|
|
.dstAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
|
|
|
|
|
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
.srcSubpass = 0,
|
|
|
|
|
.dstSubpass = ~0U,
|
|
|
|
|
.srcStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT |
|
|
|
|
|
Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
|
|
|
|
|
.dstStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT |
|
|
|
|
|
Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
|
|
|
|
|
.srcAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
|
|
|
|
|
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
|
|
|
|
|
.dstAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
|
|
|
|
|
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
|
|
|
|
|
},
|
|
|
|
|
};
|
2026-04-15 16:56:19 +02:00
|
|
|
|
2026-04-12 20:49:02 +02:00
|
|
|
renderPass = graphics->createRenderPass(layout, dependency, viewport->getRenderArea(), "FluidRenderPass");
|
|
|
|
|
pipeline = graphics->createGraphicsPipeline(Gfx::LegacyPipelineCreateInfo{
|
|
|
|
|
.vertexShader = vertexShader,
|
|
|
|
|
.fragmentShader = fragmentShader,
|
|
|
|
|
.renderPass = renderPass,
|
|
|
|
|
.pipelineLayout = pipelineLayout,
|
|
|
|
|
.multisampleState =
|
|
|
|
|
{
|
|
|
|
|
.samples = Gfx::SE_SAMPLE_COUNT_1_BIT,
|
|
|
|
|
},
|
|
|
|
|
.rasterizationState =
|
|
|
|
|
{
|
2026-04-15 16:56:19 +02:00
|
|
|
.cullMode = Gfx::SE_CULL_MODE_NONE,
|
2026-04-12 20:49:02 +02:00
|
|
|
},
|
|
|
|
|
.colorBlend =
|
|
|
|
|
{
|
|
|
|
|
.attachmentCount = 1,
|
|
|
|
|
.blendAttachments =
|
|
|
|
|
{
|
|
|
|
|
Gfx::ColorBlendState::BlendAttachment{
|
|
|
|
|
.blendEnable = true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|