summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cwd/assets/altcraft/scripts/ui.lua3
-rw-r--r--cwd/assets/altcraft/shaders/frag/ssao.fs5
-rw-r--r--cwd/assets/altcraft/ui/options-styles.rcss4
-rw-r--r--cwd/assets/altcraft/ui/options.rml14
-rw-r--r--src/Render.cpp6
-rw-r--r--src/RenderConfigs.cpp24
-rw-r--r--src/RenderConfigs.hpp2
7 files changed, 39 insertions, 19 deletions
diff --git a/cwd/assets/altcraft/scripts/ui.lua b/cwd/assets/altcraft/scripts/ui.lua
index bc04626..5973fc4 100644
--- a/cwd/assets/altcraft/scripts/ui.lua
+++ b/cwd/assets/altcraft/scripts/ui.lua
@@ -8,7 +8,8 @@ local options = {
targetFps = 60,
vsync = false,
wireframe = false,
- ssao = false,
+ ssaoSamples = 0,
+ ssaoScale = 0.5,
}
function OpenOptions(doc)
diff --git a/cwd/assets/altcraft/shaders/frag/ssao.fs b/cwd/assets/altcraft/shaders/frag/ssao.fs
index 0615e8f..4ed93fd 100644
--- a/cwd/assets/altcraft/shaders/frag/ssao.fs
+++ b/cwd/assets/altcraft/shaders/frag/ssao.fs
@@ -8,6 +8,8 @@ uniform sampler2D normal;
uniform sampler2D worldPos;
uniform sampler2D ssaoNoise;
+uniform int ssaoSamples;
+
layout (std140) uniform Globals {
mat4 projView;
mat4 proj;
@@ -36,7 +38,8 @@ void main() {
mat3 TBN = mat3(tangent, bitangent, normal);
float occlusion = 0.0;
- for(int i = 0; i < kernelSize; i++)
+ int samples = min(kernelSize, ssaoSamples);
+ for(int i = 0; i < samples; i++)
{
vec3 samplePos = TBN * ssaoKernels[i].xyz;
samplePos = fragPos + samplePos * radius;
diff --git a/cwd/assets/altcraft/ui/options-styles.rcss b/cwd/assets/altcraft/ui/options-styles.rcss
index fbfc685..4822580 100644
--- a/cwd/assets/altcraft/ui/options-styles.rcss
+++ b/cwd/assets/altcraft/ui/options-styles.rcss
@@ -5,7 +5,7 @@
form {
width: 70%;
display: block;
- margin: 5% auto;
+ margin: 1% auto;
background-color: #211710;
}
@@ -80,5 +80,5 @@ input.range sliderarrowinc {
width: 45%;
height: 8%;
position: fixed;
- margin: 5% auto auto;
+ margin: 3% auto auto;
}
diff --git a/cwd/assets/altcraft/ui/options.rml b/cwd/assets/altcraft/ui/options.rml
index ea7c39e..7211ef2 100644
--- a/cwd/assets/altcraft/ui/options.rml
+++ b/cwd/assets/altcraft/ui/options.rml
@@ -62,11 +62,17 @@
</div>
<div class="option">
- <label>Ambient occlusion</label>
- <input type="checkbox" id="ssao" />
- <span id="ssao-val"></span>
+ <label>Ambient occlusion quality</label>
+ <input type="range" min="0" max="64" step="4" id="ssaoSamples" />
+ <span id="ssaoSamples-val"></span>
</div>
-
+
+ <div class="option">
+ <label>Ambient occlusion scale</label>
+ <input type="range" min="0.05" max="2.0" step="0.05" id="ssaoScale" />
+ <span id="ssaoScale-val"></span>
+ </div>
+
</form>
<button class="mc-button" id="done" onclick="CloseOptions(document)">Done</button>
</body>
diff --git a/src/Render.cpp b/src/Render.cpp
index 35ee695..be7e2b2 100644
--- a/src/Render.cpp
+++ b/src/Render.cpp
@@ -152,7 +152,11 @@ void Render::PrepareToRendering() {
bool useDeffered = Settings::ReadBool("deffered", false);
if (useDeffered) {
- gbuffer = std::make_unique<Gbuffer>(scaledW, scaledH, scaledW, scaledH, Settings::ReadBool("ssao", false));
+ int ssaoSamples = Settings::ReadDouble("ssaoSamples", 0.5f);
+ float ssaoScale = Settings::ReadDouble("ssaoScale", 0.5f);
+ size_t ssaoW = scaledW * ssaoScale, ssaoH = scaledH * ssaoScale;
+
+ gbuffer = std::make_unique<Gbuffer>(scaledW, scaledH, scaledW, scaledH, ssaoSamples, ssaoW, ssaoH);
gbuffer->SetRenderBuff(renderBuff);
std::mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());
diff --git a/src/RenderConfigs.cpp b/src/RenderConfigs.cpp
index 3d91a1d..56c24bf 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, bool applySsao) {
+Gbuffer::Gbuffer(size_t geomW, size_t geomH, size_t lightW, size_t lightH, int ssaoSamples, size_t ssaoW, size_t ssaoH) {
auto gal = Gal::GetImplementation();
auto colorConf = gal->CreateTexture2DConfig(geomW, geomH, Gal::Format::R8G8B8);
@@ -124,7 +124,7 @@ Gbuffer::Gbuffer(size_t geomW, size_t geomH, size_t lightW, size_t lightH, bool
geomFramebuffer = gal->BuildFramebuffer(geomFbConf);
geomFramebuffer->SetViewport(0, 0, geomW, geomH);
- if (applySsao) {
+ if (ssaoSamples > 0) {
auto noiseConf = gal->CreateTexture2DConfig(4, 4, Gal::Format::R32G32B32A32F);
noiseConf->SetWrapping(Gal::Wrapping::Repeat);
noiseConf->SetMinFilter(Gal::Filtering::Bilinear);
@@ -148,14 +148,20 @@ Gbuffer::Gbuffer(size_t geomW, size_t geomH, size_t lightW, size_t lightH, bool
{"ssaoNoise", ssaoNoise},
};
+ std::vector<std::pair<std::string_view, Gal::Type>> ssaoParameters = {
+ {"ssaoSamples", Gal::Type::Int32},
+ };
+
ssaoPass = std::make_unique<PostProcess>(LoadPixelShader("/altcraft/shaders/frag/ssao"),
ssaoTextures,
- std::vector<std::pair<std::string_view, Gal::Type>>{},
- lightW,
- lightH,
+ ssaoParameters,
+ ssaoW,
+ ssaoH,
Gal::Format::R8G8B8A8,
Gal::Filtering::Bilinear);
+ ssaoPass->SetShaderParameter("ssaoSamples", ssaoSamples);
+
std::vector<std::pair<std::string_view, std::shared_ptr<Gal::Texture>>> ssaoBlurTextures = {
{"blurInput", ssaoPass->GetResultTexture()},
};
@@ -167,8 +173,8 @@ Gbuffer::Gbuffer(size_t geomW, size_t geomH, size_t lightW, size_t lightH, bool
ssaoBlurPass = std::make_unique<PostProcess>(LoadPixelShader("/altcraft/shaders/frag/blur"),
ssaoBlurTextures,
ssaoBlurParameters,
- lightW,
- lightH,
+ ssaoW,
+ ssaoH,
Gal::Format::R8G8B8A8,
Gal::Filtering::Bilinear);
@@ -189,7 +195,7 @@ Gbuffer::Gbuffer(size_t geomW, size_t geomH, size_t lightW, size_t lightH, bool
{"light", light},
};
- if (applySsao)
+ if (ssaoSamples > 0)
lightingTextures.emplace_back("ssao", ssaoBlurPass->GetResultTexture());
lightingPass = std::make_unique<PostProcess>(LoadPixelShader("/altcraft/shaders/frag/light"),
@@ -200,5 +206,5 @@ Gbuffer::Gbuffer(size_t geomW, size_t geomH, size_t lightW, size_t lightH, bool
Gal::Format::R8G8B8A8,
Gal::Filtering::Bilinear);
- lightingPass->SetShaderParameter("applySsao", applySsao);
+ lightingPass->SetShaderParameter("applySsao", ssaoSamples);
}
diff --git a/src/RenderConfigs.hpp b/src/RenderConfigs.hpp
index a9b8d72..d76647e 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, bool applySsao);
+ Gbuffer(size_t geomW, size_t geomH, size_t lightW, size_t lightH, int ssaoSamples, size_t ssaoW, size_t ssaoH);
std::shared_ptr<Gal::Framebuffer> GetGeometryTarget() {
return geomFramebuffer;