From ca69b55875a44c5e1bd8083f54e622db561de967 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Mon, 28 Oct 2024 11:33:46 +0300 Subject: [PATCH] add 'u_lightDir' to main shader --- src/graphics/render/Skybox.cpp | 3 ++- src/graphics/render/Skybox.hpp | 6 ++++++ src/graphics/render/WorldRenderer.cpp | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/graphics/render/Skybox.cpp b/src/graphics/render/Skybox.cpp index 420f0ec7..38f8f55d 100644 --- a/src/graphics/render/Skybox.cpp +++ b/src/graphics/render/Skybox.cpp @@ -180,10 +180,11 @@ void Skybox::refresh(const DrawContext& pctx, float t, float mie, uint quality) }; t *= M_PI*2.0f; + lightDir = glm::normalize(glm::vec3(sin(t), -cos(t), 0.0f)); shader->uniform1i("u_quality", quality); shader->uniform1f("u_mie", mie); shader->uniform1f("u_fog", mie - 1.0f); - shader->uniform3f("u_lightDir", glm::normalize(glm::vec3(sin(t), -cos(t), 0.0f))); + shader->uniform3f("u_lightDir", lightDir); for (uint face = 0; face < 6; face++) { glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, cubemap->getId(), 0); shader->uniform3f("u_xaxis", xaxs[face]); diff --git a/src/graphics/render/Skybox.hpp b/src/graphics/render/Skybox.hpp index 01bffab7..c0635f90 100644 --- a/src/graphics/render/Skybox.hpp +++ b/src/graphics/render/Skybox.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "typedefs.hpp" #include "maths/fastmaths.hpp" @@ -27,6 +28,7 @@ class Skybox { Shader* shader; bool ready = false; FastRandom random; + glm::vec3 lightDir; std::unique_ptr mesh; std::unique_ptr batch3d; @@ -52,4 +54,8 @@ public: bool isReady() const { return ready; } + + const glm::vec3 getLightDir() const { + return lightDir; + } }; diff --git a/src/graphics/render/WorldRenderer.cpp b/src/graphics/render/WorldRenderer.cpp index 7b617a13..d72e72ac 100644 --- a/src/graphics/render/WorldRenderer.cpp +++ b/src/graphics/render/WorldRenderer.cpp @@ -166,6 +166,7 @@ void WorldRenderer::setupWorldShader( shader->uniform1f("u_fogFactor", fogFactor); shader->uniform1f("u_fogCurve", settings.graphics.fogCurve.get()); shader->uniform1f("u_dayTime", level->getWorld()->getInfo().daytime); + shader->uniform2f("u_lightDir", skybox->getLightDir()); shader->uniform3f("u_cameraPos", camera.position); shader->uniform1i("u_cubemap", 1);