2020-08-06 00:54:43 +02:00
|
|
|
#include "BasePass.h"
|
|
|
|
|
#include "Graphics/Graphics.h"
|
2021-01-19 15:30:00 +01: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-01-19 15:30:00 +01:00
|
|
|
#include "Math/Vector.h"
|
2021-05-06 17:02:10 +02:00
|
|
|
#include "RenderGraph.h"
|
2023-01-21 18:43:21 +01:00
|
|
|
#include "Material/MaterialInstance.h"
|
2023-10-26 18:37:29 +02:00
|
|
|
#include "Graphics/Descriptor.h"
|
2020-08-06 00:54:43 +02:00
|
|
|
|
|
|
|
|
using namespace Seele;
|
|
|
|
|
|
2023-10-24 15:01:09 +02:00
|
|
|
BasePass::BasePass(Gfx::PGraphics graphics, PScene scene)
|
|
|
|
|
: RenderPass(graphics, scene)
|
2020-10-03 11:00:10 +02:00
|
|
|
, descriptorSets(4)
|
2020-08-06 00:54:43 +02:00
|
|
|
{
|
2020-11-03 01:18:30 +01:00
|
|
|
UniformBufferCreateInfo uniformInitializer;
|
2020-10-03 11:00:10 +02:00
|
|
|
basePassLayout = graphics->createPipelineLayout();
|
|
|
|
|
|
2021-05-06 17:02:10 +02:00
|
|
|
lightLayout = graphics->createDescriptorLayout("LightLayout");
|
2021-06-12 18:51:29 +02:00
|
|
|
|
|
|
|
|
// Directional Lights
|
2023-10-24 15:01:09 +02:00
|
|
|
lightLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
|
|
|
|
lightLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
|
|
|
|
// Point Lights
|
2021-06-12 18:51:29 +02:00
|
|
|
lightLayout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
2023-10-24 15:01:09 +02:00
|
|
|
lightLayout->addDescriptorBinding(3, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
2021-06-12 18:51:29 +02:00
|
|
|
// Light Index List
|
|
|
|
|
lightLayout->addDescriptorBinding(4, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
|
|
|
|
// Light Grid
|
|
|
|
|
lightLayout->addDescriptorBinding(5, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE);
|
2020-10-03 11:00:10 +02:00
|
|
|
lightLayout->create();
|
2021-05-06 17:02:10 +02:00
|
|
|
basePassLayout->addDescriptorLayout(INDEX_LIGHT_ENV, lightLayout);
|
2021-05-10 23:57:55 +02:00
|
|
|
descriptorSets[INDEX_LIGHT_ENV] = lightLayout->allocateDescriptorSet();
|
2020-10-03 11:00:10 +02:00
|
|
|
|
2021-05-06 17:02:10 +02:00
|
|
|
viewLayout = graphics->createDescriptorLayout("ViewLayout");
|
2020-10-03 11:00:10 +02:00
|
|
|
viewLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
2023-11-01 23:12:30 +01:00
|
|
|
uniformInitializer.sourceData.size = sizeof(ViewParameter);
|
|
|
|
|
uniformInitializer.sourceData.data = (uint8*)&viewParams;
|
2020-11-03 01:18:30 +01:00
|
|
|
uniformInitializer.bDynamic = true;
|
2020-10-03 11:00:10 +02:00
|
|
|
viewParamBuffer = graphics->createUniformBuffer(uniformInitializer);
|
|
|
|
|
viewLayout->create();
|
2021-05-06 17:02:10 +02:00
|
|
|
basePassLayout->addDescriptorLayout(INDEX_VIEW_PARAMS, viewLayout);
|
2021-05-10 23:57:55 +02:00
|
|
|
descriptorSets[INDEX_VIEW_PARAMS] = viewLayout->allocateDescriptorSet();
|
2020-10-03 11:00:10 +02:00
|
|
|
|
2023-10-24 15:01:09 +02:00
|
|
|
sceneLayout = graphics->createDescriptorLayout("SceneLayout");
|
|
|
|
|
sceneLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
|
|
|
|
sceneLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
|
|
|
|
sceneLayout->create();
|
|
|
|
|
basePassLayout->addDescriptorLayout(INDEX_SCENE_DATA, sceneLayout);
|
|
|
|
|
//basePassLayout->addPushConstants(Gfx::SePushConstantRange{
|
|
|
|
|
// .stageFlags = (Gfx::SE_SHADER_STAGE_VERTEX_BIT | Gfx::SE_SHADER_STAGE_FRAGMENT_BIT),
|
|
|
|
|
// .offset = 0,
|
|
|
|
|
// .size = sizeof(uint32),
|
|
|
|
|
//});
|
2020-08-06 00:54:43 +02:00
|
|
|
}
|
|
|
|
|
|
2020-10-03 11:00:10 +02:00
|
|
|
BasePass::~BasePass()
|
2023-10-24 15:01:09 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-17 16:47:42 +01:00
|
|
|
void BasePass::beginFrame(const Component::Camera& cam)
|
2020-10-03 11:00:10 +02:00
|
|
|
{
|
2023-11-01 23:12:30 +01:00
|
|
|
DataSource uniformUpdate;
|
2020-10-03 11:00:10 +02:00
|
|
|
|
2022-11-17 16:47:42 +01:00
|
|
|
viewParams.viewMatrix = cam.getViewMatrix();
|
2022-11-30 10:19:45 +01:00
|
|
|
viewParams.projectionMatrix = viewport->getProjectionMatrix();
|
2023-02-27 13:52:57 +01:00
|
|
|
viewParams.cameraPosition = Vector4(cam.getCameraPosition(), 1);
|
2023-01-21 18:43:21 +01:00
|
|
|
viewParams.screenDimensions = Vector2(static_cast<float>(viewport->getSizeX()), static_cast<float>(viewport->getSizeY()));
|
2020-10-03 11:00:10 +02:00
|
|
|
uniformUpdate.size = sizeof(ViewParameter);
|
|
|
|
|
uniformUpdate.data = (uint8*)&viewParams;
|
|
|
|
|
viewParamBuffer->updateContents(uniformUpdate);
|
2021-06-04 18:27:49 +02:00
|
|
|
viewLayout->reset();
|
|
|
|
|
lightLayout->reset();
|
2023-01-21 18:43:21 +01:00
|
|
|
|
2023-10-24 15:01:09 +02:00
|
|
|
descriptorSets[INDEX_SCENE_DATA] = sceneLayout->allocateDescriptorSet();
|
2023-01-21 18:43:21 +01:00
|
|
|
descriptorSets[INDEX_SCENE_DATA]->updateBuffer(0, passData.sceneDataBuffer);
|
|
|
|
|
descriptorSets[INDEX_SCENE_DATA]->writeChanges();
|
2021-06-04 18:27:49 +02:00
|
|
|
descriptorSets[INDEX_LIGHT_ENV] = lightLayout->allocateDescriptorSet();
|
|
|
|
|
descriptorSets[INDEX_VIEW_PARAMS] = viewLayout->allocateDescriptorSet();
|
2021-05-06 17:02:10 +02:00
|
|
|
descriptorSets[INDEX_VIEW_PARAMS]->updateBuffer(0, viewParamBuffer);
|
|
|
|
|
descriptorSets[INDEX_VIEW_PARAMS]->writeChanges();
|
2022-02-24 22:38:26 +01:00
|
|
|
//std::cout << "BasePass beginFrame()" << std::endl;
|
2022-04-15 23:45:44 +02:00
|
|
|
//co_return;
|
2020-10-03 11:00:10 +02:00
|
|
|
}
|
|
|
|
|
|
2022-04-15 23:45:44 +02:00
|
|
|
void BasePass::render()
|
2020-08-06 00:54:43 +02:00
|
|
|
{
|
2021-11-13 19:28:18 +01:00
|
|
|
oLightIndexList->pipelineBarrier(
|
2021-05-10 23:57:55 +02:00
|
|
|
Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
|
|
|
|
|
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
|
|
|
|
oLightGrid->pipelineBarrier(
|
|
|
|
|
Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
|
|
|
|
|
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
2021-06-04 18:27:49 +02:00
|
|
|
|
2023-03-09 17:39:57 +01:00
|
|
|
descriptorSets[INDEX_LIGHT_ENV]->updateBuffer(0, passData.lightEnv.directionalLights);
|
|
|
|
|
descriptorSets[INDEX_LIGHT_ENV]->updateBuffer(1, passData.lightEnv.numDirectional);
|
|
|
|
|
descriptorSets[INDEX_LIGHT_ENV]->updateBuffer(2, passData.lightEnv.pointLights);
|
|
|
|
|
descriptorSets[INDEX_LIGHT_ENV]->updateBuffer(3, passData.lightEnv.numPoints);
|
2021-06-12 18:51:29 +02:00
|
|
|
descriptorSets[INDEX_LIGHT_ENV]->updateBuffer(4, oLightIndexList);
|
|
|
|
|
descriptorSets[INDEX_LIGHT_ENV]->updateTexture(5, oLightGrid);
|
2021-05-10 23:57:55 +02:00
|
|
|
descriptorSets[INDEX_LIGHT_ENV]->writeChanges();
|
2023-01-21 18:43:21 +01:00
|
|
|
|
2020-08-06 00:54:43 +02:00
|
|
|
graphics->beginRenderPass(renderPass);
|
2023-02-13 14:56:13 +01:00
|
|
|
for (const auto& meshBatch : passData.staticDrawList)
|
2020-08-06 00:54:43 +02:00
|
|
|
{
|
2022-11-17 16:47:42 +01:00
|
|
|
processor->processMeshBatch(meshBatch, viewport, renderPass, basePassLayout, primitiveLayout, descriptorSets);
|
2021-11-24 12:10:23 +01:00
|
|
|
}
|
2020-08-06 00:54:43 +02:00
|
|
|
graphics->executeCommands(processor->getRenderCommands());
|
|
|
|
|
graphics->endRenderPass();
|
2022-02-24 22:38:26 +01:00
|
|
|
//std::cout << "BasePass render()" << std::endl;
|
2022-04-15 23:45:44 +02:00
|
|
|
//co_return;
|
2020-08-06 00:54:43 +02:00
|
|
|
}
|
2020-10-03 11:00:10 +02:00
|
|
|
|
2022-04-15 23:45:44 +02:00
|
|
|
void BasePass::endFrame()
|
2020-10-03 11:00:10 +02:00
|
|
|
{
|
2022-02-24 22:38:26 +01:00
|
|
|
//std::cout << "BasePass endFrame()" << std::endl;
|
2022-04-15 23:45:44 +02:00
|
|
|
//co_return;
|
2020-10-03 11:00:10 +02:00
|
|
|
}
|
2021-05-06 17:02:10 +02:00
|
|
|
|
|
|
|
|
void BasePass::publishOutputs()
|
|
|
|
|
{
|
2021-06-12 18:51:29 +02:00
|
|
|
colorAttachment = new Gfx::SwapchainAttachment(viewport->getOwner());
|
2021-10-01 19:55:04 +02:00
|
|
|
resources->registerRenderPassOutput("BASEPASS_COLOR", colorAttachment);
|
2021-05-06 17:02:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BasePass::createRenderPass()
|
2023-03-09 17:39:57 +01:00
|
|
|
{
|
2021-10-01 19:55:04 +02:00
|
|
|
Gfx::PRenderTargetAttachment depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH");
|
2021-05-06 17:02:10 +02:00
|
|
|
depthAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD;
|
2022-11-17 16:47:42 +01:00
|
|
|
colorAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR;
|
|
|
|
|
colorAttachment->storeOp = Gfx::SE_ATTACHMENT_STORE_OP_STORE;
|
2021-05-06 17:02:10 +02:00
|
|
|
Gfx::PRenderTargetLayout layout = new Gfx::RenderTargetLayout(colorAttachment, depthAttachment);
|
2021-09-23 10:10:39 +02:00
|
|
|
renderPass = graphics->createRenderPass(layout, viewport);
|
2021-10-01 19:55:04 +02:00
|
|
|
oLightIndexList = resources->requestBuffer("LIGHTCULLING_OLIGHTLIST");
|
|
|
|
|
oLightGrid = resources->requestTexture("LIGHTCULLING_OLIGHTGRID");
|
2021-05-06 17:02:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BasePass::modifyRenderPassMacros(Map<const char*, const char*>& defines)
|
|
|
|
|
{
|
|
|
|
|
defines["INDEX_LIGHT_ENV"] = "0";
|
|
|
|
|
defines["INDEX_VIEW_PARAMS"] = "1";
|
|
|
|
|
defines["INDEX_MATERIAL"] = "2";
|
|
|
|
|
defines["INDEX_SCENE_DATA"] = "3";
|
|
|
|
|
}
|