Sign in to follow this  
yewbie

Strange problem with alpha blending and colorkey

Recommended Posts

yewbie    677
I am using directx9 and I am using a 3d renderer to draw 2d tiles (this works great), but I just started playing with using a alpha to combine tiles for stuff like water effects... now this is also working...

But I am getting a strange problem when I draw texture over top of each other I get artifacts that shouldn't be coming from the textures themselves I double checked every pixel and its the correct colorkey (000000) true black.

Basically what im doing right now is drawing the "river bed" tile, then drawing the "water" tile with a alpha on it.

Then drawing the "grass" tile on top of that but im getting strange blackness where there should be none..

Attached are a picture of whats going on with original samples of each texture

Also Please only look at the top left corner to see whats really happening, the rest is just exaggerated because the texture is not fully cleaned up.

alpha 125
water
alpha 255
dirt
alpha 255
grass
Ugh...

You can see the black artifacts in last one.

Here is how im setting my renderstates and texture states


//Setup rendering states
d3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
d3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
d3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
d3dDevice->SetRenderState(D3DRS_SRCBLENDALPHA, D3DRS_DESTBLENDALPHA);
//Setup Texture States
d3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
d3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );


Loading my textures like so

[code]
D3DCOLOR colorkey = D3DCOLOR_XRGB(0,0,0);
D3DXCreateTextureFromFileEx (D3d, TexturePath, 0, 0, 1, 0,
D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_FILTER_NONE, D3DX_DEFAULT,
colorkey, NULL, NULL, &d3dTexture)
[code]

And to draw each "tile" I am just using below after I setup the vertices


d3dDevice->DrawPrimitive (D3DPT_TRIANGLEFAN, 0, 2);


Any help will be greatly appreciated, let me know if I missed anything.

Edit:
I am also using gimp, saving them with 100% quality

Edit Edit:
It appears to be the grass texture (or anything using the color key) just doesn't always draw a crisp image at the borders like the colorkey for transparency is just missing some of it.

[Edited by - yewbie on November 9, 2010 10:45:38 PM]

Share this post


Link to post
Share on other sites
M2tM    948
*EDIT: Whoopse, I mistook your problem.

Are you using .jpg? You should choose a different format like .png which can support lossless compression and it is generally much better as there won't be any artifacting.

Share this post


Link to post
Share on other sites
yewbie    677
Quote:
Original post by M2tM
Texture clamping may be your issue. I don't know directx, but in opengl when you set up your texture using: GL_CLAMP_TO_EDGE can help.


Hrmm I will look and see if DX is using something like that.
I figured the texture would just draw true because im using a 64x64 texture on a 64x64 quad (I think thats the right word)

Share this post


Link to post
Share on other sites
M2tM    948
Sorry, I saw the lines and didn't realize they were part of your texture, clamping isn't your problem, jpg compression probably is, but it couldn't hurt to be aware of. See my edited post.

Share this post


Link to post
Share on other sites
yewbie    677
Quote:
Original post by M2tM
Sorry, I saw the lines and didn't realize they were part of your texture, clamping isn't your problem, jpg compression probably is, but it couldn't hurt to be aware of. See my edited post.


Ah, I didn't even think of something that simple... I just figured 100% quality would give me no loss compression. Ugh I will give that a try and report back!

Share this post


Link to post
Share on other sites
yewbie    677
Quote:
Original post by M2tM
Sorry, I saw the lines and didn't realize they were part of your texture, clamping isn't your problem, jpg compression probably is, but it couldn't hurt to be aware of. See my edited post.


This was exactly my problem assuming jpg at 100% quality would not have loss of compression when loaded by DX. switching to PNG fixed my problem <3!!

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