From ded1b0983842c814f542bae95308feccea2f0ce6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gef=C3=BCllte=20Taubenbrust?= <72752000+GefullteTaubenbrust2@users.noreply.github.com> Date: Thu, 9 May 2024 18:38:29 +0200 Subject: [PATCH] Add artificial light control --- client/shaders/nodes_shader/opengl_vertex.glsl | 4 ++-- client/shaders/object_shader/opengl_vertex.glsl | 4 ++-- src/client/game.cpp | 3 +++ src/lighting.h | 3 +++ src/network/clientpackethandler.cpp | 2 ++ src/network/networkprotocol.h | 1 + src/script/lua_api/l_object.cpp | 9 +++++++++ src/server.cpp | 2 ++ 8 files changed, 24 insertions(+), 4 deletions(-) diff --git a/client/shaders/nodes_shader/opengl_vertex.glsl b/client/shaders/nodes_shader/opengl_vertex.glsl index d96164d76..2c1e5981b 100644 --- a/client/shaders/nodes_shader/opengl_vertex.glsl +++ b/client/shaders/nodes_shader/opengl_vertex.glsl @@ -46,7 +46,7 @@ varying float area_enable_parallax; varying highp vec3 eyeVec; varying float nightRatio; // Color of the light emitted by the light sources. -const vec3 artificialLight = vec3(1.04, 1.04, 1.04); +uniform vec3 artificialLight; const float e = 2.718281828459; const float BS = 10.0; uniform float xyPerspectiveBias0; @@ -211,7 +211,7 @@ void main(void) // The alpha gives the ratio of sunlight in the incoming light. nightRatio = 1.0 - color.a; color.rgb = color.rgb * (color.a * dayLight.rgb + - nightRatio * artificialLight.rgb) * 2.0; + nightRatio * 2.0 * artificialLight.rgb) * 2.0; color.a = 1.0; // Emphase blue a bit in darker places diff --git a/client/shaders/object_shader/opengl_vertex.glsl b/client/shaders/object_shader/opengl_vertex.glsl index d5a434da5..53f487a56 100644 --- a/client/shaders/object_shader/opengl_vertex.glsl +++ b/client/shaders/object_shader/opengl_vertex.glsl @@ -33,7 +33,7 @@ centroid varying vec2 varTexCoord; varying highp vec3 eyeVec; varying float nightRatio; // Color of the light emitted by the light sources. -const vec3 artificialLight = vec3(1.04, 1.04, 1.04); +uniform vec3 artificialLight; varying float vIDiff; const float e = 2.718281828459; const float BS = 10.0; @@ -120,7 +120,7 @@ void main(void) // The alpha gives the ratio of sunlight in the incoming light. nightRatio = 1.0 - color.a; color.rgb = color.rgb * (color.a * dayLight.rgb + - nightRatio * artificialLight.rgb) * 2.0; + nightRatio * 2.0 * artificialLight.rgb) * 2.0; color.a = 1.0; // Emphase blue a bit in darker places diff --git a/src/client/game.cpp b/src/client/game.cpp index 01739ff25..8c1fb407f 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -381,6 +381,7 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter m_animation_timer_delta_vertex{"animationTimerDelta"}; CachedPixelShaderSetting m_animation_timer_delta_pixel{"animationTimerDelta"}; + CachedPixelShaderSetting m_artificial_light{ "artificialLight" }; CachedPixelShaderSetting m_day_light{"dayLight"}; CachedPixelShaderSetting m_minimap_yaw{"yawVec"}; CachedPixelShaderSetting m_camera_offset_pixel{"cameraOffset"}; @@ -525,6 +526,8 @@ public: const auto &lighting = m_client->getEnv().getLocalPlayer()->getLighting(); float saturation = lighting.saturation; m_saturation_pixel.set(&saturation, services); + video::SColorf artificial_light = lighting.artificial_light_color; + m_artificial_light.set(artificial_light, services); if (m_volumetric_light_enabled) { // Map directional light to screen space diff --git a/src/lighting.h b/src/lighting.h index 262a48b5d..2a324cff4 100644 --- a/src/lighting.h +++ b/src/lighting.h @@ -18,7 +18,9 @@ with this program; if not, write to the Free Software Foundation, Inc., */ #pragma once +#include +using namespace irr; /** * Parameters for automatic exposure compensation @@ -54,4 +56,5 @@ struct Lighting float shadow_intensity {0.0f}; float saturation {1.0f}; float volumetric_light_strength {0.0f}; + video::SColor artificial_light_color{ 133, 133, 133, 255 }; }; diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp index 90f2bed5b..9fb0c56ad 100644 --- a/src/network/clientpackethandler.cpp +++ b/src/network/clientpackethandler.cpp @@ -1815,4 +1815,6 @@ void Client::handleCommand_SetLighting(NetworkPacket *pkt) } if (pkt->getRemainingBytes() >= 4) *pkt >> lighting.volumetric_light_strength; + if (pkt->getRemainingBytes() >= 4) + *pkt >> lighting.artificial_light_color; } diff --git a/src/network/networkprotocol.h b/src/network/networkprotocol.h index 4d9900ea0..fbe8eb8be 100644 --- a/src/network/networkprotocol.h +++ b/src/network/networkprotocol.h @@ -224,6 +224,7 @@ with this program; if not, write to the Free Software Foundation, Inc., Add TOCLIENT_MOVE_PLAYER_REL Move default minimap from client-side C++ to server-side builtin Lua [scheduled bump for 5.9.0] + Add artificial light color packet */ #define LATEST_PROTOCOL_VERSION 44 diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index bc5ddba5c..1246ae104 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -2528,6 +2528,13 @@ int ObjectRef::l_set_lighting(lua_State *L) if (!lua_isnoneornil(L, 2)) { luaL_checktype(L, 2, LUA_TTABLE); lighting = player->getLighting(); + + lua_getfield(L, 2, "artificial_light"); + if (!lua_isnil(L, -1)) { + read_color(L, -1, &lighting.artificial_light_color); + } + lua_pop(L, 1); // artificial_light + lua_getfield(L, 2, "shadows"); if (lua_istable(L, -1)) { getfloatfield(L, -1, "intensity", lighting.shadow_intensity); @@ -2571,6 +2578,8 @@ int ObjectRef::l_get_lighting(lua_State *L) const Lighting &lighting = player->getLighting(); lua_newtable(L); // result + push_ARGB8(L, lighting.artificial_light_color); + lua_setfield(L, -2, "artificial_light"); lua_newtable(L); // "shadows" lua_pushnumber(L, lighting.shadow_intensity); lua_setfield(L, -2, "intensity"); diff --git a/src/server.cpp b/src/server.cpp index 6e12017bc..8ae194988 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1895,6 +1895,8 @@ void Server::SendSetLighting(session_t peer_id, const Lighting &lighting) pkt << lighting.volumetric_light_strength; + pkt << lighting.artificial_light_color; + Send(&pkt); }