Skip to content

Commit

Permalink
Split up texture filtering properties of SMaterialLayer into MinFilte…
Browse files Browse the repository at this point in the history
…r and MagFilter

You can	now set	the filter used	when scaling textures down and the filter used when scaling textures up separately.
  • Loading branch information
grorp authored and sfan5 committed Jul 20, 2023
1 parent 307e380 commit 9bef3c1
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 47 deletions.
11 changes: 5 additions & 6 deletions src/client/clientmap.cpp
Expand Up @@ -843,9 +843,8 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)

// Apply filter settings
material.forEachTexture([this] (video::SMaterialLayer &tex) {
tex.TrilinearFilter = m_cache_trilinear_filter;
tex.BilinearFilter = m_cache_trilinear_filter;
tex.AnisotropicFilter = m_cache_anistropic_filter ? 0xFF : 0;
tex.setFiltersMinetest(m_cache_bilinear_filter, m_cache_trilinear_filter,
m_cache_anistropic_filter);
});
material.Wireframe = m_control.show_wireframe;

Expand All @@ -859,9 +858,9 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
// Do not enable filter on shadow texture to avoid visual artifacts
// with colored shadows.
// Filtering is done in shader code anyway
layer.BilinearFilter = false;
layer.AnisotropicFilter = false;
layer.TrilinearFilter = false;
layer.MinFilter = video::ETMINF_NEAREST;
layer.MagFilter = video::ETMAGF_NEAREST;
layer.AnisotropicFilter = 0;
}
driver->setMaterial(material);
++material_swaps;
Expand Down
3 changes: 2 additions & 1 deletion src/client/clouds.cpp
Expand Up @@ -53,7 +53,8 @@ Clouds::Clouds(scene::ISceneManager* mgr,
m_material.AntiAliasing = video::EAAM_SIMPLE;
m_material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
m_material.forEachTexture([] (video::SMaterialLayer &tex) {
tex.BilinearFilter = false;
tex.MinFilter = video::ETMINF_NEAREST;
tex.MagFilter = video::ETMAGF_NEAREST;
});

m_params.height = 120;
Expand Down
31 changes: 14 additions & 17 deletions src/client/content_cao.cpp
Expand Up @@ -255,7 +255,8 @@ void TestCAO::addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr)
buf->getMaterial().Lighting = false;
buf->getMaterial().BackfaceCulling = false;
buf->getMaterial().setTexture(0, tsrc->getTextureForMesh("rat.png"));
buf->getMaterial().TextureLayer[0].BilinearFilter = false;
buf->getMaterial().TextureLayer[0].MinFilter = video::ETMINF_NEAREST;
buf->getMaterial().TextureLayer[0].MagFilter = video::ETMAGF_NEAREST;
buf->getMaterial().FogEnable = true;
buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
// Add to mesh
Expand Down Expand Up @@ -652,7 +653,8 @@ void GenericCAO::addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr)
mat.NormalizeNormals = true;
}
mat.forEachTexture([] (video::SMaterialLayer &tex) {
tex.BilinearFilter = false;
tex.MinFilter = video::ETMINF_NEAREST;
tex.MagFilter = video::ETMAGF_NEAREST;
});
};

Expand Down Expand Up @@ -1353,9 +1355,8 @@ void GenericCAO::updateTextures(std::string mod)
}

material.forEachTexture([=] (video::SMaterialLayer &tex) {
tex.TrilinearFilter = use_trilinear_filter;
tex.BilinearFilter = use_bilinear_filter;
tex.AnisotropicFilter = use_anisotropic_filter ? 0xFF : 0;
tex.setFiltersMinetest(use_bilinear_filter, use_trilinear_filter,
use_anisotropic_filter);
});
}
}
Expand Down Expand Up @@ -1390,9 +1391,8 @@ void GenericCAO::updateTextures(std::string mod)
use_bilinear_filter &= res > 64;

material.forEachTexture([=] (video::SMaterialLayer &tex) {
tex.TrilinearFilter = use_trilinear_filter;
tex.BilinearFilter = use_bilinear_filter;
tex.AnisotropicFilter = use_anisotropic_filter ? 0xFF : 0;
tex.setFiltersMinetest(use_bilinear_filter, use_trilinear_filter,
use_anisotropic_filter);
});
}
for (u32 i = 0; i < m_prop.colors.size() &&
Expand Down Expand Up @@ -1438,9 +1438,8 @@ void GenericCAO::updateTextures(std::string mod)
}

material.forEachTexture([=] (video::SMaterialLayer &tex) {
tex.TrilinearFilter = use_trilinear_filter;
tex.BilinearFilter = use_bilinear_filter;
tex.AnisotropicFilter = use_anisotropic_filter ? 0xFF : 0;
tex.setFiltersMinetest(use_bilinear_filter, use_trilinear_filter,
use_anisotropic_filter);
});
}
} else if (m_prop.visual == "upright_sprite") {
Expand All @@ -1464,9 +1463,8 @@ void GenericCAO::updateTextures(std::string mod)
}

