summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaG1924 <lag1924@gmail.com>2021-12-05 00:50:13 +0100
committerLaG1924 <lag1924@gmail.com>2021-12-05 00:50:13 +0100
commitf01c1c3704d277a3fe8286f591fef6693d9e089c (patch)
tree261a99b53ebcb5e8973e71685a038a6a26ff88e6
parentAdded SSAO blur (diff)
downloadAltCraft-f01c1c3704d277a3fe8286f591fef6693d9e089c.tar
AltCraft-f01c1c3704d277a3fe8286f591fef6693d9e089c.tar.gz
AltCraft-f01c1c3704d277a3fe8286f591fef6693d9e089c.tar.bz2
AltCraft-f01c1c3704d277a3fe8286f591fef6693d9e089c.tar.lz
AltCraft-f01c1c3704d277a3fe8286f591fef6693d9e089c.tar.xz
AltCraft-f01c1c3704d277a3fe8286f591fef6693d9e089c.tar.zst
AltCraft-f01c1c3704d277a3fe8286f591fef6693d9e089c.zip
Diffstat (limited to '')
-rw-r--r--cwd/assets/altcraft/scripts/ui.lua17
-rw-r--r--cwd/assets/altcraft/shaders/frag/light.fs5
-rw-r--r--cwd/assets/altcraft/ui/options.rml6
-rw-r--r--src/Render.cpp2
-rw-r--r--src/RenderConfigs.cpp105
-rw-r--r--src/RenderConfigs.hpp14
6 files changed, 85 insertions, 64 deletions
diff --git a/cwd/assets/altcraft/scripts/ui.lua b/cwd/assets/altcraft/scripts/ui.lua
index 10791d1..938088f 100644
--- a/cwd/assets/altcraft/scripts/ui.lua
+++ b/cwd/assets/altcraft/scripts/ui.lua
@@ -1,12 +1,13 @@
local options = {
- gamma = 2.2,
- flight = false,
- mouseSensetivity = 0.1,
- renderDistance = 2,
- resolutionScale = 1.0,
- targetFps = 60,
- vsync = false,
- wireframe = false
+ gamma = 2.2,
+ flight = false,
+ mouseSensetivity = 0.1,
+ renderDistance = 2,
+ resolutionScale = 1.0,
+ targetFps = 60,
+ vsync = false,
+ wireframe = false,
+ ssao = false,
}
function OpenOptions(doc)
diff --git a/cwd/assets/altcraft/shaders/frag/light.fs b/cwd/assets/altcraft/shaders/frag/light.fs
index 8556770..5b2de5d 100644
--- a/cwd/assets/altcraft/shaders/frag/light.fs
+++ b/cwd/assets/altcraft/shaders/frag/light.fs
@@ -13,6 +13,7 @@ uniform sampler2D light;
uniform sampler2D ssao;
uniform int renderBuff;
+uniform bool applySsao;
layout (std140) uniform Globals {
mat4 projView;
@@ -41,7 +42,9 @@ void main() {
float skyLight = l.g;
float lightLevel = clamp(faceLight + skyLight * dayTime, 0.01f, 1.0f);
lightLevel = pow(lightLevel, 3);
- lightLevel *= (1.0f - s.r);
+ if (applySsao) {
+ lightLevel *= (1.0f - s.r);
+ }
lightLevel = clamp(lightLevel, 0.005f, 1.0f);
vec3 faceColor = mix(ac.rgb * lightLevel, vec3(1,1,1) * lightLevel, float(ac.rgb == vec3(0,0,0)));
diff --git a/cwd/assets/altcraft/ui/options.rml b/cwd/assets/altcraft/ui/options.rml
index c5758be..9aa4624 100644
--- a/cwd/assets/altcraft/ui/options.rml
+++ b/cwd/assets/altcraft/ui/options.rml
@@ -54,6 +54,12 @@
<input type="checkbox" id="wireframe" />
<span id="wireframe-val"></span>
</div>
+
+ <div class="option">
+ <label>Ambient occlusion</label>
+ <input type="checkbox" id="ssao" />
+ <span id="ssao-val"></span>
+ </div>
</form>
<button class="mc-button" id="done" onclick="CloseOptions(document)">Done</button>
diff --git a/src/Render.cpp b/src/Render.cpp
index 1095148..1e85437 100644
--- a/src/Render.cpp
+++ b/src/Render.cpp
@@ -140,7 +140,7 @@ void Render::PrepareToRendering() {
float resolutionScale = Settings::ReadDouble("resolutionScale", 1.0f);
size_t scaledW = width * resolutionScale, scaledH = height * resolutionScale;
- gbuffer = std::make_unique<Gbuffer>(scaledW, scaledH, scaledW, scaledH);
+ gbuffer = std::make_unique<Gbuffer>(scaledW, scaledH, scaledW, scaledH, Settings::ReadBool("ssao", false));
gbuffer->SetRenderBuff(renderBuff);
auto gal = Gal::GetImplementation();
diff --git a/src/RenderConfigs.cpp b/src/RenderConfigs.cpp
index 88166a5..0a5450b 100644
--- a/src/RenderConfigs.cpp
+++ b/src/RenderConfigs.cpp
@@ -80,7 +80,7 @@ PostProcess::PostProcess(
});
}
-Gbuffer::Gbuffer(size_t geomW, size_t geomH, size_t lightW, size_t lightH) {
+Gbuffer::Gbuffer(size_t geomW, size_t geomH, size_t lightW, size_t lightH, bool applySsao) {
auto gal = Gal::GetImplementation();
auto colorConf = gal->CreateTexture2DConfig(geomW, geomH, Gal::Format::R8G8B8);
@@ -124,57 +124,60 @@ Gbuffer::Gbuffer(size_t geomW, size_t geomH, size_t lightW, size_t lightH) {
geomFramebuffer = gal->BuildFramebuffer(geomFbConf);
geomFramebuffer->SetViewport(0, 0, geomW, geomH);
- auto noiseConf = gal->CreateTexture2DConfig(4, 4, Gal::Format::R32G32B32A32F);
- noiseConf->SetWrapping(Gal::Wrapping::Repeat);
- noiseConf->SetMinFilter(Gal::Filtering::Bilinear);
- noiseConf->SetMaxFilter(Gal::Filtering::Bilinear);
- ssaoNoise = gal->BuildTexture(noiseConf);
-
- std::mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());
- std::uniform_real_distribution<> dis(-1.0f, 1.0f);
- std::vector<glm::vec4> noiseTexData(16);
- for (auto& vec : noiseTexData) {
- vec.x = dis(rng);
- vec.y = dis(rng);
- vec.z = 0.0f;
- vec.w = 0.0f;
+ if (applySsao) {
+ auto noiseConf = gal->CreateTexture2DConfig(4, 4, Gal::Format::R32G32B32A32F);
+ noiseConf->SetWrapping(Gal::Wrapping::Repeat);
+ noiseConf->SetMinFilter(Gal::Filtering::Bilinear);
+ noiseConf->SetMaxFilter(Gal::Filtering::Bilinear);
+ ssaoNoise = gal->BuildTexture(noiseConf);
+
+ std::mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());
+ std::uniform_real_distribution<> dis(-1.0f, 1.0f);
+ std::vector<glm::vec4> noiseTexData(16);
+ for (auto& vec : noiseTexData) {
+ vec.x = dis(rng);
+ vec.y = dis(rng);
+ vec.z = 0.0f;
+ vec.w = 0.0f;
+ }
+ ssaoNoise->SetData({ reinterpret_cast<std::byte*>(noiseTexData.data()), reinterpret_cast<std::byte*>(noiseTexData.data() + noiseTexData.size()) });
+
+ std::vector<std::pair<std::string_view, std::shared_ptr<Gal::Texture>>> ssaoTextures = {
+ {"normal", normal},
+ {"worldPos", worldPos},
+ {"ssaoNoise", ssaoNoise},
+ };
+
+ ssaoPass = std::make_unique<PostProcess>(LoadPixelShader("/altcraft/shaders/frag/ssao"),
+ ssaoTextures,
+ std::vector<std::pair<std::string_view, Gal::Type>>{},
+ lightW,
+ lightH,
+ Gal::Format::R8G8B8A8,
+ Gal::Filtering::Bilinear);
+
+ std::vector<std::pair<std::string_view, std::shared_ptr<Gal::Texture>>> ssaoBlurTextures = {
+ {"blurInput", ssaoPass->GetResultTexture()},
+ };
+
+ std::vector<std::pair<std::string_view, Gal::Type>> ssaoBlurParameters = {
+ {"blurScale", Gal::Type::Int32},
+ };
+
+ ssaoBlurPass = std::make_unique<PostProcess>(LoadPixelShader("/altcraft/shaders/frag/blur"),
+ ssaoBlurTextures,
+ ssaoBlurParameters,
+ lightW,
+ lightH,
+ Gal::Format::R8G8B8A8,
+ Gal::Filtering::Bilinear);
+
+ ssaoBlurPass->SetShaderParameter("blurScale", 2);
}
- ssaoNoise->SetData({ reinterpret_cast<std::byte*>(noiseTexData.data()), reinterpret_cast<std::byte*>(noiseTexData.data() + noiseTexData.size()) });
-
- std::vector<std::pair<std::string_view, std::shared_ptr<Gal::Texture>>> ssaoTextures = {
- {"normal", normal},
- {"worldPos", worldPos},
- {"ssaoNoise", ssaoNoise},
- };
-
- ssaoPass = std::make_unique<PostProcess>(LoadPixelShader("/altcraft/shaders/frag/ssao"),
- ssaoTextures,
- std::vector<std::pair<std::string_view, Gal::Type>>{},
- lightW,
- lightH,
- Gal::Format::R8G8B8A8,
- Gal::Filtering::Bilinear);
-
- std::vector<std::pair<std::string_view, std::shared_ptr<Gal::Texture>>> ssaoBlurTextures = {
- {"blurInput", ssaoPass->GetResultTexture()},
- };
-
- std::vector<std::pair<std::string_view, Gal::Type>> ssaoBlurParameters = {
- {"blurScale", Gal::Type::Int32},
- };
-
- ssaoBlurPass = std::make_unique<PostProcess>(LoadPixelShader("/altcraft/shaders/frag/blur"),
- ssaoBlurTextures,
- ssaoBlurParameters,
- lightW,
- lightH,
- Gal::Format::R8G8B8A8,
- Gal::Filtering::Bilinear);
-
- ssaoBlurPass->SetShaderParameter("blurScale", 2);
std::vector<std::pair<std::string_view, Gal::Type>> lightingParameters = {
{"renderBuff", Gal::Type::Int32},
+ {"applySsao", Gal::Type::Int32},
};
std::vector<std::pair<std::string_view, std::shared_ptr<Gal::Texture>>> lightingTextures = {
@@ -184,9 +187,11 @@ Gbuffer::Gbuffer(size_t geomW, size_t geomH, size_t lightW, size_t lightH) {
{"worldPos", worldPos},
{"addColor", addColor},
{"light", light},
- {"ssao", ssaoBlurPass->GetResultTexture()},
};
+ if (applySsao)
+ lightingTextures.emplace_back("ssao", ssaoBlurPass->GetResultTexture());
+
lightingPass = std::make_unique<PostProcess>(LoadPixelShader("/altcraft/shaders/frag/light"),
lightingTextures,
lightingParameters,
@@ -194,4 +199,6 @@ Gbuffer::Gbuffer(size_t geomW, size_t geomH, size_t lightW, size_t lightH) {
lightH,
Gal::Format::R8G8B8A8,
Gal::Filtering::Bilinear);
+
+ lightingPass->SetShaderParameter("applySsao", true);
}
diff --git a/src/RenderConfigs.hpp b/src/RenderConfigs.hpp
index 0667bbe..a9b8d72 100644
--- a/src/RenderConfigs.hpp
+++ b/src/RenderConfigs.hpp
@@ -73,7 +73,7 @@ class Gbuffer {
std::shared_ptr<Gal::Framebuffer> geomFramebuffer;
public:
- Gbuffer(size_t geomW, size_t geomH, size_t lightW, size_t lightH);
+ Gbuffer(size_t geomW, size_t geomH, size_t lightW, size_t lightH, bool applySsao);
std::shared_ptr<Gal::Framebuffer> GetGeometryTarget() {
return geomFramebuffer;
@@ -84,15 +84,19 @@ public:
}
void Render() {
- ssaoPass->Render();
- ssaoBlurPass->Render();
+ if (ssaoPass) {
+ ssaoPass->Render();
+ ssaoBlurPass->Render();
+ }
lightingPass->Render();
}
void Clear() {
geomFramebuffer->Clear();
- ssaoPass->Clear();
- ssaoBlurPass->Clear();
+ if (ssaoPass) {
+ ssaoPass->Clear();
+ ssaoBlurPass->Clear();
+ }
lightingPass->Clear();
}