diff --git a/doc/lua_api.md b/doc/lua_api.md index 8c3bbf850..fd190761b 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -8395,9 +8395,9 @@ child will follow movement and rotation of that bone. * `set_lighting(light_definition)`: sets lighting for the player * Passing no arguments resets lighting to its default values. * `light_definition` is a table with the following optional fields: - * `ambient_light` is a ColorSpec controlling lightness & color of ambient light; alpha must be 255 + * `ambient_light` is a ColorSpec controlling lightness & color of ambient light; alpha is ignored (always set to 255) (global lighting; default: `{a = 255, r = 0, g = 0, b = 0}` / last set value). - * It works only if 'enable_shaders' setting is set to true. + * It works only if 'enable_shaders' is set to true. * `saturation` sets the saturation (vividness; default: `1.0`). * values > 1 increase the saturation * values in [0,1] decrease the saturation diff --git a/games/devtest/mods/lighting/init.lua b/games/devtest/mods/lighting/init.lua index 7b4392fb8..182c05c4b 100644 --- a/games/devtest/mods/lighting/init.lua +++ b/games/devtest/mods/lighting/init.lua @@ -14,6 +14,14 @@ local lighting_sections = { {n = "speed_bright_dark", d = "Dark scene adaptation speed", min = -10, max = 10, type="log2"}, {n = "center_weight_power", d = "Power factor for center-weighting", min = 0.1, max = 10}, } + }, + { + n = "ambient_light", d = "Ambient Light", + entries = { + {n = "r", d = "Red", min = 0, max = 255}, + {n = "g", d = "Green", min = 0, max = 255}, + {n = "b", d = "Blue", min = 0, max = 255} + } } } @@ -61,7 +69,7 @@ minetest.register_chatcommand("set_lighting", { local form = { "formspec_version[2]", - "size[15,30]", + "size[15,32]", "position[0.99,0.15]", "anchor[1,0]", "padding[0.05,0.1]", @@ -137,4 +145,4 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) player:hud_change(hud_id, "text", debug_value) player:set_lighting(lighting) -end) \ No newline at end of file +end) diff --git a/src/client/clientenvironment.cpp b/src/client/clientenvironment.cpp index fc0e20daa..7e9fb26d2 100644 --- a/src/client/clientenvironment.cpp +++ b/src/client/clientenvironment.cpp @@ -248,14 +248,6 @@ void ClientEnvironment::step(float dtime) if (m_client->modsLoaded()) m_script->environment_step(dtime); - // Update the ambient light - auto new_ambient_light_clr = getLocalPlayer()->getLighting().ambient_light; - - bool enable_shaders = g_settings->getBool("enable_shaders"); - - if (enable_shaders && (new_ambient_light_clr != m_ambient_light)) - m_ambient_light = new_ambient_light_clr; - // Update lighting on local player (used for wield item) u32 day_night_ratio = getDayNightRatio(); { @@ -273,8 +265,8 @@ void ClientEnvironment::step(float dtime) video::SColor ambient_light(255, 0, 0, 0); - if (enable_shaders) - ambient_light = m_ambient_light; + if (g_settings->getBool("enable_shaders")) + ambient_light = lplayer->getLighting().ambient_light; final_color_blend(&lplayer->light_color, light, day_night_ratio, ambient_light); } diff --git a/src/client/clientenvironment.h b/src/client/clientenvironment.h index 3b56f07a4..99276a2a5 100644 --- a/src/client/clientenvironment.h +++ b/src/client/clientenvironment.h @@ -149,9 +149,6 @@ class ClientEnvironment : public Environment void updateFrameTime(bool is_paused); u64 getFrameTime() const { return m_frame_time; } u64 getFrameTimeDelta() const { return m_frame_dtime; } - - video::SColor getAmbientLight() const { return m_ambient_light; } - private: ClientMap *m_map; LocalPlayer *m_local_player = nullptr; @@ -167,6 +164,4 @@ class ClientEnvironment : public Environment u64 m_frame_time = 0; u64 m_frame_dtime = 0; u64 m_frame_time_pause_accumulator = 0; - // Note: Alpha should always be 255. - video::SColor m_ambient_light {255, 0, 0, 0}; }; diff --git a/src/client/game.cpp b/src/client/game.cpp index 773521717..f38282403 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -474,7 +474,9 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter get_sunlight_color(&sunlight, daynight_ratio); m_day_light.set(sunlight, services); - video::SColorf ambient_light_f(m_client->getEnv().getAmbientLight()); + auto lighting = m_client->getEnv().getLocalPlayer()->getLighting(); + + video::SColorf ambient_light_f(lighting.ambient_light); m_ambient_light.set(ambient_light_f, services); u32 animation_timer = m_client->getEnv().getFrameTime() % 1000000; @@ -508,8 +510,6 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter m_texel_size0_vertex.set(m_texel_size0, services); m_texel_size0_pixel.set(m_texel_size0, services); - auto lighting = m_client->getEnv().getLocalPlayer()->getLighting(); - const AutoExposure &exposure_params = lighting.exposure; std::array exposure_buffer = { std::pow(2.0f, exposure_params.luminance_min), @@ -1448,7 +1448,7 @@ void Game::copyServerClientCache() { // It would be possible to let the client directly read the media files // from where the server knows they are. But aside from being more complicated - // it would also *not* fill the media cache and cause slower joining of + // it would also *not* fill the media cache and cause slower joining of // remote servers. // (Imagine that you launch a game once locally and then connect to a server.) diff --git a/src/client/particles.cpp b/src/client/particles.cpp index 638505846..e5e654518 100644 --- a/src/client/particles.cpp +++ b/src/client/particles.cpp @@ -35,6 +35,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "client.h" #include "settings.h" #include "profiler.h" +#include "client/mapblock_mesh.h" ClientParticleTexture::ClientParticleTexture(const ServerParticleTexture& p, ITextureSource *tsrc) { @@ -186,10 +187,15 @@ video::SColor Particle::updateLight(ClientEnvironment *env) light = blend_light(env->getDayNightRatio(), LIGHT_SUN, 0); u8 m_light = decode_light(light + m_p.glow); + + video::SColor light_color{0xFFFFFFFF}; + + final_color_blend(&light_color, m_light, env->getDayNightRatio(), + env->getLocalPlayer()->getLighting().ambient_light); return video::SColor(255, - m_light * m_base_color.getRed() / 255, - m_light * m_base_color.getGreen() / 255, - m_light * m_base_color.getBlue() / 255); + light_color.getRed() * m_base_color.getRed() / 255, + light_color.getGreen() * m_base_color.getGreen() / 255, + light_color.getBlue() * m_base_color.getBlue() / 255); } void Particle::updateVertices(ClientEnvironment *env, video::SColor color) diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp index e8f16b63f..4884e177c 100644 --- a/src/network/clientpackethandler.cpp +++ b/src/network/clientpackethandler.cpp @@ -1826,5 +1826,4 @@ void Client::handleCommand_SetLighting(NetworkPacket *pkt) if (pkt->getRemainingBytes() < 4) return; *pkt >> lighting.ambient_light; - lighting.ambient_light.setAlpha(255); // alpha should always be 255 } diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index 327ea3b52..1c37fb09e 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -2539,8 +2539,7 @@ int ObjectRef::l_set_lighting(lua_State *L) lua_getfield(L, 2, "ambient_light"); if (!lua_isnil(L, -1)) { read_color(L, -1, &lighting.ambient_light); - if (lighting.ambient_light.getAlpha() != 255) - throw LuaError("ambient light alpha must be 255"); + lighting.ambient_light.setAlpha(255); // alpha should always be 255 } lua_pop(L, 1); // ambient light @@ -2585,6 +2584,16 @@ int ObjectRef::l_get_lighting(lua_State *L) lua_pushnumber(L, lighting.shadow_intensity); lua_setfield(L, -2, "intensity"); lua_setfield(L, -2, "shadows"); + lua_newtable(L); // "ambient_light" + lua_pushnumber(L, lighting.ambient_light.getRed()); + lua_setfield(L, -2, "r"); + lua_pushnumber(L, lighting.ambient_light.getGreen()); + lua_setfield(L, -2, "g"); + lua_pushnumber(L, lighting.ambient_light.getBlue()); + lua_setfield(L, -2, "b"); + lua_pushnumber(L, 255); + lua_setfield(L, -2, "a"); + lua_setfield(L, -2, "ambient_light"); lua_pushnumber(L, lighting.saturation); lua_setfield(L, -2, "saturation"); lua_newtable(L); // "exposure"