Basic UI quad, yay

This commit is contained in:
Dynamitos
2021-09-23 10:10:39 +02:00
parent df977110d3
commit 632d120f6d
51 changed files with 579 additions and 187 deletions
+2 -4
View File
@@ -80,11 +80,9 @@ void BasePassMeshProcessor::clearCommands()
}
BasePass::BasePass(PRenderGraph renderGraph, const PScene scene, Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source)
: RenderPass(renderGraph)
: RenderPass(renderGraph, graphics, viewport)
, processor(new BasePassMeshProcessor(scene, viewport, graphics, false))
, scene(scene)
, graphics(graphics)
, viewport(viewport)
, descriptorSets(4)
, source(source->getCameraComponent())
{
@@ -198,7 +196,7 @@ void BasePass::createRenderPass()
Gfx::PRenderTargetAttachment depthAttachment = renderGraph->requestRenderTarget("DEPTHPREPASS_DEPTH");
depthAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD;
Gfx::PRenderTargetLayout layout = new Gfx::RenderTargetLayout(colorAttachment, depthAttachment);
renderPass = graphics->createRenderPass(layout);
renderPass = graphics->createRenderPass(layout, viewport);
oLightIndexList = renderGraph->requestBuffer("LIGHTCULLING_OLIGHTLIST");
oLightGrid = renderGraph->requestTexture("LIGHTCULLING_OLIGHTGRID");
}
+1 -2
View File
@@ -46,9 +46,8 @@ private:
Gfx::PRenderTargetAttachment colorAttachment;
Gfx::PTexture2D depthBuffer;
UPBasePassMeshProcessor processor;
const PScene scene;
Gfx::PGraphics graphics;
Gfx::PViewport viewport;
Array<Gfx::PDescriptorSet> descriptorSets;
PCameraComponent source;
Gfx::PPipelineLayout basePassLayout;
@@ -11,4 +11,6 @@ target_sources(SeeleEngine
RenderGraph.h
RenderGraph.cpp
RenderPass.h
RenderPass.cpp)
RenderPass.cpp
UIPass.h
UIPass.cpp)
@@ -79,11 +79,9 @@ void DepthPrepassMeshProcessor::clearCommands()
}
DepthPrepass::DepthPrepass(PRenderGraph renderGraph, const PScene scene, Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source)
: RenderPass(renderGraph)
: RenderPass(renderGraph, graphics, viewport)
, processor(new DepthPrepassMeshProcessor(scene, viewport, graphics))
, scene(scene)
, graphics(graphics)
, viewport(viewport)
, descriptorSets(3)
, source(source->getCameraComponent())
{
@@ -156,8 +154,10 @@ void DepthPrepass::endFrame()
void DepthPrepass::publishOutputs()
{
TextureCreateInfo depthBufferInfo;
depthBufferInfo.width = viewport->getSizeX();
depthBufferInfo.height = viewport->getSizeY();
// If we render to a part of an image, the depth buffer itself must
// still match the size of the whole image or their coordinate systems go out of sync
depthBufferInfo.width = viewport->getOwner()->getSizeX();
depthBufferInfo.height = viewport->getOwner()->getSizeY();
depthBufferInfo.format = Gfx::SE_FORMAT_D32_SFLOAT;
depthBufferInfo.usage = Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
depthBuffer = graphics->createTexture2D(depthBufferInfo);
@@ -170,7 +170,7 @@ void DepthPrepass::publishOutputs()
void DepthPrepass::createRenderPass()
{
Gfx::PRenderTargetLayout layout = new Gfx::RenderTargetLayout(depthAttachment);
renderPass = graphics->createRenderPass(layout);
renderPass = graphics->createRenderPass(layout, viewport);
}
void DepthPrepass::modifyRenderPassMacros(Map<const char*, const char*>& defines)
@@ -46,8 +46,7 @@ private:
Gfx::PTexture2D depthBuffer;
UPDepthPrepassMeshProcessor processor;
const PScene scene;
Gfx::PGraphics graphics;
Gfx::PViewport viewport;
Array<Gfx::PDescriptorSet> descriptorSets;
PCameraComponent source;
Gfx::PPipelineLayout depthPrepassLayout;
@@ -8,10 +8,8 @@
using namespace Seele;
LightCullingPass::LightCullingPass(PRenderGraph renderGraph, const PScene scene, Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor camera)
: RenderPass(renderGraph)
: RenderPass(renderGraph, graphics, viewport)
, scene(scene)
, viewport(viewport)
, graphics(graphics)
, source(camera->getCameraComponent())
{
}
@@ -44,9 +44,7 @@ private:
};
PScene scene;
Gfx::PViewport viewport;
Gfx::PGraphics graphics;
Gfx::PStructuredBuffer frustumBuffer;
Gfx::PUniformBuffer dispatchParamsBuffer;
Gfx::PUniformBuffer viewParamsBuffer;
@@ -2,8 +2,8 @@
using namespace Seele;
RenderPass::RenderPass(PRenderGraph renderGraph)
: renderGraph(renderGraph)
RenderPass::RenderPass(PRenderGraph renderGraph, Gfx::PGraphics graphics, Gfx::PViewport viewport)
: renderGraph(renderGraph), graphics(graphics), viewport(viewport)
{
}
+5 -1
View File
@@ -4,12 +4,14 @@
namespace Seele
{
DECLARE_NAME_REF(Gfx, Viewport)
DECLARE_NAME_REF(Gfx, Graphics)
DECLARE_NAME_REF(Gfx, RenderPass)
DECLARE_REF(RenderGraph)
class RenderPass
{
public:
RenderPass(PRenderGraph rendergraph);
RenderPass(PRenderGraph rendergraph, Gfx::PGraphics graphics, Gfx::PViewport viewport);
virtual ~RenderPass();
virtual void beginFrame() = 0;
virtual void render() = 0;
@@ -27,6 +29,8 @@ protected:
} viewParams;
Gfx::PRenderPass renderPass;
PRenderGraph renderGraph;
Gfx::PGraphics graphics;
Gfx::PViewport viewport;
};
DEFINE_REF(RenderPass)
} // namespace Seele
+91
View File
@@ -0,0 +1,91 @@
#include "UIPass.h"
#include "RenderGraph.h"
#include "Graphics/Graphics.h"
using namespace Seele;
UIPass::UIPass(PRenderGraph renderGraph, Gfx::PGraphics graphics, Gfx::PViewport viewport, Gfx::PRenderTargetAttachment attachment)
: RenderPass(renderGraph, graphics, viewport)
, renderTarget(attachment)
{
}
UIPass::~UIPass()
{
}
void UIPass::beginFrame()
{
}
void UIPass::render()
{
graphics->beginRenderPass(renderPass);
Gfx::PRenderCommand command = graphics->createRenderCommand("UIPassCommand");
command->setViewport(viewport);
command->bindPipeline(pipeline);
command->draw(4, 1, 0, 0);
graphics->executeCommands(Array<Gfx::PRenderCommand>({command}));
graphics->endRenderPass();
}
void UIPass::endFrame()
{
}
void UIPass::publishOutputs()
{
TextureCreateInfo depthBufferInfo;
// Even if we only render to part of an image, we need to make sure
// that the depthbuffer is the same size or they can't be used in the same
// framebuffer
depthBufferInfo.width = viewport->getOwner()->getSizeX();
depthBufferInfo.height = viewport->getOwner()->getSizeY();
depthBufferInfo.format = Gfx::SE_FORMAT_D32_SFLOAT;
depthBufferInfo.usage = Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
depthBuffer = graphics->createTexture2D(depthBufferInfo);
depthAttachment =
new Gfx::RenderTargetAttachment(depthBuffer, Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
depthAttachment->clear.depthStencil.depth = 1.0f;
renderGraph->registerRenderPassOutput("UIPASS_DEPTH", depthAttachment);
}
void UIPass::createRenderPass()
{
std::ifstream codeStream("./shaders/UIPass.slang", std::ios::ate);
auto fileSize = codeStream.tellg();
codeStream.seekg(0);
Array<char> buffer(static_cast<uint32>(fileSize));
codeStream.read(buffer.data(), fileSize);
ShaderCreateInfo createInfo;
createInfo.shaderCode.add(std::string(buffer.data()));
createInfo.name = "UIVertex";
createInfo.entryPoint = "vertexMain";
vertexShader = graphics->createVertexShader(createInfo);
createInfo.name = "UIFragment";
createInfo.entryPoint = "fragmentMain";
fragmentShader = graphics->createFragmentShader(createInfo);
declaration = graphics->createVertexDeclaration({});
pipelineLayout = graphics->createPipelineLayout();
pipelineLayout->create();
Gfx::PRenderTargetLayout layout = new Gfx::RenderTargetLayout(renderTarget, depthAttachment);
renderPass = graphics->createRenderPass(layout, viewport);
GraphicsPipelineCreateInfo pipelineInfo;
pipelineInfo.vertexDeclaration = declaration;
pipelineInfo.vertexShader = vertexShader;
pipelineInfo.fragmentShader = fragmentShader;
pipelineInfo.renderPass = renderPass;
pipelineInfo.pipelineLayout = pipelineLayout;
pipelineInfo.rasterizationState.cullMode = Gfx::SE_CULL_MODE_NONE;
pipelineInfo.topology = Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
pipeline = graphics->createGraphicsPipeline(pipelineInfo);
}
+33
View File
@@ -0,0 +1,33 @@
#pragma once
#include "RenderPass.h"
#include "UI/RenderHierarchy.h"
#include "Graphics/GraphicsResources.h"
namespace Seele
{
DECLARE_NAME_REF(Gfx, Texture2D)
DECLARE_NAME_REF(Gfx, RenderTargetAttachment)
class UIPass : public RenderPass
{
public:
UIPass(PRenderGraph renderGraph, Gfx::PGraphics graphics, Gfx::PViewport viewport, Gfx::PRenderTargetAttachment renderTarget);
virtual ~UIPass();
virtual void beginFrame() override;
virtual void render() override;
virtual void endFrame() override;
virtual void publishOutputs() override;
virtual void createRenderPass() override;
private:
UI::RenderHierarchy hierarchy;
Gfx::PRenderTargetAttachment renderTarget;
Gfx::PRenderTargetAttachment depthAttachment;
Gfx::PTexture2D depthBuffer;
Gfx::PVertexDeclaration declaration;
Gfx::PVertexShader vertexShader;
Gfx::PFragmentShader fragmentShader;
Gfx::PPipelineLayout pipelineLayout;
Gfx::PGraphicsPipeline pipeline;
};
DEFINE_REF(UIPass);
} // namespace Seele