Strange problem with alpha blending and colorkey

Started by
4 comments, last by yewbie 13 years, 5 months ago
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 statesd3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE);d3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);d3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);d3dDevice->SetRenderState(D3DRS_SRCBLENDALPHA, D3DRS_DESTBLENDALPHA);//Setup Texture Statesd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);d3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_MODULATE );


Loading my textures like so


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)


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]
Advertisement
*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.
_______________________"You're using a screwdriver to nail some glue to a ming vase. " -ToohrVyk
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)
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.
_______________________"You're using a screwdriver to nail some glue to a ming vase. " -ToohrVyk
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!
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!!

This topic is closed to new replies.

Advertisement