Page 1 of 1

controlling irrlichts magfilter setting?

PostPosted: Fri Oct 04, 2013 22:11
by miner65536
I reckon minetest would look superb if we could get irrlicht to set the magfiltering to point mode (for D3D mode anyway).
This way mip-mapping, bi-linear or aniso filtering could be enabled for the distant scenery but close up the textures would just be point sampled, so would look properly retro.
This would be the perfect setup for the default 16x16 textures.
I've looked quickly at irrlicht & it looks like point mode (D3DTEXF_POINT) cannot be set for the texture stage states, so it would need an irrlicht recompile... If i get time i will try, but I'm too busy, if someone else could try this it'd be awesome...

cheers,
Rob


PS the piece of code i was looking at in irrlicht was in CD3D9Driver.cpp
I reckon replace this lot:

// Bilinear, trilinear, and anisotropic filter
if (resetAllRenderstates ||
lastmaterial.TextureLayer[st].BilinearFilter != material.TextureLayer[st].BilinearFilter ||
lastmaterial.TextureLayer[st].TrilinearFilter != material.TextureLayer[st].TrilinearFilter ||
lastmaterial.TextureLayer[st].AnisotropicFilter != material.TextureLayer[st].AnisotropicFilter ||
lastmaterial.UseMipMaps != material.UseMipMaps)
{
if (material.TextureLayer[st].BilinearFilter || material.TextureLayer[st].TrilinearFilter || material.TextureLayer[st].AnisotropicFilter)
{
D3DTEXTUREFILTERTYPE tftMag = ((Caps.TextureFilterCaps & D3DPTFILTERCAPS_MAGFANISOTROPIC) &&
material.TextureLayer[st].AnisotropicFilter) ? D3DTEXF_ANISOTROPIC : D3DTEXF_LINEAR;
D3DTEXTUREFILTERTYPE tftMin = ((Caps.TextureFilterCaps & D3DPTFILTERCAPS_MINFANISOTROPIC) &&
material.TextureLayer[st].AnisotropicFilter) ? D3DTEXF_ANISOTROPIC : D3DTEXF_LINEAR;
D3DTEXTUREFILTERTYPE tftMip = material.UseMipMaps? (material.TextureLayer[st].TrilinearFilter ? D3DTEXF_LINEAR : D3DTEXF_POINT) : D3DTEXF_NONE;

if (tftMag==D3DTEXF_ANISOTROPIC || tftMin == D3DTEXF_ANISOTROPIC)
pID3DDevice->SetSamplerState(st, D3DSAMP_MAXANISOTROPY, core::min_((DWORD)material.TextureLayer[st].AnisotropicFilter, Caps.MaxAnisotropy));
pID3DDevice->SetSamplerState(st, D3DSAMP_MAGFILTER, tftMag);
pID3DDevice->SetSamplerState(st, D3DSAMP_MINFILTER, tftMin);
pID3DDevice->SetSamplerState(st, D3DSAMP_MIPFILTER, tftMip);
}
else
{
pID3DDevice->SetSamplerState(st, D3DSAMP_MINFILTER, D3DTEXF_POINT);
pID3DDevice->SetSamplerState(st, D3DSAMP_MIPFILTER, D3DTEXF_NONE);
pID3DDevice->SetSamplerState(st, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
}
}


with this:

pID3DDevice->SetSamplerState(st, D3DSAMP_MINFILTER, D3DTEXF_ANISOTROPIC);
pID3DDevice->SetSamplerState(st, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
pID3DDevice->SetSamplerState(st, D3DSAMP_MAGFILTER, D3DTEXF_POINT);

PostPosted: Mon Oct 07, 2013 09:39
by miner65536
It turned out compiling irrlicht was as simple as opening the VS solution & pressing F5!
I tried this on an i5 laptop using the integrated HD4000 and after setting the mipmapping LOD bias to -1.5 its a huge improvement, distant scenery looks unconfused (I've got to try this on a decent gfx card to compare with good anisotropic filtering) But compared to the options available with the default irrlicht build & minetests settings its great, I'll post some A-B screen shots if anyone is interested.

PostPosted: Mon Oct 07, 2013 10:13
by Ragnar
screenies!

PostPosted: Mon Oct 07, 2013 11:58
by Calinou
miner65536 wrote:This way mip-mapping, bi-linear or aniso filtering could be enabled for the distant scenery but close up the textures would just be point sampled, so would look properly retro.


This is already possible! Enable anisotropic filtering and mip-mapping but disable bilinear and trilinear filtering.