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

113 lines
4.3 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>(),
.fogColor = Vector(0.2, 0.1, 0.6),
.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-11-01 23:12:30 +01:00
DataSource uniformUpdate;
2023-01-29 18:58:59 +01:00
2023-11-09 22:15:51 +01:00
skyboxDataLayout->reset();
textureLayout->reset();
skyboxDataSet = skyboxDataLayout->allocateDescriptorSet();
skyboxDataSet->updateBuffer(0, viewParamsBuffer);
skyboxDataSet->writeChanges();
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()
{
graphics->beginRenderPass(renderPass);
Gfx::PRenderCommand renderCommand = graphics->createRenderCommand("SkyboxRender");
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);
graphics->executeCommands(Array{ renderCommand });
graphics->endRenderPass();
2023-12-10 22:27:59 +01:00
baseColorAttachment->getTexture()->changeLayout(Gfx::SE_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
graphics->resolveTexture(baseColorAttachment->getTexture(), viewport->getOwner()->getBackBuffer());
2023-01-29 18:58:59 +01:00
}
void SkyboxRenderPass::endFrame()
{
}
void SkyboxRenderPass::publishOutputs()
{
2023-11-09 22:15:51 +01:00
skyboxDataLayout = graphics->createDescriptorLayout("SkyboxDescLayout");
skyboxDataLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
skyboxDataLayout->create();
textureLayout = graphics->createDescriptorLayout();
2023-11-11 13:56:12 +01:00
textureLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE);
2023-11-09 22:15:51 +01:00
textureLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE);
2023-11-11 13:56:12 +01:00
textureLayout->addDescriptorBinding(2, 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()
{
2023-12-10 22:27:59 +01:00
baseColorAttachment = resources->requestRenderTarget("BASEPASS_COLOR");
2023-01-29 18:58:59 +01:00
baseColorAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD;
Gfx::PRenderTargetAttachment depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH");
depthAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD;
2023-12-10 22:27:59 +01:00
Gfx::ORenderTargetLayout layout = new Gfx::RenderTargetLayout{
.colorAttachments = { baseColorAttachment },
.depthAttachment = depthAttachment
};
2023-11-05 10:36:01 +01:00
renderPass = graphics->createRenderPass(std::move(layout), viewport);
2023-01-29 18:58:59 +01:00
ShaderCreateInfo createInfo;
createInfo.name = "SkyboxVertex";
2023-11-11 13:56:12 +01:00
createInfo.additionalModules.add("Skybox");
2023-01-29 18:58:59 +01:00
createInfo.mainModule = "Skybox";
createInfo.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
2023-11-09 22:15:51 +01:00
Gfx::OPipelineLayout pipelineLayout = graphics->createPipelineLayout();
2023-11-11 13:56:12 +01:00
pipelineLayout->addDescriptorLayout(0, viewParamsLayout);
pipelineLayout->addDescriptorLayout(1, skyboxDataLayout);
pipelineLayout->addDescriptorLayout(2, 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.rasterizationState.lineWidth = 5.f;
gfxInfo.topology = Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
2023-11-09 22:15:51 +01:00
gfxInfo.pipelineLayout = std::move(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
}