material.forEachTexture([=] (video::SMaterialLayer &tex) {
tex.TrilinearFilter = use_trilinear_filter;
tex.BilinearFilter = use_bilinear_filter;
tex.AnisotropicFilter = use_anisotropic_filter ? 0xFF : 0;
tex.setFiltersMinetest(use_bilinear_filter, use_trilinear_filter,
use_anisotropic_filter);
});
}
{
Expand Down Expand Up @@ -1494,9 +1492,8 @@ void GenericCAO::updateTextures(std::string mod)
}

material.forEachTexture([=] (video::SMaterialLayer &tex) {
tex.TrilinearFilter = use_trilinear_filter;
tex.BilinearFilter = use_bilinear_filter;
tex.AnisotropicFilter = use_anisotropic_filter ? 0xFF : 0;
tex.setFiltersMinetest(use_bilinear_filter, use_trilinear_filter,
use_anisotropic_filter);
});
}
// Set mesh color (only if lighting is disabled)
Expand Down
3 changes: 2 additions & 1 deletion src/client/content_cso.cpp
Expand Up @@ -43,7 +43,8 @@ class SmokePuffCSO: public ClientSimpleObject
mat.Lighting = false;
mat.FogEnable = true;
mat.forEachTexture([] (video::SMaterialLayer &tex) {
tex.BilinearFilter = false;
tex.MinFilter = video::ETMINF_NEAREST;
tex.MagFilter = video::ETMAGF_NEAREST;
});
});
m_spritenode->setColor(video::SColor(255,0,0,0));
Expand Down
3 changes: 2 additions & 1 deletion src/client/mapblock_mesh.cpp
Expand Up @@ -768,7 +768,8 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
material.FogEnable = true;
material.setTexture(0, p.layer.texture);
material.forEachTexture([] (video::SMaterialLayer &tex) {
tex.BilinearFilter = false;
tex.MinFilter = video::ETMINF_NEAREST;
tex.MagFilter = video::ETMAGF_NEAREST;
});

