]> git.lizzy.rs Git - minetest.git/commitdiff
Allow saturation to be controlled by the server. (#13075)
authorlhofhansl <larsh@apache.org>
Mon, 26 Dec 2022 00:15:32 +0000 (16:15 -0800)
committerGitHub <noreply@github.com>
Mon, 26 Dec 2022 00:15:32 +0000 (16:15 -0800)
builtin/settingtypes.txt
doc/lua_api.txt
games/devtest/mods/util_commands/init.lua
src/client/game.cpp
src/defaultsettings.cpp
src/lighting.h
src/network/clientpackethandler.cpp
src/network/networkprotocol.h
src/script/lua_api/l_object.cpp
src/server.cpp

index d2b093cc3c5e69ce4409b79b8fb44ecb43bda8a7..b3398c831501adfc50710f6b866724a26c3354e1 100644 (file)
@@ -365,15 +365,6 @@ enable_shaders (Shaders) bool true
 #    enhanced, highlights and shadows are gradually compressed.
 tone_mapping (Filmic tone mapping) bool false
 
-#    Adjust the saturation (or vividness) of the scene
-#    Values
-#    < 1.0 decrease saturation
-#    > 1.0 increase saturation
-#    1.0 = unchanged saturation
-#    0.0 = black and white
-#    (Tone mapping needs to be enabled.)
-saturation (Saturation) float 1.0 0.0 5.0
-
 [**Waving Nodes]
 
 #    Set to true to enable waving leaves.
index b41189e9c6c999a2ce57facf8bd33ea05d78c140..8dfb991b7a909e8da9a8f61fa5930475faf848c2 100644 (file)
@@ -7465,6 +7465,9 @@ child will follow movement and rotation of that bone.
     * Resource intensive - use sparsely
 * `set_lighting(light_definition)`: sets lighting for the player
     * `light_definition` is a table with the following optional fields:
+      * `saturation` sets the saturation (vividness).
+          values > 1 increase the saturation
+          values in [0,1) decrease the saturation
       * `shadows` is a table that controls ambient shadows
         * `intensity` sets the intensity of the shadows from 0 (no shadows, default) to 1 (blackness)
 * `get_lighting()`: returns the current state of lighting for the player.
index 8d12d27f03f87d708fcaf8b50a765bd9f75f7246..4702cc5562395f2f124ad063de4dfbeb6a151d3b 100644 (file)
@@ -223,3 +223,12 @@ core.register_chatcommand("set_shadow", {
         minetest.get_player_by_name(player_name):set_lighting({shadows = { intensity = shadow_intensity} })
     end
 })
+
+core.register_chatcommand("set_saturation", {
+    params = "<saturation>",
+    description = "Set the saturation for current player.",
+    func = function(player_name, param)
+        local saturation = tonumber(param)
+        minetest.get_player_by_name(player_name):set_lighting({saturation = saturation })
+    end
+})
index 486ab41a36093b5680b4fa6b21302fb814f274ea..078998bf77e347df8cf98815a2efc50034870576 100644 (file)
@@ -436,7 +436,6 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
        float m_bloom_strength;
        CachedPixelShaderSetting<float> m_bloom_radius_pixel;
        float m_bloom_radius;
-       float m_saturation;
        CachedPixelShaderSetting<float> m_saturation_pixel;
 
 public:
@@ -452,8 +451,6 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
                        m_bloom_strength = RenderingEngine::BASE_BLOOM_STRENGTH * g_settings->getFloat("bloom_strength_factor", 0.1f, 10.0f);
                if (name == "bloom_radius")
                        m_bloom_radius = g_settings->getFloat("bloom_radius", 0.1f, 8.0f);
-               if (name == "saturation")
-                       m_saturation = g_settings->getFloat("saturation", 0.0f, 5.0f);
        }
 
        static void settingsCallback(const std::string &name, void *userdata)
