diff options
-rw-r--r-- | cwd/assets/altcraft/shaders/frag/face.fs | 3 | ||||
-rw-r--r-- | cwd/assets/altcraft/shaders/frag/light.fs | 2 | ||||
-rw-r--r-- | cwd/assets/altcraft/shaders/frag/ssao.fs | 4 | ||||
-rw-r--r-- | cwd/assets/altcraft/shaders/vert/face.vs | 3 | ||||
-rw-r--r-- | src/AssetManager.cpp | 1 | ||||
-rw-r--r-- | src/AssetManager.hpp | 1 | ||||
-rw-r--r-- | src/RenderConfigs.cpp | 3 | ||||
-rw-r--r-- | src/RenderConfigs.hpp | 2 | ||||
-rw-r--r-- | src/RendererSectionData.cpp | 1 | ||||
-rw-r--r-- | src/RendererSectionData.hpp | 3 | ||||
-rw-r--r-- | src/RendererWorld.cpp | 3 |
11 files changed, 19 insertions, 7 deletions
diff --git a/cwd/assets/altcraft/shaders/frag/face.fs b/cwd/assets/altcraft/shaders/frag/face.fs index f8b795f..f9af02c 100644 --- a/cwd/assets/altcraft/shaders/frag/face.fs +++ b/cwd/assets/altcraft/shaders/frag/face.fs @@ -4,6 +4,7 @@ in vec3 faceTextureUv; in vec3 faceAddColor; in vec3 faceNormal; in vec2 faceLight; +in float faceAmbientOcclusion; layout (location = 0) out vec4 color; layout (location = 1) out vec4 normal; @@ -18,5 +19,5 @@ void main() { color = vec4(col.rgb * faceAddColor.rgb, 1.0f); normal = vec4(faceNormal, 1.0f); - light = vec4(faceLight / 15.0f, 0.0f, 1.0f); + light = vec4(faceLight / 15.0f, faceAmbientOcclusion, 1.0f); } diff --git a/cwd/assets/altcraft/shaders/frag/light.fs b/cwd/assets/altcraft/shaders/frag/light.fs index aa9e04e..a0cda02 100644 --- a/cwd/assets/altcraft/shaders/frag/light.fs +++ b/cwd/assets/altcraft/shaders/frag/light.fs @@ -71,7 +71,7 @@ void main() { fragColor = vec4(0.5f); break; case 5: - fragColor = l; + fragColor = vec4(l.r, l.g, 1.0f - l.b, 1.0f); break; case 6: fragColor = vec4(vec3(d), 1.0f); diff --git a/cwd/assets/altcraft/shaders/frag/ssao.fs b/cwd/assets/altcraft/shaders/frag/ssao.fs index 0e49c0b..1c9db1f 100644 --- a/cwd/assets/altcraft/shaders/frag/ssao.fs +++ b/cwd/assets/altcraft/shaders/frag/ssao.fs @@ -5,6 +5,7 @@ out vec4 fragColor; in vec2 uv; uniform sampler2D normal; +uniform sampler2D light; uniform sampler2D depthStencil; uniform sampler2D ssaoNoise; @@ -57,7 +58,8 @@ void main() { float sampleDepth = RecoverViewWorldPos(offset.xy, texture(depthStencil, offset.xy).r).z; float rangeCheck = smoothstep(0.0, 1.0, radius / abs(fragPos.z - sampleDepth)); - occlusion += (sampleDepth >= samplePos.z + bias ? 1.0 : 0.0) * rangeCheck; + float aoMask = texture(light, offset.xy).b; + occlusion += (sampleDepth >= samplePos.z + bias ? 1.0 : 0.0) * rangeCheck * aoMask; } occlusion = 1.0f - (occlusion / samples); diff --git a/cwd/assets/altcraft/shaders/vert/face.vs b/cwd/assets/altcraft/shaders/vert/face.vs index 3e6adf7..d3caf32 100644 --- a/cwd/assets/altcraft/shaders/vert/face.vs +++ b/cwd/assets/altcraft/shaders/vert/face.vs @@ -7,11 +7,13 @@ in float uvLayer; in float animation; in vec3 color; in vec2 light; +in float ambientOcclusion; out vec3 faceTextureUv; out vec3 faceNormal; out vec3 faceAddColor; out vec2 faceLight; +out float faceAmbientOcclusion; layout (std140) uniform Globals { mat4 projView; @@ -34,4 +36,5 @@ void main() { faceNormal = (view * vec4(normal, 0.0f)).xyz; faceAddColor = color; faceLight = light; + faceAmbientOcclusion = ambientOcclusion; } diff --git a/src/AssetManager.cpp b/src/AssetManager.cpp index ca68304..3e3f677 100644 --- a/src/AssetManager.cpp +++ b/src/AssetManager.cpp @@ -594,6 +594,7 @@ BlockFaces &AssetManager::GetBlockModelByBlockId(BlockId block) { blockFaces.transform = glm::mat4(1.0); blockFaces.faces = assetModel->blockModel.parsedFaces; blockFaces.isBlock = assetModel->blockModel.IsBlock; + blockFaces.ambientOcclusion = assetModel->blockModel.AmbientOcclusion; glm::mat4 transform = glm::mat4(1.0); if (model.y != 0) { diff --git a/src/AssetManager.hpp b/src/AssetManager.hpp index 2bee47c..59fc851 100644 --- a/src/AssetManager.hpp +++ b/src/AssetManager.hpp @@ -48,6 +48,7 @@ struct BlockFaces { glm::mat4 transform; std::vector<ParsedFace> faces; bool isBlock; + bool ambientOcclusion; Vector faceDirectionVector[FaceDirection::none]; }; diff --git a/src/RenderConfigs.cpp b/src/RenderConfigs.cpp index 43342bb..78b442d 100644 --- a/src/RenderConfigs.cpp +++ b/src/RenderConfigs.cpp @@ -183,7 +183,7 @@ Gbuffer::Gbuffer(size_t geomW, size_t geomH, size_t lightW, size_t lightH, int s normalConf->SetMaxFilter(Gal::Filtering::Bilinear); normal = gal->BuildTexture(normalConf); - auto lightConf = gal->CreateTexture2DConfig(geomW, geomH, Gal::Format::R8G8); + auto lightConf = gal->CreateTexture2DConfig(geomW, geomH, Gal::Format::R8G8B8); lightConf->SetMinFilter(Gal::Filtering::Bilinear); lightConf->SetMaxFilter(Gal::Filtering::Bilinear); light = gal->BuildTexture(lightConf); @@ -221,6 +221,7 @@ Gbuffer::Gbuffer(size_t geomW, size_t geomH, size_t lightW, size_t lightH, int s std::vector<std::pair<std::string_view, std::shared_ptr<Gal::Texture>>> ssaoTextures = { {"normal", normal}, + {"light", light}, {"depthStencil", depthStencil}, {"ssaoNoise", ssaoNoise}, }; diff --git a/src/RenderConfigs.hpp b/src/RenderConfigs.hpp index d0adfce..9d1ffcd 100644 --- a/src/RenderConfigs.hpp +++ b/src/RenderConfigs.hpp @@ -96,7 +96,7 @@ class Gbuffer { std::shared_ptr<Gal::Texture> depthStencil; std::shared_ptr<Gal::Texture> color; //RGB - color std::shared_ptr<Gal::Texture> normal; //RGB - normal - std::shared_ptr<Gal::Texture> light; //R - faceLight, G - skyLight, B - unused + std::shared_ptr<Gal::Texture> light; //R - faceLight, G - skyLight, B - ssaoDepthMask std::shared_ptr<Gal::Framebuffer> geomFramebuffer; public: diff --git a/src/RendererSectionData.cpp b/src/RendererSectionData.cpp index 7e3d285..c7d922e 100644 --- a/src/RendererSectionData.cpp +++ b/src/RendererSectionData.cpp @@ -69,6 +69,7 @@ void AddFacesByBlockModel(RendererSectionData &data, const BlockFaces &model, co vertexData.animations = face.frames; vertexData.colors = face.color; vertexData.lights = lightness; + vertexData.ambientOcclusion = model.ambientOcclusion ? 1.0f : 0.0f; } } diff --git a/src/RendererSectionData.hpp b/src/RendererSectionData.hpp index 0a80560..390200c 100644 --- a/src/RendererSectionData.hpp +++ b/src/RendererSectionData.hpp @@ -38,7 +38,8 @@ struct VertexData { float animations; glm::vec3 colors; glm::vec2 lights; - uint8_t padding[8]; + float ambientOcclusion; + uint8_t padding[4]; }; struct RendererSectionData { diff --git a/src/RendererWorld.cpp b/src/RendererWorld.cpp index 7cbd45e..2ffb57f 100644 --- a/src/RendererWorld.cpp +++ b/src/RendererWorld.cpp @@ -463,7 +463,8 @@ void RendererWorld::PrepareRender(std::shared_ptr<Gal::Framebuffer> target, bool {"animation", Gal::Type::Float, 1, 1}, {"color", Gal::Type::Vec3, 1, 1}, {"light", Gal::Type::Vec2, 1, 1}, - {"", Gal::Type::Uint8, 8, 1} + {"ambientOcclusion", Gal::Type::Float, 1, 1}, + {"", Gal::Type::Uint8, 4, 1} }); sectionsPipeline = gal->BuildPipeline(sectionsPLC); } |