Nearest neighbor filtering under DirectX

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
Munger
Posts: 28
Joined: Sun Mar 04, 2007 11:39 am
Location: Tokyo

Nearest neighbor filtering under DirectX

Post by Munger »

I was just trying to turn off bilinear filtering using something like this:

Code: Select all

node->setMaterialFlag(EMF_BILINEAR_FILTER, false);
It works under OpenGL, but neither the DirectX 8 or 9 renderers work - bilinear filtering remains on. Any ideas?
Munger
Posts: 28
Joined: Sun Mar 04, 2007 11:39 am
Location: Tokyo

Post by Munger »

BTW, GeForce 7900GS under XP, current drivers
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Probably because the code in the D3D8/9 drivers for filtering configuration is wrong. Notice how the following code doesn't even look at the filtering values other than anisotropic...

Code: Select all

if (material.BilinearFilter || material.TrilinearFilter || material.AnisotropicFilter)
{
  D3DTEXTUREFILTERTYPE tftMag = ((Caps.TextureFilterCaps & D3DPTFILTERCAPS_MAGFANISOTROPIC) && material.AnisotropicFilter) ? D3DTEXF_ANISOTROPIC : D3DTEXF_LINEAR;
  D3DTEXTUREFILTERTYPE tftMin = ((Caps.TextureFilterCaps & D3DPTFILTERCAPS_MINFANISOTROPIC) && material.AnisotropicFilter) ? D3DTEXF_ANISOTROPIC : D3DTEXF_LINEAR;
  D3DTEXTUREFILTERTYPE tftMip = material.TrilinearFilter ? D3DTEXF_LINEAR : D3DTEXF_POINT;

  for (u32 st=0; st<MaxTextureUnits; ++st)
  {
    pID3DDevice->SetTextureStageState(st, D3DTSS_MAGFILTER, tftMag);
    pID3DDevice->SetTextureStageState(st, D3DTSS_MINFILTER, tftMin);
    pID3DDevice->SetTextureStageState(st, D3DTSS_MIPFILTER, tftMip);
  }
}
I think it should be...

Code: Select all

if (material.BilinearFilter || material.TrilinearFilter || material.AnisotropicFilter)
{
   D3DTEXTUREFILTERTYPE tftMin = D3DTEXF_LINEAR;
   if (material.AnisotropicFilter && (Caps.TextureFilterCaps & D3DPTFILTERCAPS_MINFANISOTROPIC))
      tftMin = D3DTEXF_ANISOTROPIC;

   D3DTEXTUREFILTERTYPE tftMag = D3DTEXF_LINEAR;
   if (material.AnisotropicFilter && (Caps.TextureFilterCaps & D3DPTFILTERCAPS_MAGFANISOTROPIC))
      tftMag = D3DTEXF_ANISOTROPIC;

   D3DTEXTUREFILTERTYPE tftMip = D3DXF_POINT;
   if (material.TrilinearFilter && (Caps.TextureFilterCaps & D3DPTFILTERCAPS_MIPFLINEAR))
      tftMip = D3DTEXF_LINEAR;

  for (u32 st=0; st<MaxTextureUnits; ++st)
  {
    pID3DDevice->SetTextureStageState(st, D3DTSS_MAGFILTER, tftMag);
    pID3DDevice->SetTextureStageState(st, D3DTSS_MINFILTER, tftMin);
    pID3DDevice->SetTextureStageState(st, D3DTSS_MIPFILTER, tftMip);
  }
}
Travis
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

ummmm, shouldn't this -

Code: Select all

pID3DDevice->SetTextureStageState(st, D3DTSS_MAGFILTER, tftMag); 
pID3DDevice->SetTextureStageState(st, D3DTSS_MINFILTER, tftMin); 
pID3DDevice->SetTextureStageState(st, D3DTSS_MIPFILTER, tftMip); 
be this -

Code: Select all

pID3DDevice->SetSamplerState(st, D3DSAMP_MAGFILTER, tftMag); 
pID3DDevice->SetSamplerState(st, D3DSAMP_MINFILTER, tftMin); 
pID3DDevice->SetSamplerState(st, D3DSAMP_MIPFILTER, tftMip); 
I think D3DTSS stuff is old, maybe it should be that for DX8( I don't use it ), but DX9 is definitely D3DSAMP and SetSamplerState.
Image
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Yes, D3D8 uses SetTextureStageState() and D3D9 uses SetSamplerState().
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

I think the two fragments from vitek are the same besides the Caps check for the trilinear support. So there will be no more filter support than before!? So to say: It was correct and should have worked in all Irrlicht versions AFAIK.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Haha, that's hilarious. I didn't even read the code I had in my copy of the video driver. I just blindly copy/pasted it. I remember there being an issue with these flags before 1.3, but never checked to see if it was fixed. Apparently now it is exactly the same as what I have, just formatted differently.
Munger
Posts: 28
Joined: Sun Mar 04, 2007 11:39 am
Location: Tokyo

Post by Munger »

I never really thought about it, but looking at the code it seems filtering is set for all layers of a material. It would be nice to have per layer filtering. I'm sure it would be useful for something (although nothing springs to mind).

In my current project I'm using a character that's from the 8-bit generation so he should look like pixellated. It's no big deal for me to stick with OpenGL, but I'm not imagining things.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Per-layer setting will come soon. If I can keep the API compatible with the old one (i.e. only extending the old one) it will be in the next version, otherwise it will be in the next API-breaking one.
But as said in the previous posts the filtering should work for both accelerated drivers!
Post Reply