From d5ddfa6e465645280be5ba746411facabbd8f5a5 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Wed, 10 Jan 2024 19:34:52 +0100 Subject: [PATCH] ContentCAO: Fix threshold of alpha channel textures (#14213) With disabled shaders, the material EMT_TRANSPARENT_ALPHA_CHANNEL uses the parameter as an alpha threshold to decide whether to draw the texture. Thus lowering this limit fixes the issue of vanishing textures below alpha 128. --- src/client/content_cao.cpp | 16 +++++++++++----- src/client/content_cao.h | 1 + 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index 1c66062e0..48c09b769 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -619,6 +619,8 @@ void GenericCAO::addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr) infostream << "GenericCAO::addToScene(): " << m_prop.visual << std::endl; + m_material_type_param = 0.5f; // May cut off alpha < 128 depending on m_material_type + if (m_enable_shaders) { IShaderSource *shader_source = m_client->getShaderSource(); MaterialType material_type; @@ -633,8 +635,12 @@ void GenericCAO::addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr) u32 shader_id = shader_source->getShader("object_shader", material_type, NDT_NORMAL); m_material_type = shader_source->getShaderInfo(shader_id).material; } else { - m_material_type = (m_prop.use_texture_alpha) ? - video::EMT_TRANSPARENT_ALPHA_CHANNEL : video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; + if (m_prop.use_texture_alpha) { + m_material_type = video::EMT_TRANSPARENT_ALPHA_CHANNEL; + m_material_type_param = 1.0f / 256.f; // minimal alpha for texture rendering + } else { + m_material_type = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; + } } auto grabMatrixNode = [this] { @@ -1340,7 +1346,7 @@ void GenericCAO::updateTextures(std::string mod) video::SMaterial &material = m_spritenode->getMaterial(0); material.MaterialType = m_material_type; - material.MaterialTypeParam = 0.5f; + material.MaterialTypeParam = m_material_type_param; material.setTexture(0, tsrc->getTextureForMesh(texturestring)); // This allows setting per-material colors. However, until a real lighting @@ -1376,7 +1382,7 @@ void GenericCAO::updateTextures(std::string mod) // Set material flags and texture video::SMaterial &material = m_animated_meshnode->getMaterial(i); material.MaterialType = m_material_type; - material.MaterialTypeParam = 0.5f; + material.MaterialTypeParam = m_material_type_param; material.TextureLayers[0].Texture = texture; material.Lighting = true; material.BackfaceCulling = m_prop.backface_culling; @@ -1420,7 +1426,7 @@ void GenericCAO::updateTextures(std::string mod) // Set material flags and texture video::SMaterial &material = m_meshnode->getMaterial(i); material.MaterialType = m_material_type; - material.MaterialTypeParam = 0.5f; + material.MaterialTypeParam = m_material_type_param; material.Lighting = false; material.setTexture(0, tsrc->getTextureForMesh(texturestring)); material.getTextureMatrix(0).makeIdentity(); diff --git a/src/client/content_cao.h b/src/client/content_cao.h index b090cdc08..8180ceb14 100644 --- a/src/client/content_cao.h +++ b/src/client/content_cao.h @@ -130,6 +130,7 @@ private: bool m_is_visible = false; // Material video::E_MATERIAL_TYPE m_material_type; + f32 m_material_type_param; // Settings bool m_enable_shaders = false;