diff options
author | LaG1924 <lag1924@gmail.com> | 2021-12-04 20:51:39 +0100 |
---|---|---|
committer | LaG1924 <lag1924@gmail.com> | 2021-12-04 20:56:29 +0100 |
commit | 3f122e57f118db1229a4bad2c54be624f2f8f19c (patch) | |
tree | 538ec737720cc8e344cbcfed1edcedff0d23a109 | |
parent | Added gamma correction (diff) | |
download | AltCraft-3f122e57f118db1229a4bad2c54be624f2f8f19c.tar AltCraft-3f122e57f118db1229a4bad2c54be624f2f8f19c.tar.gz AltCraft-3f122e57f118db1229a4bad2c54be624f2f8f19c.tar.bz2 AltCraft-3f122e57f118db1229a4bad2c54be624f2f8f19c.tar.lz AltCraft-3f122e57f118db1229a4bad2c54be624f2f8f19c.tar.xz AltCraft-3f122e57f118db1229a4bad2c54be624f2f8f19c.tar.zst AltCraft-3f122e57f118db1229a4bad2c54be624f2f8f19c.zip |
Diffstat (limited to '')
-rw-r--r-- | cwd/assets/altcraft/shaders/frag/entity.fs | 8 | ||||
-rw-r--r-- | cwd/assets/altcraft/shaders/frag/face.fs | 7 | ||||
-rw-r--r-- | cwd/assets/altcraft/shaders/frag/light.fs | 24 | ||||
-rw-r--r-- | cwd/assets/altcraft/shaders/frag/sky.fs | 9 | ||||
-rw-r--r-- | cwd/assets/altcraft/shaders/frag/ssao.fs | 55 | ||||
-rw-r--r-- | cwd/assets/altcraft/shaders/vert/entity.vs | 6 | ||||
-rw-r--r-- | cwd/assets/altcraft/shaders/vert/face.vs | 6 | ||||
-rw-r--r-- | cwd/assets/altcraft/shaders/vert/fbo.vs | 3 | ||||
-rw-r--r-- | cwd/assets/altcraft/shaders/vert/light.vs | 3 | ||||
-rw-r--r-- | cwd/assets/altcraft/shaders/vert/pp.vs | 3 | ||||
-rw-r--r-- | cwd/assets/altcraft/shaders/vert/rml.vs | 3 | ||||
-rw-r--r-- | cwd/assets/altcraft/shaders/vert/sky.vs | 3 | ||||
-rw-r--r-- | src/Gal.hpp | 1 | ||||
-rw-r--r-- | src/GalOgl.cpp | 14 | ||||
-rw-r--r-- | src/Render.cpp | 18 | ||||
-rw-r--r-- | src/RenderConfigs.cpp | 62 | ||||
-rw-r--r-- | src/RenderConfigs.hpp | 14 | ||||
-rw-r--r-- | src/RendererSectionData.cpp | 2 | ||||
-rw-r--r-- | src/RendererWorld.cpp | 15 |
19 files changed, 227 insertions, 29 deletions
diff --git a/cwd/assets/altcraft/shaders/frag/entity.fs b/cwd/assets/altcraft/shaders/frag/entity.fs index be4da09..6e77a29 100644 --- a/cwd/assets/altcraft/shaders/frag/entity.fs +++ b/cwd/assets/altcraft/shaders/frag/entity.fs @@ -1,15 +1,19 @@ #version 330 core +in vec4 entityWorldPos; + layout (location = 0) out vec4 color; layout (location = 1) out vec4 normal; -layout (location = 2) out vec4 addColor; -layout (location = 3) out vec4 light; +layout (location = 2) out vec4 worldPos; +layout (location = 3) out vec4 addColor; +layout (location = 4) out vec4 light; uniform vec3 entityColor; void main() { color = vec4(entityColor, 1.0f); normal = vec4(0.0f, 0.0f, 0.0f, 1.0f); + worldPos = entityWorldPos; addColor = vec4(0.0f, 0.0f, 0.0f, 1.0f); light = vec4(1.0f, 1.0f, 0.0f, 1.0f); } diff --git a/cwd/assets/altcraft/shaders/frag/face.fs b/cwd/assets/altcraft/shaders/frag/face.fs index ebda304..65b7d15 100644 --- a/cwd/assets/altcraft/shaders/frag/face.fs +++ b/cwd/assets/altcraft/shaders/frag/face.fs @@ -1,5 +1,6 @@ #version 330 core +in vec4 faceWorldPos; in vec3 faceTextureUv; in vec3 faceAddColor; in vec3 faceNormal; @@ -7,8 +8,9 @@ in vec2 faceLight; layout (location = 0) out vec4 color; layout (location = 1) out vec4 normal; -layout (location = 2) out vec4 addColor; -layout (location = 3) out vec4 light; +layout (location = 2) out vec4 worldPos; +layout (location = 3) out vec4 addColor; +layout (location = 4) out vec4 light; uniform sampler2DArray textureAtlas; @@ -19,6 +21,7 @@ void main() { color = vec4(col.rgb, 1.0f); normal = vec4(faceNormal, 1.0f); + worldPos = faceWorldPos; addColor = vec4(faceAddColor, 1.0f); light = vec4(faceLight / 15.0f, 0.0f, 1.0f); } diff --git a/cwd/assets/altcraft/shaders/frag/light.fs b/cwd/assets/altcraft/shaders/frag/light.fs index 117e0ef..fd7aa4e 100644 --- a/cwd/assets/altcraft/shaders/frag/light.fs +++ b/cwd/assets/altcraft/shaders/frag/light.fs @@ -4,17 +4,22 @@ out vec4 fragColor; in vec2 uv; +uniform sampler2D depthStencil; uniform sampler2D color; uniform sampler2D normal; +uniform sampler2D worldPos; uniform sampler2D addColor; uniform sampler2D light; -uniform sampler2D depthStencil; +uniform sampler2D ssao; uniform int renderBuff; layout (std140) uniform Globals { mat4 projView; + mat4 proj; + mat4 view; uvec2 viewportSize; + vec4 ssaoKernels[64]; float globalTime; float dayTime; float gamma; @@ -23,9 +28,14 @@ layout (std140) uniform Globals { void main() { vec4 c = texture(color, uv); vec4 n = texture(normal, uv); + n += 1.0f; + n /= 2.0f; + + vec4 wp = texture(worldPos, uv); vec4 ac = texture(addColor, uv); vec4 l = texture(light, uv); float d = (1.0f - texture(depthStencil, uv).r) * 16.0f; + vec4 s = texture(ssao, uv); float faceLight = l.r; float skyLight = l.g; @@ -34,7 +44,7 @@ void main() { 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); + vec4 finalColor = vec4(c.rgb * faceColor * (1.0f - s.r), 1.0f); finalColor.rgb = pow(finalColor.rgb, vec3(1.0f / gamma)); @@ -49,13 +59,19 @@ void main() { fragColor = n; break; case 3: - fragColor = ac; + fragColor = wp; break; case 4: - fragColor = l; + fragColor = ac; break; case 5: + fragColor = l; + break; + case 6: fragColor = vec4(vec3(d), 1.0f); break; + case 7: + fragColor = s; + break; } } diff --git a/cwd/assets/altcraft/shaders/frag/sky.fs b/cwd/assets/altcraft/shaders/frag/sky.fs index 1e36dd3..65a56ad 100644 --- a/cwd/assets/altcraft/shaders/frag/sky.fs +++ b/cwd/assets/altcraft/shaders/frag/sky.fs @@ -4,12 +4,16 @@ in vec3 facePos; layout (location = 0) out vec4 color; layout (location = 1) out vec4 normal; -layout (location = 2) out vec4 addColor; -layout (location = 3) out vec4 light; +layout (location = 2) out vec4 worldPos; +layout (location = 3) out vec4 addColor; +layout (location = 4) out vec4 light; layout (std140) uniform Globals { mat4 projView; + mat4 proj; + mat4 view; uvec2 viewportSize; + vec4 ssaoKernels[64]; float globalTime; float dayTime; float gamma; @@ -61,6 +65,7 @@ void main() { color += vec4(Sun().rgb, 1.0f); color += vec4(Moon().rgb, 1.0f); normal = vec4(0.0f, 0.0f, 0.0f, 1.0f); + worldPos = vec4(0.0f, 0.0f, 0.0f, 1.0f); addColor = vec4(0.0f, 0.0f, 0.0f, 1.0f); light = vec4(1.0f, 1.0f, 0.0f, 1.0f); } diff --git a/cwd/assets/altcraft/shaders/frag/ssao.fs b/cwd/assets/altcraft/shaders/frag/ssao.fs new file mode 100644 index 0000000..f4fea34 --- /dev/null +++ b/cwd/assets/altcraft/shaders/frag/ssao.fs @@ -0,0 +1,55 @@ +#version 330 core + +out vec4 fragColor; + +in vec2 uv; + +uniform sampler2D normal; +uniform sampler2D worldPos; +uniform sampler2D ssaoNoise; + +layout (std140) uniform Globals { + mat4 projView; + mat4 proj; + mat4 view; + uvec2 viewportSize; + vec4 ssaoKernels[64]; + float globalTime; + float dayTime; + float gamma; +}; + +const vec2 noiseScale = vec2(4.0f, 4.0f); +const int kernelSize = 64; +const float radius = 0.5f; +const float bias = 0.025f; + +void main() { + vec3 normal = texture(normal, uv).xyz; + vec3 fragPos = texture(worldPos, uv).xyz; + vec2 noiseUv = uv * viewportSize / noiseScale; + + vec3 randomVec = texture(ssaoNoise, noiseUv).xyz; + + vec3 tangent = normalize(randomVec - normal * dot(randomVec, normal)); + vec3 bitangent = cross(normal, tangent); + mat3 TBN = mat3(tangent, bitangent, normal); + + float occlusion = 0.0; + for(int i = 0; i < kernelSize; i++) + { + vec3 samplePos = TBN * ssaoKernels[i].xyz; + samplePos = fragPos + samplePos * radius; + + vec4 offset = vec4(samplePos, 1.0); + offset = proj * offset; + offset.xyz /= offset.w; + offset.xyz = offset.xyz * 0.5 + 0.5; + + float sampleDepth = texture(worldPos, offset.xy).z; + float rangeCheck = smoothstep(0.0, 1.0, radius / abs(fragPos.z - sampleDepth)); + occlusion += (sampleDepth >= samplePos.z + bias ? 1.0 : 0.0) * rangeCheck; + } + + fragColor = vec4(vec3(occlusion / kernelSize), 1.0f); +} diff --git a/cwd/assets/altcraft/shaders/vert/entity.vs b/cwd/assets/altcraft/shaders/vert/entity.vs index 4acaa93..f90fbc1 100644 --- a/cwd/assets/altcraft/shaders/vert/entity.vs +++ b/cwd/assets/altcraft/shaders/vert/entity.vs @@ -2,11 +2,16 @@ in vec3 pos; +out vec4 entityWorldPos; + uniform mat4 model; layout (std140) uniform Globals { mat4 projView; + mat4 proj; + mat4 view; uvec2 viewportSize; + vec4 ssaoKernels[64]; float globalTime; float dayTime; float gamma; @@ -14,4 +19,5 @@ layout (std140) uniform Globals { void main() { gl_Position = projView * model * vec4(pos, 1); + entityWorldPos = view * model * vec4(pos, 1.0f); } diff --git a/cwd/assets/altcraft/shaders/vert/face.vs b/cwd/assets/altcraft/shaders/vert/face.vs index 70c24c8..e50e503 100644 --- a/cwd/assets/altcraft/shaders/vert/face.vs +++ b/cwd/assets/altcraft/shaders/vert/face.vs @@ -8,6 +8,7 @@ in float animation; in vec3 color; in vec2 light; +out vec4 faceWorldPos; out vec3 faceTextureUv; out vec3 faceNormal; out vec3 faceAddColor; @@ -15,7 +16,10 @@ out vec2 faceLight; layout (std140) uniform Globals { mat4 projView; + mat4 proj; + mat4 view; uvec2 viewportSize; + vec4 ssaoKernels[64]; float globalTime; float dayTime; float gamma; @@ -24,6 +28,8 @@ layout (std140) uniform Globals { void main() { gl_Position = projView * vec4(pos[gl_VertexID], 1.0f); + faceWorldPos = view * vec4(pos[gl_VertexID], 1.0f); + faceTextureUv = vec3(uv[gl_VertexID], uvLayer); faceTextureUv.y -= (uv[2].y - uv[0].y) * trunc(mod(globalTime * 4.0f, animation)); diff --git a/cwd/assets/altcraft/shaders/vert/fbo.vs b/cwd/assets/altcraft/shaders/vert/fbo.vs index cfde14e..0e05eaf 100644 --- a/cwd/assets/altcraft/shaders/vert/fbo.vs +++ b/cwd/assets/altcraft/shaders/vert/fbo.vs @@ -7,7 +7,10 @@ out vec2 uv; layout (std140) uniform Globals { mat4 projView; + mat4 proj; + mat4 view; uvec2 viewportSize; + vec4 ssaoKernels[64]; float globalTime; float dayTime; float gamma; diff --git a/cwd/assets/altcraft/shaders/vert/light.vs b/cwd/assets/altcraft/shaders/vert/light.vs index 4e551f8..118ea5b 100644 --- a/cwd/assets/altcraft/shaders/vert/light.vs +++ b/cwd/assets/altcraft/shaders/vert/light.vs @@ -7,7 +7,10 @@ out vec2 uv; layout (std140) uniform Globals { mat4 projView; + mat4 proj; + mat4 view; uvec2 viewportSize; + vec4 ssaoKernels[64]; float globalTime; float dayTime; float gamma; diff --git a/cwd/assets/altcraft/shaders/vert/pp.vs b/cwd/assets/altcraft/shaders/vert/pp.vs index 4e551f8..118ea5b 100644 --- a/cwd/assets/altcraft/shaders/vert/pp.vs +++ b/cwd/assets/altcraft/shaders/vert/pp.vs @@ -7,7 +7,10 @@ out vec2 uv; layout (std140) uniform Globals { mat4 projView; + mat4 proj; + mat4 view; uvec2 viewportSize; + vec4 ssaoKernels[64]; float globalTime; float dayTime; float gamma; diff --git a/cwd/assets/altcraft/shaders/vert/rml.vs b/cwd/assets/altcraft/shaders/vert/rml.vs index ea78825..c61a4a0 100644 --- a/cwd/assets/altcraft/shaders/vert/rml.vs +++ b/cwd/assets/altcraft/shaders/vert/rml.vs @@ -11,7 +11,10 @@ uniform vec2 translation; layout (std140) uniform Globals { mat4 projView; + mat4 proj; + mat4 view; uvec2 viewportSize; + vec4 ssaoKernels[64]; float globalTime; float dayTime; float gamma; diff --git a/cwd/assets/altcraft/shaders/vert/sky.vs b/cwd/assets/altcraft/shaders/vert/sky.vs index 617caed..7043584 100644 --- a/cwd/assets/altcraft/shaders/vert/sky.vs +++ b/cwd/assets/altcraft/shaders/vert/sky.vs @@ -8,7 +8,10 @@ uniform mat4 model; layout (std140) uniform Globals { mat4 projView; + mat4 proj; + mat4 view; uvec2 viewportSize; + vec4 ssaoKernels[64]; float globalTime; float dayTime; float gamma; diff --git a/src/Gal.hpp b/src/Gal.hpp index 8d7394a..76db560 100644 --- a/src/Gal.hpp +++ b/src/Gal.hpp @@ -63,6 +63,7 @@ namespace Gal { D24S8, R8G8B8, R8G8B8A8, + R32G32B32A32F, }; enum class Filtering { diff --git a/src/GalOgl.cpp b/src/GalOgl.cpp index ff43ed8..c7344fe 100644 --- a/src/GalOgl.cpp +++ b/src/GalOgl.cpp @@ -311,10 +311,14 @@ GLenum GalTypeGetComponentGlType(Gal::Type type) { size_t GalFormatGetSize(Format format) { switch (format) { + case Format::D24S8: + return 4; case Format::R8G8B8: return 3; case Format::R8G8B8A8: return 4; + case Format::R32G32B32A32F: + return 16; default: return 0; } @@ -329,6 +333,8 @@ GLenum GalFormatGetGlLinearInternalFormat(Format format) { return GL_RGB8; case Format::R8G8B8A8: return GL_RGBA8; + case Format::R32G32B32A32F: + return GL_RGBA32F; default: return 0; } @@ -338,11 +344,13 @@ GLenum GalFormatGetGlLinearInternalFormat(Format format) { GLenum GalFormatGetGlInternalFormat(Format format) { switch (format) { case Format::D24S8: - return GL_DEPTH24_STENCIL8; + return 0; case Format::R8G8B8: return GL_SRGB; case Format::R8G8B8A8: return GL_SRGB_ALPHA; + case Format::R32G32B32A32F: + return 0; default: return 0; } @@ -357,6 +365,8 @@ GLenum GalFormatGetGlFormat(Format format) { return GL_RGB; case Format::R8G8B8A8: return GL_RGBA; + case Format::R32G32B32A32F: + return GL_RGBA; default: return 0; } @@ -371,6 +381,8 @@ GLenum GalFormatGetGlType(Format format) { return GL_UNSIGNED_BYTE; case Format::R8G8B8A8: return GL_UNSIGNED_BYTE; + case Format::R32G32B32A32F: + return GL_FLOAT; default: return 0; } diff --git a/src/Render.cpp b/src/Render.cpp index 4fc0616..1095148 100644 --- a/src/Render.cpp +++ b/src/Render.cpp @@ -1,5 +1,7 @@ #include "Render.hpp" +#include <random> + #include <easylogging++.h> #include <optick.h> #include <RmlUi/Core.h> @@ -146,6 +148,22 @@ void Render::PrepareToRendering() { gal->GetGlobalShaderParameters()->Get<GlobalShaderParameters>()->gamma = Settings::ReadDouble("gamma", 2.2); + std::mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count()); + std::uniform_real_distribution<float> dis(-1.0f, 1.0f); + auto& ssaoKernels = gal->GetGlobalShaderParameters()->Get<GlobalShaderParameters>()->ssaoKernels; + for (auto& vec : ssaoKernels) { + vec.x = dis(rng); + vec.y = dis(rng); + vec.z = (dis(rng) + 1.0f) / 2.0f; + vec.w = 0.0f; + vec = glm::normalize(vec); + } + for (size_t i = 0; i < sizeof(ssaoKernels) / sizeof(*ssaoKernels); i++) { + float scale = i / 64.0f; + scale = glm::mix(0.1f, 1.0f, scale * scale); + ssaoKernels[i] *= scale; + } + std::string vertexSource, pixelSource; { auto vertAsset = AssetManager::GetAssetByAssetName("/altcraft/shaders/vert/fbo"); diff --git a/src/RenderConfigs.cpp b/src/RenderConfigs.cpp index aad2c59..d185c79 100644 --- a/src/RenderConfigs.cpp +++ b/src/RenderConfigs.cpp @@ -1,5 +1,8 @@ #include "RenderConfigs.hpp" +#include <chrono> +#include <random> + #include "AssetManager.hpp" std::string LoadShaderCode(std::string_view assetPath) { @@ -85,7 +88,7 @@ Gbuffer::Gbuffer(size_t geomW, size_t geomH, size_t lightW, size_t lightH) { colorConf->SetMaxFilter(Gal::Filtering::Bilinear); color = gal->BuildTexture(colorConf); - auto normalConf = gal->CreateTexture2DConfig(geomW, geomH, Gal::Format::R8G8B8); + auto normalConf = gal->CreateTexture2DConfig(geomW, geomH, Gal::Format::R32G32B32A32F); normalConf->SetMinFilter(Gal::Filtering::Bilinear); normalConf->SetMaxFilter(Gal::Filtering::Bilinear); normal = gal->BuildTexture(normalConf); @@ -105,30 +108,69 @@ Gbuffer::Gbuffer(size_t geomW, size_t geomH, size_t lightW, size_t lightH) { dsConf->SetMaxFilter(Gal::Filtering::Bilinear); depthStencil = gal->BuildTexture(dsConf); + auto worldPosConf = gal->CreateTexture2DConfig(geomW, geomH, Gal::Format::R32G32B32A32F); + worldPosConf->SetMinFilter(Gal::Filtering::Bilinear); + worldPosConf->SetMaxFilter(Gal::Filtering::Bilinear); + worldPos = gal->BuildTexture(worldPosConf); + auto geomFbConf = gal->CreateFramebufferConfig(); + geomFbConf->SetDepthStencil(depthStencil); geomFbConf->SetTexture(0, color); geomFbConf->SetTexture(1, normal); - geomFbConf->SetTexture(2, addColor); - geomFbConf->SetTexture(3, light); - geomFbConf->SetDepthStencil(depthStencil); + geomFbConf->SetTexture(2, worldPos); + geomFbConf->SetTexture(3, addColor); + geomFbConf->SetTexture(4, light); geomFramebuffer = gal->BuildFramebuffer(geomFbConf); geomFramebuffer->SetViewport(0, 0, geomW, geomH); - std::vector<std::pair<std::string_view, std::shared_ptr<Gal::Texture>>> lightingTexture = { - {"color", color}, - {"addColor", addColor}, + 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}, - {"light", light}, - {"depthStencil", depthStencil}, + {"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, Gal::Type>> lightingParameters = { {"renderBuff", Gal::Type::Int32}, }; + std::vector<std::pair<std::string_view, std::shared_ptr<Gal::Texture>>> lightingTextures = { + {"depthStencil", depthStencil}, + {"color", color}, + {"normal", normal}, + {"worldPos", worldPos}, + {"addColor", addColor}, + {"light", light}, + {"ssao", ssaoPass->GetResultTexture()}, + }; + lightingPass = std::make_unique<PostProcess>(LoadPixelShader("/altcraft/shaders/frag/light"), - lightingTexture, + lightingTextures, lightingParameters, lightW, lightH, diff --git a/src/RenderConfigs.hpp b/src/RenderConfigs.hpp index 1e6a978..ef4c97d 100644 --- a/src/RenderConfigs.hpp +++ b/src/RenderConfigs.hpp @@ -4,7 +4,12 @@ struct GlobalShaderParameters { glm::mat4 projView; + glm::mat4 proj; + glm::mat4 view; glm::uvec2 viewportSize; + glm::uint32 paddingFA = 0xFAAFFAFA; + glm::uint32 paddingFB = 0xFBFBFBFB; + glm::vec4 ssaoKernels[64]; glm::float32 globalTime; glm::float32 dayTime; glm::float32 gamma; @@ -55,12 +60,15 @@ public: }; class Gbuffer { + std::shared_ptr<Gal::Texture> ssaoNoise; + std::unique_ptr<PostProcess> ssaoPass; std::unique_ptr<PostProcess> lightingPass; + 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> worldPos; //RGB - viewSpaceWorldPos std::shared_ptr<Gal::Texture> addColor; //RGB - addColor std::shared_ptr<Gal::Texture> light; //R - faceLight, G - skyLight, B - unused - std::shared_ptr<Gal::Texture> depthStencil; std::shared_ptr<Gal::Framebuffer> geomFramebuffer; public: @@ -75,16 +83,18 @@ public: } void Render() { + ssaoPass->Render(); lightingPass->Render(); } void Clear() { geomFramebuffer->Clear(); + ssaoPass->Clear(); lightingPass->Clear(); } int GetMaxRenderBuffers() { - return 5; + return 7; } void SetRenderBuff(int renderBuff) { diff --git a/src/RendererSectionData.cpp b/src/RendererSectionData.cpp index 0ac901e..45d242c 100644 --- a/src/RendererSectionData.cpp +++ b/src/RendererSectionData.cpp @@ -58,7 +58,7 @@ void AddFacesByBlockModel(RendererSectionData &data, const BlockFaces &model, co vertexData.positions[2] = transformed * glm::vec4(1, 0, 1, 1); vertexData.positions[3] = transformed * glm::vec4(1, 0, 0, 1); - vertexData.normal = normal; + vertexData.normal = model.transform * face.transform * glm::vec4(normal, 1.0f); vertexData.uvs[0] = TransformTextureCoord(face.texture, glm::vec2(0, 0), face.frames); vertexData.uvs[1] = TransformTextureCoord(face.texture, glm::vec2(1, 0), face.frames); diff --git a/src/RendererWorld.cpp b/src/RendererWorld.cpp index 846788b..2108ba6 100644 --- a/src/RendererWorld.cpp +++ b/src/RendererWorld.cpp @@ -278,15 +278,20 @@ RendererWorld::~RendererWorld() { void RendererWorld::Render(float screenRatio) { OPTICK_EVENT(); //Common - glm::mat4 projection = glm::perspective( + + auto globalSpb = Gal::GetImplementation()->GetGlobalShaderParameters(); + + auto& projection = globalSpb->Get<GlobalShaderParameters>()->proj; + projection = glm::perspective( glm::radians(70.0f), screenRatio, 0.1f, 10000000.0f ); - glm::mat4 view = GetGameState()->GetViewMatrix(); - glm::mat4 projView = projection * view; - auto globalSpb = Gal::GetImplementation()->GetGlobalShaderParameters(); - globalSpb->Get<GlobalShaderParameters>()->projView = projView; + auto& view = globalSpb->Get<GlobalShaderParameters>()->view; + view = GetGameState()->GetViewMatrix(); + + auto& projView = globalSpb->Get<GlobalShaderParameters>()->projView; + projView = projection * view; //Render Entities constexpr size_t entitiesVerticesCount = 240; |