Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Super blurry textures - XNA

Tags:

c#

xna

textures

I seem to be getting really blurry textures when I look at my textures up close. I am creating a minecraft-like terrain thing and I would like the textures to be pixelated - like it is made rather than XNA try to smooth it out for me.

Here is how it appears: http://s1100.photobucket.com/albums/g420/darestium/?action=view&current=bluryminecraftterrain.png

Any suggestions would be much appeciated.

like image 893
Darestium Avatar asked Jan 19 '26 09:01

Darestium


1 Answers

It's not related to anti-aliasing... it's related to how the hardware samples the texels in the texture. The default filter in XNA is usually Linear, but to get those "blocky" looking textures you must use Point.

In C# you can set any of your SamplerStates to use PointWrap. This is a combination of point filtering with UV wrapping.

// any state index from 0 to 15, textures usually take 0 first    
GraphicsDevice.SamplerStates[0] = SamplerState.PointWrap; 

However it must the one assigned to the same register as the SamplerState. eg. register s0 will usually be SamplerStates[0]. Alternatively you can enforce sampler states on the shader, and set your registers there:

sampler2D textureSampler : register(s0) = sampler_state
{
    Texture = <Texture>;
    MipFilter = Point;
    MagFilter = Point;
    MinFilter = Point;
    AddressU = Wrap;
    AddressV = Wrap;
};

You can also force mipmapping off with MipFilter set to None.

like image 192
Chris C Avatar answered Jan 20 '26 22:01

Chris C



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!