@@ -503,7 +500,6 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
                m_bloom_intensity = g_settings->getFloat("bloom_intensity", 0.01f, 1.0f);
                m_bloom_strength = RenderingEngine::BASE_BLOOM_STRENGTH * g_settings->getFloat("bloom_strength_factor", 0.1f, 10.0f);
                m_bloom_radius = g_settings->getFloat("bloom_radius", 0.1f, 8.0f);
-               m_saturation = g_settings->getFloat("saturation", 0.0f, 5.0f);
        }
 
        ~GameGlobalShaderConstantSetter()
@@ -591,7 +587,8 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
                        m_bloom_radius_pixel.set(&m_bloom_radius, services);
                        m_bloom_strength_pixel.set(&m_bloom_strength, services);
                }
-               m_saturation_pixel.set(&m_saturation, services);
+               float saturation = m_client->getEnv().getLocalPlayer()->getLighting().saturation;
+               m_saturation_pixel.set(&saturation, services);
        }
 
        void onSetMaterial(const video::SMaterial &material)
index f2525bf754d03807e4f23b57cb4ffe069401b537..e8170788ac52563a48ac514cebcdf3e6ecce44c9 100644 (file)
@@ -281,7 +281,6 @@ void set_default_settings()
        settings->setDefault("bloom_strength_factor", "1.0");
        settings->setDefault("bloom_intensity", "0.05");
        settings->setDefault("bloom_radius", "1");
-       settings->setDefault("saturation", "1.0");
 
        // Effects Shadows
        settings->setDefault("enable_dynamic_shadows", "false");
index e0d9cee0969e63a8f387ec29d3b6727411fdf6c1..6c837568b618a8ac868d2f5ee643d7b95f7f7477 100644 (file)
@@ -24,4 +24,5 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 struct Lighting
 {
     float shadow_intensity {0.0f};
+    float saturation {1.0f};
 };
index 9044e6e35584fe04984c63ad12d5c45c57650337..a98fa0733c3b82e391e1dbcdbb43f202e6441806 100644 (file)
@@ -1764,4 +1764,6 @@ void Client::handleCommand_SetLighting(NetworkPacket *pkt)
 
        if (pkt->getRemainingBytes() >= 4)
                *pkt >> lighting.shadow_intensity;
+       if (pkt->getRemainingBytes() >= 4)
+               *pkt >> lighting.saturation;
 }
index a1cd926df17612e41ee3365a71abf521e4055758..01e65ef68b77dce6ac39503d4ae581677ca20ed1 100644 (file)
@@ -830,6 +830,7 @@ enum ToClientCommand
        TOCLIENT_SET_LIGHTING = 0x63,
        /*
                f32 shadow_intensity
+               f32 saturation
        */
 
        TOCLIENT_NUM_MSG_TYPES = 0x64,
index 4b9beaec3e95706af806aa1ce6b6c0c7bb294d0d..0538e15d55914057f1c9384e2415f56f5ff03c50 100644 (file)
@@ -2294,8 +2294,9 @@ int ObjectRef::l_set_lighting(lua_State *L)
        Lighting lighting = player->getLighting();
        lua_getfield(L, 2, "shadows");
        if (lua_istable(L, -1)) {
-               lighting.shadow_intensity = getfloatfield_default(L, -1, "intensity",    lighting.shadow_intensity);
+               lighting.shadow_intensity = getfloatfield_default(L, -1, "intensity", lighting.shadow_intensity);
        }
+       lighting.saturation = getfloatfield_default(L, 2, "saturation", lighting.saturation);
        lua_pop(L, -1);
 
        getServer(L)->setLighting(player, lighting);
@@ -2318,6 +2319,8 @@ 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_pushnumber(L, lighting.saturation);
+       lua_setfield(L, -2, "saturation");
        return 1;
 }
 
index 5c3496569374145112a5ff32572f49e5890aa7a3..ee08b45fd792291270c5722397f863e56d3a8acd 100644 (file)
@@ -1864,6 +1864,7 @@ void Server::SendSetLighting(session_t peer_id, const Lighting &lighting)
                        4, peer_id);
 
        pkt << lighting.shadow_intensity;
+       pkt << lighting.saturation;
 
        Send(&pkt);
 }