I'm trying to render a plane mesh textured with a simple grid pattern. The problem is that XNA keeps mip-mapping the texture in horrible, horrible ways.

enter image description here

What I'm trying to achieve is to get this grid to look as close to vector graphics as possible (so anisotropic filtering is out of the question, I must use point filtering):

SamplerState ss = new SamplerState();
ss.Filter = TextureFilter.Point;
ss.MaxMipLevel = 0;
ss.AddressU = TextureAddressMode.Wrap;
ss.AddressV = TextureAddressMode.Wrap;
GraphicsDevice.SamplerStates[0] = ss;

I'm loading the mesh, and it's textures, from an .x file so I don't have control over the specifics of the texture loads. Can I disable mip-mapping for the whole rendering process?

  • \$\begingroup\$ @childonline Not sure, off the top of my head. If it's not an option for the default content importer, you may need to write a content pipeline extension. Or maybe try doing this without a .x model? (Set up the vertices by hand and load the texture independently.) \$\endgroup\$ – Andrew Russell Mar 31 '13 at 11:14
  • \$\begingroup\$ (There may be a way to do it at runtime - but I'm not sure - I would have thought that MaxMipLevel would have worked. But I've never played with that.) \$\endgroup\$ – Andrew Russell Mar 31 '13 at 11:15
  • 1
    \$\begingroup\$ @Andrew Russell: Nevermind, I've fixed it, it's sort of a dirty hack, but i've set the MipMapLevelOfDetailBias of the SamlperState to -2, i don't know why it works, but it works. Here is a screen: imgur.com/OFbYAqE \$\endgroup\$ – childonline Mar 31 '13 at 11:58

If you're using the default content importer, there's no way to control the mipmap generation behavior of the textures.

The .x file format doesn't really provide a template that allows control over mipmapping of textures, and XNA's importer assumes you'll want mipmaps for all the referenced textures.

Your two best options are likely:

  • Build a custom importer to parse the .x file and generate the textures without mipmaps.
  • Ignore or discard the textures loaded by the content importer for the .x file, loading manual copies yourself, in which you disable mipmapping.
  • Set the MipMapLevelOfDetailBias property of your sampler state to a sufficiently-negative number to ensure mipmap level 0 is always used (in later shader models you could use SampleLevel to explicitly specify that mipmap 0 should be sampled, but I don't think XNA supports a new-enough model for this).

The last option is probably the easiest, but also wastes all the memory of the extra mip levels which you'll never sample.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.