Search code examples
directxhlsldirect3d9

HLSL - How can I set sampler Min/Mag/Mip filters to disable all filtering/anti-aliasing?


I have a tex2D sampler I want to only return precisely those colours that are present on my texture. I am using Shader Model 3, so cannot use load.

In the event of a texel overlapping multiple colours, I want it to pick one and have the whole texel be that colour.

I think to do this I want to disable mipmapping, or at least trilinear filtering of mips.

sampler2D gColourmapSampler : register(s0) = sampler_state {
    Texture = <gColourmapTexture>; //Defined above
    MinFilter = None; //Controls sampling. None, Linear, or Point.
    MagFilter = None; //Controls sampling. None, Linear, or Point.
    MipFilter = None; //Controls how the mips are generated. None, Linear, or Point.
    //...
};

My problem is I don't really understand Min/Mag/Mip filtering, so am not sure what combination I need to set these in, or if this is even what I am after.

What a portion of my source texture looks like;
http://img689.imageshack.us/img689/6171/sourcev.png

Screenshot of what the relevant area looks like after the full texture is mapped to my sphere;
http://img717.imageshack.us/img717/9202/resultc.png
The anti-aliasing/blending/filtering artefacts are clearly visible; I don't want these.


MSDN has this to say;

D3DSAMP_MAGFILTER: Magnification filter of type D3DTEXTUREFILTERTYPE

D3DSAMP_MINFILTER: Minification filter of type D3DTEXTUREFILTERTYPE.

D3DSAMP_MIPFILTER: Mipmap filter to use during minification. See D3DTEXTUREFILTERTYPE.

D3DTEXF_NONE: When used with D3DSAMP_MIPFILTER, disables mipmapping.

Another good link on understanding hlsl intrinsics.


RESOLVED

Not an HLSL issue at all! Sorry all. I seem to ask a lot of questions that are impossible to answer. Ogre was over-riding the above settings. This was fixed with;

Ogre::MaterialManager::getSingleton().setDefaultTextureFiltering(Ogre::FO_NONE , Ogre::FO_NONE, Ogre::FO_NONE);

Solution

  • What it looks to me is that you're getting the values from a lower level mip-map (unfiltered) than the highest detail you're showing.

    MipFilter = None 
    

    should prevent that, unless something in the code overrides it. So look for calls to SetSamplerState.