if (m_enable_shaders) {
Expand Down
6 changes: 4 additions & 2 deletions src/client/mesh.cpp
Expand Up @@ -101,7 +101,8 @@ scene::IAnimatedMesh* createCubeMesh(v3f scale)
buf->getMaterial().Lighting = false;
buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
buf->getMaterial().forEachTexture([] (video::SMaterialLayer &tex) {
tex.BilinearFilter = false;
tex.MinFilter = video::ETMINF_NEAREST;
tex.MagFilter = video::ETMAGF_NEAREST;
});
// Add mesh buffer to mesh
mesh->addMeshBuffer(buf);
Expand Down Expand Up @@ -410,7 +411,8 @@ scene::IMesh* convertNodeboxesToMesh(const std::vector<aabb3f> &boxes,
scene::IMeshBuffer *buf = new scene::SMeshBuffer();
buf->getMaterial().Lighting = false;
buf->getMaterial().forEachTexture([] (video::SMaterialLayer &tex) {
tex.BilinearFilter = false;
tex.MinFilter = video::ETMINF_NEAREST;
tex.MagFilter = video::ETMAGF_NEAREST;
});
dst_mesh->addMeshBuffer(buf);
buf->drop();
Expand Down
3 changes: 2 additions & 1 deletion src/client/minimap.cpp
Expand Up @@ -609,7 +609,8 @@ void Minimap::drawMinimap(core::rect<s32> rect) {

video::SMaterial &material = m_meshbuffer->getMaterial();
material.forEachTexture([] (video::SMaterialLayer &tex) {
tex.TrilinearFilter = true;
tex.MinFilter = video::ETMINF_TRILINEAR;
tex.MagFilter = video::ETMAGF_BILINEAR;
});
material.Lighting = false;
material.TextureLayer[0].Texture = minimap_texture;
Expand Down
3 changes: 2 additions & 1 deletion src/client/particles.cpp
Expand Up @@ -93,7 +93,8 @@ Particle::Particle(
m_material.BackfaceCulling = false;
m_material.FogEnable = true;
m_material.forEachTexture([] (video::SMaterialLayer &tex) {
tex.BilinearFilter = false;
tex.MinFilter = video::ETMINF_NEAREST;
tex.MagFilter = video::ETMAGF_NEAREST;
});

// correctly render layered transparent particles -- see #10398
Expand Down
9 changes: 5 additions & 4 deletions src/client/render/secondstage.cpp
Expand Up @@ -38,9 +38,9 @@ void PostProcessingStep::configureMaterial()
material.ZBuffer = true;
material.ZWriteEnable = video::EZW_ON;
for (u32 k = 0; k < texture_map.size(); ++k) {
material.TextureLayer[k].AnisotropicFilter = false;
material.TextureLayer[k].BilinearFilter = false;
material.TextureLayer[k].TrilinearFilter = false;
material.TextureLayer[k].AnisotropicFilter = 0;
material.TextureLayer[k].MinFilter = video::ETMINF_NEAREST;
material.TextureLayer[k].MagFilter = video::ETMAGF_NEAREST;
material.TextureLayer[k].TextureWrapU = video::ETC_CLAMP_TO_EDGE;
material.TextureLayer[k].TextureWrapV = video::ETC_CLAMP_TO_EDGE;
}
Expand Down Expand Up @@ -92,7 +92,8 @@ void PostProcessingStep::run(PipelineContext &context)
void PostProcessingStep::setBilinearFilter(u8 index, bool value)
{
assert(index < video::MATERIAL_MAX_TEXTURES);
material.TextureLayer[index].BilinearFilter = value;
material.TextureLayer[index].MinFilter = value ? video::ETMINF_BILINEAR : video::ETMINF_NEAREST;
material.TextureLayer[index].MagFilter = value ? video::ETMAGF_BILINEAR : video::ETMAGF_NEAREST;
}

RenderStep *addPostProcessing(RenderPipeline *pipeline, RenderStep *previousStep, v2f scale, Client *client)
Expand Down
4 changes: 2 additions & 2 deletions src/client/sky.cpp
Expand Up @@ -51,8 +51,8 @@ static video::SMaterial baseMaterial()
static inline void disableTextureFiltering(video::SMaterial &mat)
{
mat.forEachTexture([] (video::SMaterialLayer &tex) {
tex.BilinearFilter = false;
tex.TrilinearFilter = false;
tex.MinFilter = video::ETMINF_NEAREST;
tex.MagFilter = video::ETMAGF_NEAREST;
tex.AnisotropicFilter = 0;
});
}
Expand Down
21 changes: 11 additions & 10 deletions src/client/wieldmesh.cpp
Expand Up @@ -298,10 +298,11 @@ void WieldMeshSceneNode::setExtruded(const std::string &imagename,
material.MaterialTypeParam = 0.5f;
material.BackfaceCulling = true;
// Enable bi/trilinear filtering only for high resolution textures
material.forEachTexture([this, &dim] (video::SMaterialLayer &tex) {
tex.BilinearFilter = dim.Width > 32 && m_bilinear_filter;
tex.TrilinearFilter = dim.Width > 32 && m_trilinear_filter;
tex.AnisotropicFilter = m_anisotropic_filter ? 0xFF : 0;
bool bilinear_filter = dim.Width > 32 && m_bilinear_filter;
bool trilinear_filter = dim.Width > 32 && m_trilinear_filter;
material.forEachTexture([=] (video::SMaterialLayer &tex) {
tex.setFiltersMinetest(bilinear_filter, trilinear_filter,
m_anisotropic_filter);
});
// mipmaps cause "thin black line" artifacts
material.UseMipMaps = false;
Expand Down Expand Up @@ -464,8 +465,8 @@ void WieldMeshSceneNode::setItem(const ItemStack &item, Client *client, bool che
material.MaterialTypeParam = 0.5f;
material.BackfaceCulling = cull_backface;
material.forEachTexture([this] (video::SMaterialLayer &tex) {
tex.BilinearFilter = m_bilinear_filter;
tex.TrilinearFilter = m_trilinear_filter;
tex.setFiltersMinetest(m_bilinear_filter, m_trilinear_filter,
m_anisotropic_filter);
});
}

Expand Down Expand Up @@ -655,8 +656,8 @@ void getItemMesh(Client *client, const ItemStack &item, ItemMesh *result)
material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
material.MaterialTypeParam = 0.5f;
material.forEachTexture([] (video::SMaterialLayer &tex) {
tex.BilinearFilter = false;
tex.TrilinearFilter = false;
tex.MinFilter = video::ETMINF_NEAREST;
tex.MagFilter = video::ETMAGF_NEAREST;
});
material.BackfaceCulling = cull_backface;
material.Lighting = false;
Expand Down Expand Up @@ -701,8 +702,8 @@ scene::SMesh *getExtrudedMesh(ITextureSource *tsrc,
video::SMaterial &material = mesh->getMeshBuffer(layer)->getMaterial();
material.TextureLayer[0].TextureWrapU = video::ETC_CLAMP_TO_EDGE;
material.TextureLayer[0].TextureWrapV = video::ETC_CLAMP_TO_EDGE;
material.TextureLayer[0].BilinearFilter = false;
material.TextureLayer[0].TrilinearFilter = false;
material.TextureLayer[0].MinFilter = video::ETMINF_NEAREST;
material.TextureLayer[0].MagFilter = video::ETMAGF_NEAREST;
material.BackfaceCulling = true;
material.Lighting = false;
material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
Expand Down
3 changes: 2 additions & 1 deletion src/gui/guiScene.cpp
Expand Up @@ -68,7 +68,8 @@ void GUIScene::setTexture(u32 idx, video::ITexture *texture)
material.TextureLayer[0].Texture = texture;
material.Lighting = false;
material.FogEnable = true;
material.TextureLayer[0].BilinearFilter = false;
material.TextureLayer[0].MinFilter = video::ETMINF_NEAREST;
material.TextureLayer[0].MagFilter = video::ETMAGF_NEAREST;
material.BackfaceCulling = false;
material.ZWriteEnable = video::EZW_AUTO;
}
Expand Down

0 comments on commit 9bef3c1

Please sign in to comment.