From 65af606729f7e3c162bf0b77a02570697f784c66 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Tue, 10 Sep 2024 18:41:57 +0200 Subject: [PATCH] Fix CAO mesh lighting with shaders disabled the 'Lighting' material flag does not have portable behavior --- src/client/content_cao.cpp | 30 +++++++++++------------------- src/client/mesh.cpp | 7 ------- src/client/mesh.h | 5 ----- 3 files changed, 11 insertions(+), 31 deletions(-) diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index 72f24dfca..b87d36c4f 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -186,6 +186,12 @@ static bool logOnce(const std::ostringstream &from, std::ostream &log_to) return true; } +static void setEmissiveColor(scene::ISceneNode *node, video::SColor color) +{ + for (u32 i = 0; i < node->getMaterialCount(); ++i) + node->getMaterial(i).EmissiveColor = color; +} + /* TestCAO */ @@ -774,8 +780,6 @@ void GenericCAO::addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr) // set vertex colors to ensure alpha is set setMeshColor(m_animated_meshnode->getMesh(), video::SColor(0xFFFFFFFF)); - setAnimatedMeshColor(m_animated_meshnode, video::SColor(0xFFFFFFFF)); - setSceneNodeMaterials(m_animated_meshnode); m_animated_meshnode->forEachMaterial([this] (auto &mat) { @@ -923,26 +927,15 @@ void GenericCAO::setNodeLight(const video::SColor &light_color) } if (m_enable_shaders) { - if (m_prop.visual == "upright_sprite") { - if (!m_meshnode) - return; - for (u32 i = 0; i < m_meshnode->getMaterialCount(); ++i) - m_meshnode->getMaterial(i).EmissiveColor = light_color; - } else { - scene::ISceneNode *node = getSceneNode(); - if (!node) - return; - - for (u32 i = 0; i < node->getMaterialCount(); ++i) { - video::SMaterial &material = node->getMaterial(i); - material.EmissiveColor = light_color; - } - } + auto *node = getSceneNode(); + if (!node) + return; + setEmissiveColor(node, light_color); } else { if (m_meshnode) { setMeshColor(m_meshnode->getMesh(), light_color); } else if (m_animated_meshnode) { - setAnimatedMeshColor(m_animated_meshnode, light_color); + setMeshColor(m_animated_meshnode->getMesh(), light_color); } else if (m_spritenode) { m_spritenode->setColor(light_color); } @@ -1404,7 +1397,6 @@ void GenericCAO::updateTextures(std::string mod) material.MaterialType = m_material_type; material.MaterialTypeParam = m_material_type_param; material.TextureLayers[0].Texture = texture; - material.Lighting = true; material.BackfaceCulling = m_prop.backface_culling; // don't filter low-res textures, makes them look blurry diff --git a/src/client/mesh.cpp b/src/client/mesh.cpp index 6196e04d4..43c4f475b 100644 --- a/src/client/mesh.cpp +++ b/src/client/mesh.cpp @@ -181,13 +181,6 @@ void setMeshBufferColor(scene::IMeshBuffer *buf, const video::SColor &color) ((video::S3DVertex *) (vertices + i * stride))->Color = color; } -void setAnimatedMeshColor(scene::IAnimatedMeshSceneNode *node, const video::SColor &color) -{ - for (u32 i = 0; i < node->getMaterialCount(); ++i) { - node->getMaterial(i).EmissiveColor = color; - } -} - void setMeshColor(scene::IMesh *mesh, const video::SColor &color) { if (mesh == NULL) diff --git a/src/client/mesh.h b/src/client/mesh.h index 35d3886aa..931a5d818 100644 --- a/src/client/mesh.h +++ b/src/client/mesh.h @@ -59,11 +59,6 @@ void setMeshBufferColor(scene::IMeshBuffer *buf, const video::SColor &color); */ void setMeshColor(scene::IMesh *mesh, const video::SColor &color); -/* - Set a constant color for an animated mesh -*/ -void setAnimatedMeshColor(scene::IAnimatedMeshSceneNode *node, const video::SColor &color); - /*! * Overwrites the color of a mesh buffer. * The color is darkened based on the normal vector of the vertices.