summaryrefslogtreecommitdiffstats
path: root/src/RenderConfigs.cpp
diff options
context:
space:
mode:
authorLaG1924 <lag1924@gmail.com>2021-12-08 16:33:09 +0100
committerLaG1924 <lag1924@gmail.com>2021-12-08 16:33:09 +0100
commita12779bc153425407b131bce541c0bb97cccca39 (patch)
tree91ed3bb9b00c274f5be91cf920317e760fe99e7a /src/RenderConfigs.cpp
parentAdded more SSAO settings (diff)
downloadAltCraft-a12779bc153425407b131bce541c0bb97cccca39.tar
AltCraft-a12779bc153425407b131bce541c0bb97cccca39.tar.gz
AltCraft-a12779bc153425407b131bce541c0bb97cccca39.tar.bz2
AltCraft-a12779bc153425407b131bce541c0bb97cccca39.tar.lz
AltCraft-a12779bc153425407b131bce541c0bb97cccca39.tar.xz
AltCraft-a12779bc153425407b131bce541c0bb97cccca39.tar.zst
AltCraft-a12779bc153425407b131bce541c0bb97cccca39.zip
Diffstat (limited to '')
-rw-r--r--src/RenderConfigs.cpp93
1 files changed, 92 insertions, 1 deletions
diff --git a/src/RenderConfigs.cpp b/src/RenderConfigs.cpp
index 56c24bf..af1cde9 100644
--- a/src/RenderConfigs.cpp
+++ b/src/RenderConfigs.cpp
@@ -22,6 +22,96 @@ std::shared_ptr<Gal::Shader> LoadPixelShader(std::string_view assetPath) {
return gal->LoadPixelShader(LoadShaderCode(assetPath));
}
+TextureFbCopy::TextureFbCopy(
+ std::shared_ptr<Gal::Texture> inputTexture,
+ std::shared_ptr<Gal::Texture> outputTexture,
+ std::shared_ptr<Gal::Shader> copyShader) {
+
+ auto gal = Gal::GetImplementation();
+
+ auto fbConf = gal->CreateFramebufferConfig();
+ fbConf->SetTexture(0, outputTexture);
+
+ auto [outputW, outputH, outputD] = outputTexture->GetSize();
+
+ framebuffer = gal->BuildFramebuffer(fbConf);
+ framebuffer->SetViewport(0, 0, outputW, outputH);
+
+ auto fbPPC = gal->CreatePipelineConfig();
+ fbPPC->SetTarget(framebuffer);
+
+ fbPPC->AddStaticTexture("inputTexture", inputTexture);
+
+ fbPPC->SetVertexShader(LoadVertexShader("/altcraft/shaders/vert/quad"));
+ fbPPC->SetPixelShader(copyShader ? copyShader : LoadPixelShader("/altcraft/shaders/frag/copy"));
+ auto fbBufferBB = fbPPC->BindVertexBuffer({
+ {"pos", Gal::Type::Vec2},
+ {"uvPos", Gal::Type::Vec2}
+ });
+
+ pipeline = gal->BuildPipeline(fbPPC);
+
+ fbBuffer = gal->CreateBuffer();
+ constexpr float quadVertices[] = {
+ // pos // uv
+ -1.0f, 1.0f, 0.0f, 1.0f,
+ -1.0f, -1.0f, 0.0f, 0.0f,
+ 1.0f, -1.0f, 1.0f, 0.0f,
+
+ -1.0f, 1.0f, 0.0f, 1.0f,
+ 1.0f, -1.0f, 1.0f, 0.0f,
+ 1.0f, 1.0f, 1.0f, 1.0f
+ };
+ auto quadPtr = reinterpret_cast<const std::byte*>(quadVertices);
+ fbBuffer->SetData({ quadPtr, quadPtr + sizeof(quadVertices) });
+
+ pipelineInstance = pipeline->CreateInstance({
+ {fbBufferBB, fbBuffer}
+ });
+}
+
+TextureFbCopy::TextureFbCopy(
+ std::shared_ptr<Gal::Texture> inputTexture,
+ std::shared_ptr<Gal::Framebuffer> outputFb,
+ std::shared_ptr<Gal::Shader> copyShader) {
+
+ auto gal = Gal::GetImplementation();
+
+ framebuffer = outputFb;
+
+ auto fbPPC = gal->CreatePipelineConfig();
+ fbPPC->SetTarget(framebuffer);
+
+ fbPPC->AddStaticTexture("inputTexture", inputTexture);
+
+ fbPPC->SetVertexShader(LoadVertexShader("/altcraft/shaders/vert/quad"));
+ fbPPC->SetPixelShader(copyShader ? copyShader : LoadPixelShader("/altcraft/shaders/frag/copy"));
+ auto fbBufferBB = fbPPC->BindVertexBuffer({
+ {"pos", Gal::Type::Vec2},
+ {"uvPos", Gal::Type::Vec2}
+ });
+
+ pipeline = gal->BuildPipeline(fbPPC);
+
+ fbBuffer = gal->CreateBuffer();
+ constexpr float quadVertices[] = {
+ // pos // uv
+ -1.0f, 1.0f, 0.0f, 1.0f,
+ -1.0f, -1.0f, 0.0f, 0.0f,
+ 1.0f, -1.0f, 1.0f, 0.0f,
+
+ -1.0f, 1.0f, 0.0f, 1.0f,
+ 1.0f, -1.0f, 1.0f, 0.0f,
+ 1.0f, 1.0f, 1.0f, 1.0f
+ };
+ auto quadPtr = reinterpret_cast<const std::byte*>(quadVertices);
+ fbBuffer->SetData({ quadPtr, quadPtr + sizeof(quadVertices) });
+
+ pipelineInstance = pipeline->CreateInstance({
+ {fbBufferBB, fbBuffer}
+ });
+}
+
PostProcess::PostProcess(
std::shared_ptr<Gal::Shader> pixelShader,
std::vector<std::pair<std::string_view, std::shared_ptr<Gal::Texture>>> inputTextures,
@@ -52,7 +142,7 @@ PostProcess::PostProcess(
for (auto&& [name, type] : inputParameters) {
fbPPC->AddShaderParameter(name, type);
}
- fbPPC->SetVertexShader(LoadVertexShader("/altcraft/shaders/vert/pp"));
+ fbPPC->SetVertexShader(LoadVertexShader("/altcraft/shaders/vert/quad"));
fbPPC->SetPixelShader(pixelShader);
auto fbBufferBB = fbPPC->BindVertexBuffer({
{"pos", Gal::Type::Vec2},
@@ -208,3 +298,4 @@ Gbuffer::Gbuffer(size_t geomW, size_t geomH, size_t lightW, size_t lightH, int s
lightingPass->SetShaderParameter("applySsao", ssaoSamples);
}
+