Files
Seele/src/Engine/Graphics/RenderPass/SkyboxRenderPass.cpp
T

141 lines
5.5 KiB
C++
Raw Normal View History

2023-01-29 18:58:59 +01:00
#include "SkyboxRenderPass.h"
#include "Graphics/Graphics.h"
2023-10-26 18:37:29 +02:00
#include "Asset/AssetRegistry.h"
2023-11-15 17:42:57 +01:00
#include "Graphics/Command.h"
2023-01-29 18:58:59 +01:00
using namespace Seele;
2023-10-26 18:37:29 +02:00
SkyboxRenderPass::SkyboxRenderPass(Gfx::PGraphics graphics, PScene scene)
: RenderPass(graphics, scene)
2023-01-29 18:58:59 +01:00
{
2023-10-26 18:37:29 +02:00
skybox = Seele::Component::Skybox{
.day = AssetRegistry::findTexture("FS000_Day_01")->getTexture().cast<Gfx::TextureCube>(),
.night = AssetRegistry::findTexture("FS000_Night_01")->getTexture().cast<Gfx::TextureCube>(),
2024-01-02 16:48:03 +01:00
.fogColor = Vector(0.1, 0.1, 0.8),
2023-10-26 18:37:29 +02:00
.blendFactor = 0,
};
2023-01-29 18:58:59 +01:00
}
SkyboxRenderPass::~SkyboxRenderPass()
{
}
void SkyboxRenderPass::beginFrame(const Component::Camera& cam)
{
2023-11-05 10:36:01 +01:00
RenderPass::beginFrame(cam);
2023-01-29 18:58:59 +01:00
2023-11-09 22:15:51 +01:00
skyboxDataLayout->reset();
textureLayout->reset();
2024-01-02 16:48:03 +01:00
skyboxData.transformMatrix = glm::rotate(skyboxData.transformMatrix, (float)(Gfx::getCurrentFrameDelta()), Vector(0, 1, 0));
skyboxBuffer->updateContents(DataSource{
.size = sizeof(SkyboxData),
.data = (uint8*)&skyboxData,
});
2023-11-09 22:15:51 +01:00
skyboxDataSet = skyboxDataLayout->allocateDescriptorSet();
2024-01-02 16:48:03 +01:00
skyboxDataSet->updateBuffer(0, skyboxBuffer);
2023-11-09 22:15:51 +01:00
skyboxDataSet->writeChanges();
2024-01-26 23:19:18 +01:00
skyboxBuffer->pipelineBarrier(
Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_MEMORY_READ_BIT, Gfx::SE_PIPELINE_STAGE_VERTEX_SHADER_BIT
);
2023-11-09 22:15:51 +01:00
textureSet = textureLayout->allocateDescriptorSet();
textureSet->updateTexture(0, skybox.day);
textureSet->updateTexture(1, skybox.night);
textureSet->updateSampler(2, skyboxSampler);
textureSet->writeChanges();
2023-01-29 18:58:59 +01:00
}
void SkyboxRenderPass::render()
{
2024-02-01 10:21:36 +01:00
colorAttachment.getTexture()->pipelineBarrier(
2024-01-26 23:19:18 +01:00
Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Gfx::SE_ACCESS_COLOR_ATTACHMENT_READ_BIT, Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
);
2024-02-01 10:21:36 +01:00
depthAttachment.getTexture()->pipelineBarrier(
2024-01-26 23:19:18 +01:00
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT, Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
);
2023-01-29 18:58:59 +01:00
graphics->beginRenderPass(renderPass);
2024-04-11 12:38:42 +02:00
Gfx::ORenderCommand renderCommand = graphics->createRenderCommand("SkyboxRender");
2023-01-29 18:58:59 +01:00
renderCommand->setViewport(viewport);
renderCommand->bindPipeline(pipeline);
2023-11-11 13:56:12 +01:00
renderCommand->bindDescriptor({viewParamsSet, skyboxDataSet, textureSet});
2023-01-29 18:58:59 +01:00
renderCommand->draw(36, 1, 0, 0);
2024-04-11 12:38:42 +02:00
Array<Gfx::ORenderCommand> commands;
commands.add(std::move(renderCommand));
graphics->executeCommands(std::move(commands));
2023-01-29 18:58:59 +01:00
graphics->endRenderPass();
}
void SkyboxRenderPass::endFrame()
{
}
void SkyboxRenderPass::publishOutputs()
{
2024-04-19 18:23:36 +02:00
skyboxDataLayout = graphics->createDescriptorLayout("pSkyboxData");
2024-04-19 22:44:00 +02:00
skyboxDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 0, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,});
2023-11-09 22:15:51 +01:00
skyboxDataLayout->create();
2024-04-19 18:23:36 +02:00
textureLayout = graphics->createDescriptorLayout("pSkyboxTextures");
2024-04-19 22:44:00 +02:00
textureLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 0, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE,});
textureLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 1, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE,});
textureLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 2, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLER,});
2023-11-09 22:15:51 +01:00
textureLayout->create();
2023-02-01 22:13:04 +01:00
2023-11-15 17:42:57 +01:00
skyboxSampler = graphics->createSampler({});
2023-01-29 18:58:59 +01:00
}
void SkyboxRenderPass::createRenderPass()
{
2024-01-26 23:19:18 +01:00
colorAttachment = resources->requestRenderTarget("BASEPASS_COLOR");
//colorAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD;
2024-01-26 23:19:18 +01:00
depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH");
//depthAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD;
//Gfx::ORenderTargetLayout layout = new Gfx::RenderTargetLayout{
// .colorAttachments = { colorAttachment },
// .depthAttachment = depthAttachment
//};
//renderPass = graphics->createRenderPass(std::move(layout), viewport);
2023-01-29 18:58:59 +01:00
2024-01-02 16:48:03 +01:00
skyboxData.transformMatrix = Matrix4(1);
skyboxData.fogColor = skybox.fogColor;
skyboxData.blendFactor = skybox.blendFactor;
skyboxBuffer = graphics->createUniformBuffer(UniformBufferCreateInfo{
.sourceData = {
.size = sizeof(SkyboxData),
.data = (uint8*)&skyboxData,
},
.dynamic = true,
});
ShaderCreateInfo createInfo = {
.mainModule = "Skybox",
.additionalModules = {"Skybox"},
.name = "SkyboxVertex",
.entryPoint = "vertexMain",
};
2023-11-08 23:27:21 +01:00
vertexShader = graphics->createVertexShader(createInfo);
2023-01-29 18:58:59 +01:00
createInfo.name = "SkyboxFragment";
createInfo.entryPoint = "fragmentMain";
2023-11-08 23:27:21 +01:00
fragmentShader = graphics->createFragmentShader(createInfo);
2023-01-29 18:58:59 +01:00
2024-04-20 21:35:43 +02:00
pipelineLayout = graphics->createPipelineLayout("SkyboxLayout");
2024-04-19 18:23:36 +02:00
pipelineLayout->addDescriptorLayout(viewParamsLayout);
pipelineLayout->addDescriptorLayout(skyboxDataLayout);
pipelineLayout->addDescriptorLayout(textureLayout);
2023-11-09 22:15:51 +01:00
pipelineLayout->create();
2023-10-26 18:37:29 +02:00
Gfx::LegacyPipelineCreateInfo gfxInfo;
2023-01-29 18:58:59 +01:00
gfxInfo.vertexShader = vertexShader;
gfxInfo.fragmentShader = fragmentShader;
gfxInfo.rasterizationState.polygonMode = Gfx::SE_POLYGON_MODE_FILL;
gfxInfo.topology = Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
2024-04-19 18:23:36 +02:00
gfxInfo.pipelineLayout = pipelineLayout;
2023-01-29 18:58:59 +01:00
gfxInfo.renderPass = renderPass;
2023-12-10 22:27:59 +01:00
gfxInfo.multisampleState.samples = viewport->getSamples();
2023-11-09 22:15:51 +01:00
pipeline = graphics->createGraphicsPipeline(std::move(gfxInfo));
2023-01-29 18:58:59 +01:00
}