Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ContentCAO: Fix threshold of alpha channel textures #14213

Merged
merged 3 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/client/content_cao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,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;
Expand All @@ -634,8 +636,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
grorp marked this conversation as resolved.
Show resolved Hide resolved
} else {
m_material_type = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
}
}

auto grabMatrixNode = [this] {
Expand Down Expand Up @@ -1341,7 +1347,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
Expand Down Expand Up @@ -1377,7 +1383,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;
Expand Down Expand Up @@ -1421,7 +1427,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();
Expand Down
1 change: 1 addition & 0 deletions src/client/content_cao.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class GenericCAO : public ClientActiveObject
bool m_is_visible = false;
// Material
video::E_MATERIAL_TYPE m_material_type;
f32 m_material_type_param;
// Settings
bool m_enable_shaders = false;

Expand Down