Sign in to follow this  
arrecio

White border while sampling zoomed textures with directX

Recommended Posts

hi,

Im currently porting a work from XNA to DirectX using c++. Im stucked with a texture sampling issue.

[img]http://img827.imageshack.us/img827/2676/badez.png[/img]

There are 3 sprites in the image, original (1:1), XNA sampled (1:1.2) and directX sampled (1:1.2). Im getting a non desired white border in direct X.

Im using LinearClamp in XNA and

Device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
Device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
Device->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
Device->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
Device->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
Device->SetSamplerState(0, D3DSAMP_ADDRESSW, D3DTADDRESS_CLAMP);

in directX

thnx in advance

[SOLVED]

Seems like XNA content processor sets alpha colors to TransparentBlack, my png has trasnparency over TransparentWhite so the sampler was doing the same but from 2 different sources. Edited by arrecio

Share this post


Link to post
Share on other sites
I think this article best describes the problem you're dealing with:

[url="http://blogs.msdn.com/b/shawnhar/archive/2009/11/02/texture-filtering-alpha-cutouts.aspx"]http://blogs.msdn.co...ha-cutouts.aspx[/url]

When bilinearly filtering, RGB values of texels with zero alpha, even though they are fully transparent, still influence interpolated color values.

As the article recommends, the best thing to counteract this, is to set the color value of these texels to the value of their nearest 'alpha > 0'-texel. Edited by eppo

Share this post


Link to post
Share on other sites
umn I thought I understood it,

So its possible the difference between my XNA code and my dx code results is becouse the content importer in XNA? what is doing some changes on my alpha texels?, in XNA im using content importer and in DX the CreateTextureFromFile method from a png file. Its strange, im taking two different results with (i think) same sampler and blender states on the device. Well thanx eppo, i will work on it.

Share this post


Link to post
Share on other sites
I believe the reason you don't see the issue in XNA is because it uses premultiplied alpha by default.

[url="http://blogs.msdn.com/b/shawnhar/archive/2010/04/08/premultiplied-alpha-in-xna-game-studio-4-0.aspx"]http://blogs.msdn.com/b/shawnhar/archive/2010/04/08/premultiplied-alpha-in-xna-game-studio-4-0.aspx[/url]

Share this post


Link to post
Share on other sites
[quote name='jrh2365' timestamp='1342977761' post='4961965']
I believe the reason you don't see the issue in XNA is because it uses premultiplied alpha by default.

[url="http://blogs.msdn.com/b/shawnhar/archive/2010/04/08/premultiplied-alpha-in-xna-game-studio-4-0.aspx"]http://blogs.msdn.co...studio-4-0.aspx[/url]
[/quote]

Yes, by default, but im using this call with SpriteBatch:

SpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied, null, null, null, null, matrix);

But u are right, PremultiplyAlpha is turn on for content processor, if i turn off it i get same results, mistery solved.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this