]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
Fix lighting of the wield mesh (#12341)
authorx2048 <codeforsmile@gmail.com>
Fri, 20 May 2022 20:33:52 +0000 (22:33 +0200)
committerGitHub <noreply@github.com>
Fri, 20 May 2022 20:33:52 +0000 (22:33 +0200)
* Assign node light to player before final color blend.
  Fixes day/night lightbank ratio for wield meshes
* Update wield mesh light when changing mesh

src/client/camera.cpp
src/client/camera.h
src/client/clientenvironment.cpp

index d1f19adb3ff08f71488cbd2fe4feccae438fa4dd..7cc9cb6e8cdc31ae19fecdc2ce92fb5f227a8bec 100644 (file)
@@ -47,7 +47,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 Camera::Camera(MapDrawControl &draw_control, Client *client, RenderingEngine *rendering_engine):
        m_draw_control(draw_control),
-       m_client(client)
+       m_client(client),
+       m_player_light_color(0xFFFFFFFF)
 {
        auto smgr = rendering_engine->get_scene_manager();
        // note: making the camera node a child of the player node
@@ -153,8 +154,10 @@ void Camera::step(f32 dtime)
        bool was_under_zero = m_wield_change_timer < 0;
        m_wield_change_timer = MYMIN(m_wield_change_timer + dtime, 0.125);
 
-       if (m_wield_change_timer >= 0 && was_under_zero)
+       if (m_wield_change_timer >= 0 && was_under_zero) {
                m_wieldnode->setItem(m_wield_item_next, m_client);
+               m_wieldnode->setNodeLightColor(m_player_light_color);
+       }
 
        if (m_view_bobbing_state != 0)
        {
@@ -555,7 +558,8 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 tool_reload_ratio)
        m_wieldnode->setPosition(wield_position);
        m_wieldnode->setRotation(wield_rotation);
 
-       m_wieldnode->setNodeLightColor(player->light_color);
+       m_player_light_color = player->light_color;
+       m_wieldnode->setNodeLightColor(m_player_light_color);
 
        // Set render distance
        updateViewingRange();
index 403d6024c9e6aedf4ad11d68bdcf4480e7fab5ef..cbf248d9756d8ccb9ee4d9731889d64e44c5e0d2 100644 (file)
@@ -264,4 +264,7 @@ class Camera
 
        std::list<Nametag *> m_nametags;
        bool m_show_nametag_backgrounds;
+
+       // Last known light color of the player
+       video::SColor m_player_light_color;
 };
index 448af36c6596e982a144d16958db7eed0ed41a65..183a95007894abccb194a449de35274b1f47d51a 100644 (file)
@@ -305,6 +305,7 @@ void ClientEnvironment::step(float dtime)
                node_at_lplayer = m_map->getNode(p);
 
                u16 light = getInteriorLight(node_at_lplayer, 0, m_client->ndef());
+               lplayer->light_color = encode_light(light, 0); // this transfers light.alpha
                final_color_blend(&lplayer->light_color, light, day_night_ratio);
        }