diff --git a/resources/shaders/fog.f.glsl b/resources/shaders/fog.f.glsl index cf5ba69da..83accec7c 100644 --- a/resources/shaders/fog.f.glsl +++ b/resources/shaders/fog.f.glsl @@ -2,9 +2,19 @@ uniform vec4 u_fogColor; +uniform float u_time; + vec4 fog(vec4 color, float fogCoord, float fogStart, float fogEnd) { float fog = clamp((fogEnd - fogCoord) / (fogEnd - fogStart), 0.0, 1.0); - return mix(u_fogColor, color, fog); + const float pi = 3.1415927; + + float sunlight = clamp((1 + sin(2 * pi * u_time) * 4.0), 0.0, 1.0); + + float red = clamp(sunlight - (1 - u_fogColor.r), 0.0, u_fogColor.r); + float green = clamp(sunlight - (1 - u_fogColor.g), 0.0, u_fogColor.g); + float blue = clamp(sunlight - (1 - u_fogColor.b), 0.0, u_fogColor.b); + + return mix(vec4(red, green, blue, u_fogColor.a), color, fog); } diff --git a/resources/shaders/game.f.glsl b/resources/shaders/game.f.glsl index be92a4452..ac55c530d 100644 --- a/resources/shaders/game.f.glsl +++ b/resources/shaders/game.f.glsl @@ -10,8 +10,11 @@ varying float v_blockFace; varying float v_dist; uniform int u_renderDistance; + uniform sampler2D u_tex; +uniform float u_time; + // Get light color vec4 light(vec4 color, vec3 lightColor, vec4 lightPosition, float ambientIntensity, float diffuseIntensity); @@ -50,6 +53,10 @@ void main() { float minBrightness = 2.0 / 16.0; if (lightCheck != -1.) { + const float pi = 3.1415927; + + float sunlight = clamp(v_lightValue.x * 0.5 * (1 + sin(2 * pi * u_time) * 4.0), 3, 15); + float ambientIntensity = max(max(v_lightValue.x, v_lightValue.y) / 16.0, minBrightness); float diffuseIntensity = max(v_lightValue.x, v_lightValue.y) / 32.0; @@ -64,7 +71,9 @@ void main() { if (blockFace == 2. || blockFace == 3.) ambientIntensity = max(ambientIntensity * 0.9, minBrightness); - color = light(color, vec3(1.0, 1.0, 1.0), v_coord3d, ambientIntensity, diffuseIntensity); + float lightval = clamp(sunlight / 16.0, v_lightValue.y / 16.0, 1.0); + + color = light(color, vec3(lightval, lightval, lightval), v_coord3d, ambientIntensity, diffuseIntensity); } color.rgb *= v_ambientOcclusion; diff --git a/source/client/graphics/CelestialObject.cpp b/source/client/graphics/CelestialObject.cpp index 06a1228e5..9432744e8 100644 --- a/source/client/graphics/CelestialObject.cpp +++ b/source/client/graphics/CelestialObject.cpp @@ -58,7 +58,7 @@ void CelestialObject::updateVertexBuffer() const { } void CelestialObject::draw(gk::RenderTarget &target, gk::RenderStates states) const { - states.transform.rotate(fmod(gk::GameClock::getInstance().getTicks(true) / 1000.f, 360), {0, 1, 0}); + states.transform.rotate(-fmod(gk::GameClock::getInstance().getTicks() * 4 / 1000.f, 360), {0, 1, 0}); states.transform *= getTransform(); states.vertexAttributes = VertexAttribute::All; diff --git a/source/client/graphics/Skybox.cpp b/source/client/graphics/Skybox.cpp index b9f092980..4ab173b45 100644 --- a/source/client/graphics/Skybox.cpp +++ b/source/client/graphics/Skybox.cpp @@ -29,10 +29,10 @@ Skybox::Skybox(gk::Camera &camera) : m_camera(camera) { m_sun.setColor(gk::Color::Yellow); - m_sun.setPosition(150, -10, 0); + m_sun.setPosition(150, -10, -10); m_moon.setColor(gk::Color::White); - m_moon.setPosition(-150, -10, 0); + m_moon.setPosition(-150, -10, -10); } void Skybox::draw(gk::RenderTarget &target, gk::RenderStates states) const { diff --git a/source/client/states/GameState.cpp b/source/client/states/GameState.cpp index a289e8c64..659da0c82 100644 --- a/source/client/states/GameState.cpp +++ b/source/client/states/GameState.cpp @@ -24,6 +24,8 @@ * * ===================================================================================== */ +#include +#include #include #include @@ -207,10 +209,23 @@ void GameState::onGuiScaleChanged(const GuiScaleChangedEvent &event) { } void GameState::draw(gk::RenderTarget &target, gk::RenderStates states) const { - // FIXME: This uniform is not used anymore since water/leaves effects are disabled - // gk::Shader::bind(&m_shader); - // m_shader.setUniform("u_time", gk::GameClock::getInstance().getTicks()); - // gk::Shader::bind(nullptr); + float time = std::fmod(gk::GameClock::getInstance().getTicks() * 4.f / 1000.f, 360.f) / 360.f; + + gk::Shader::bind(&m_shader); + m_shader.setUniform("u_time", time); + gk::Shader::bind(nullptr); + + if (m_world.sky()) { + const float pi = 3.1415927f; + float sunlight = std::clamp(0.5f + std::sin(2 * pi * time) * 2.0f, 0.0f, 1.0f); + + gk::Color skyColor = m_world.sky()->color(); + float red = std::clamp(sunlight - (1 - skyColor.r), 0.0f, skyColor.r); + float green = std::clamp(sunlight - (1 - skyColor.g), 0.0f, skyColor.g); + float blue = std::clamp(sunlight - (1 - skyColor.b), 0.0f, skyColor.b); + + glClearColor(red, green, blue, 1.0f); + } m_fbo.begin(); diff --git a/source/client/world/ClientWorld.cpp b/source/client/world/ClientWorld.cpp index 398303e0e..cba91c1af 100644 --- a/source/client/world/ClientWorld.cpp +++ b/source/client/world/ClientWorld.cpp @@ -112,8 +112,7 @@ void ClientWorld::changeDimension(u16 dimensionID) { const Sky &sky = Registry::getInstance().getSkyFromStringID(dimension.sky()); m_sky = &sky; - glCheck(glClearColor(sky.color().r, sky.color().g, sky.color().b, sky.color().a)); - + // glCheck(glClearColor(sky.color().r, sky.color().g, sky.color().b, sky.color().a)); } void ClientWorld::receiveChunkData(Network::Packet &packet) { diff --git a/source/client/world/ClientWorld.hpp b/source/client/world/ClientWorld.hpp index d9aecc13b..0d57ffe67 100644 --- a/source/client/world/ClientWorld.hpp +++ b/source/client/world/ClientWorld.hpp @@ -68,6 +68,8 @@ class ClientWorld : public World, public gk::Drawable { std::size_t loadedChunkCount() const { return m_chunks.size(); } + const Sky *sky() const { return m_sky; } + private: void createChunkNeighbours(ClientChunk *chunk);