1
0
mirror of https://github.com/minetest/minetest.git synced 2024-09-21 20:10:17 +02:00

Split up texture filtering properties of SMaterialLayer into MinFilter and MagFilter

You can	now set	the filter used	when scaling textures down and the filter used when scaling textures up separately.
This commit is contained in:
Gregor Parzefall 2023-06-23 13:58:52 +02:00 committed by sfan5
parent 307e380f30
commit 9bef3c136a
12 changed files with 53 additions and 47 deletions

View File

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

View File

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

View File

@ -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
@ -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;
});
};
@ -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);
});
}
}
@ -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() &&
@ -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") {
@ -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);
});
}
{
@ -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)

View File

@ -43,7 +43,8 @@ public:
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));

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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