Fix CAO mesh lighting with shaders disabled

the 'Lighting' material flag does not have portable behavior
This commit is contained in:
sfan5 2024-09-10 18:41:57 +02:00
parent 740dc0162e
commit 65af606729
3 changed files with 11 additions and 31 deletions

View File

@ -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

View File

@ -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)

View File

@ -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.