From fe3e69eb4029626cd7ef3f7a1c2beaec13ba7364 Mon Sep 17 00:00:00 2001 From: Danila Shutov Date: Tue, 9 Jun 2020 22:38:09 +0300 Subject: [PATCH] Fix broken coloring of wielditems (#9969) Fixes a regression that appeared in 5.3.0-dev. --- client/shaders/object_shader/opengl_fragment.glsl | 4 +++- client/shaders/object_shader/opengl_vertex.glsl | 7 ++++++- src/client/wieldmesh.cpp | 10 +++++++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/client/shaders/object_shader/opengl_fragment.glsl b/client/shaders/object_shader/opengl_fragment.glsl index 32f3e974e..0534dc049 100644 --- a/client/shaders/object_shader/opengl_fragment.glsl +++ b/client/shaders/object_shader/opengl_fragment.glsl @@ -145,8 +145,10 @@ void main(void) vec4 col = vec4(color.rgb, base.a); + col.rgb *= gl_Color.rgb; + col.rgb *= emissiveColor.rgb * vIDiff; - + #ifdef ENABLE_TONE_MAPPING col = applyToneMapping(col); #endif diff --git a/client/shaders/object_shader/opengl_vertex.glsl b/client/shaders/object_shader/opengl_vertex.glsl index 488089392..59171145f 100644 --- a/client/shaders/object_shader/opengl_vertex.glsl +++ b/client/shaders/object_shader/opengl_vertex.glsl @@ -38,7 +38,12 @@ void main(void) lightVec = sunPosition - worldPosition; eyeVec = -(gl_ModelViewMatrix * gl_Vertex).xyz; - vIDiff = directional_ambient(normalize(gl_Normal)); + + // This is intentional comparison with zero without any margin. + // If normal is not equal to zero exactly, then we assume it's a valid, just not normalized vector + vIDiff = length(gl_Normal) == 0.0 + ? 1.0 + : directional_ambient(normalize(gl_Normal)); gl_FrontColor = gl_BackColor = gl_Color; } diff --git a/src/client/wieldmesh.cpp b/src/client/wieldmesh.cpp index 997eb1b5b..8cd3e29a9 100644 --- a/src/client/wieldmesh.cpp +++ b/src/client/wieldmesh.cpp @@ -467,7 +467,11 @@ void WieldMeshSceneNode::setColor(video::SColor c) bc.getGreen() * green / 255, bc.getBlue() * blue / 255); scene::IMeshBuffer *buf = mesh->getMeshBuffer(j); - colorizeMeshBuffer(buf, &buffercolor); + + if (m_enable_shaders) + setMeshBufferColor(buf, buffercolor); + else + colorizeMeshBuffer(buf, &buffercolor); } } @@ -481,9 +485,9 @@ void WieldMeshSceneNode::setNodeLightColor(video::SColor color) video::SMaterial &material = m_meshnode->getMaterial(i); material.EmissiveColor = color; } - } else { - setColor(color); } + + setColor(color); } void WieldMeshSceneNode::render() -- 2.25.1