diff options
-rw-r--r-- | cwd/assets/altcraft/shaders/frag/blur.fs | 22 | ||||
-rw-r--r-- | cwd/assets/altcraft/shaders/frag/light.fs | 3 | ||||
-rw-r--r-- | src/RenderConfigs.cpp | 20 | ||||
-rw-r--r-- | src/RenderConfigs.hpp | 3 |
4 files changed, 46 insertions, 2 deletions
diff --git a/cwd/assets/altcraft/shaders/frag/blur.fs b/cwd/assets/altcraft/shaders/frag/blur.fs new file mode 100644 index 0000000..b49032f --- /dev/null +++ b/cwd/assets/altcraft/shaders/frag/blur.fs @@ -0,0 +1,22 @@ +#version 330 core + +out vec4 fragColor; + +in vec2 uv; + +uniform sampler2D blurInput; +uniform int blurScale; + +void main() { + vec2 texelSize = 1.0f / vec2(textureSize(blurInput, 0)); + vec4 result = vec4(0.0f); + for (int x = -blurScale; x < blurScale; x++) + { + for (int y = -blurScale; y < blurScale; y++) + { + vec2 offset = vec2(float(x), float(y)) * texelSize; + result += texture(blurInput, uv + offset); + } + } + fragColor = result / pow(blurScale, 3); +} diff --git a/cwd/assets/altcraft/shaders/frag/light.fs b/cwd/assets/altcraft/shaders/frag/light.fs index fd7aa4e..8556770 100644 --- a/cwd/assets/altcraft/shaders/frag/light.fs +++ b/cwd/assets/altcraft/shaders/frag/light.fs @@ -41,10 +41,11 @@ 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); 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))); - vec4 finalColor = vec4(c.rgb * faceColor * (1.0f - s.r), 1.0f); + vec4 finalColor = vec4(c.rgb * faceColor, 1.0f); finalColor.rgb = pow(finalColor.rgb, vec3(1.0f / gamma)); diff --git a/src/RenderConfigs.cpp b/src/RenderConfigs.cpp index d185c79..88166a5 100644 --- a/src/RenderConfigs.cpp +++ b/src/RenderConfigs.cpp @@ -155,6 +155,24 @@ Gbuffer::Gbuffer(size_t geomW, size_t geomH, size_t lightW, size_t 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}, }; @@ -166,7 +184,7 @@ Gbuffer::Gbuffer(size_t geomW, size_t geomH, size_t lightW, size_t lightH) { {"worldPos", worldPos}, {"addColor", addColor}, {"light", light}, - {"ssao", ssaoPass->GetResultTexture()}, + {"ssao", ssaoBlurPass->GetResultTexture()}, }; lightingPass = std::make_unique<PostProcess>(LoadPixelShader("/altcraft/shaders/frag/light"), diff --git a/src/RenderConfigs.hpp b/src/RenderConfigs.hpp index ef4c97d..0667bbe 100644 --- a/src/RenderConfigs.hpp +++ b/src/RenderConfigs.hpp @@ -62,6 +62,7 @@ public: class Gbuffer { std::shared_ptr<Gal::Texture> ssaoNoise; std::unique_ptr<PostProcess> ssaoPass; + std::unique_ptr<PostProcess> ssaoBlurPass; std::unique_ptr<PostProcess> lightingPass; std::shared_ptr<Gal::Texture> depthStencil; std::shared_ptr<Gal::Texture> color; //RGB - color @@ -84,12 +85,14 @@ public: void Render() { ssaoPass->Render(); + ssaoBlurPass->Render(); lightingPass->Render(); } void Clear() { geomFramebuffer->Clear(); ssaoPass->Clear(); + ssaoBlurPass->Clear(); lightingPass->Clear(); } |