dds Alpha channel not working on mesh

Started by
16 comments, last by Evil Steve 12 years, 2 months ago
I have a DXT3 dds image loaded in a LPDIRECT3DTEXTURE9. Drawing it as a sprite will make the "black pixels/alpha" transparent. However if I use it on a mesh it will show black edges along the texture where it should be transparent.

What should I do to make it transparent ( fixed pipeline atm ) ?
Advertisement
I suppose you're referring to the D3DX sprite class. I've never used it so this post is mere speculation.
I suppose the sprite class internally sets up alpha blending and your code does not.
You need to enable [color=#000000][font=Consolas, Courier, monospace]

D3DRS_ALPHABLENDENABLE [/font](default: false). I suggest to take the chance to also consider [color=#000000][font=Consolas, Courier, monospace]

D3DRS_SRCBLEND[/font], [color=#000000][font=Consolas, Courier, monospace]

D3DRS_DESTBLEND[/font]. There are more advanced alpha blending settings as well.
For this specific application however, you might just be interested in alpha testing: see [color=#000000][font=Consolas, Courier, monospace]

D3DRS_ALPHATESTENABLE, [/font][color=#000000][font=Consolas, Courier, monospace]

D3DRS_ALPHAREF, [/font][color=#000000][font=Consolas, Courier, monospace]

D3DRS_ALPHAFUNC[/font].

Previously "Krohm"

Ok, I got the effect I wanted but with a bug.

Places like some corners or edges there are small specks of black being visible. This is not shown in the game I "borrow" the asset from.

What are tyical sources for corner and edges specks?
That sounds like you've only got alpha test on, so the pixel is either opaque or transparant, and not actually blended properly. What render states are you setting?

SetRenderState(D3DRS_ZENABLE, TRUE);
SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(50, 50, 50));
SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD);
SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);


What else is needed?
I have recoded this 4 times now and still no go. Tried even with just a pure vertex buffer, with and without indices.

specks.png
Another thing that is occuring is that if I have a sphere where a spot on the sphere surface is made transparent with alpha blending, the back/opposite side through the "spot hole" of the sphere also becomes transparent but is not supposed to.

It might be that my faces are two-sided. One interesting observation I have is that a strip of triangles are black on one side(alpha black) and have a texture on the other side, but with ALPHABLENDENABLE set to true both sides are invisble, while I want the other side visible.

So if the same "subset" is curled ontop of itself it like a sphere or ring, it will make invisible faces behind it that should not be.
lol fixed it:

SetRenderState(D3DRS_ALPHAREF , 0x80);
SetRenderState(D3DRS_ALPHAFUNC , D3DCMP_GREATER);
What DireCt version and what compiler and windows version are you using? I have problem finding AlphaBlend myself
Always a new bug to figure out for me :(

Now, if the Mesh is barely 5+ units away from the camera the mesh will have many faces start becoming fully transparent.

Turning off D3DRS_ALPHATESTENABLE corrects this but that messes up my textures... And it seems the further away my Mesh gets from the camera the darker it gets..

What is going on? I have messed around with these states without any results


SetRenderState(D3DRS_LIGHTING, false);
SetRenderState(D3DRS_ZENABLE, true);
SetRenderState(D3DRS_ALPHAREF, 0x50);
SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATER);
SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(50, 50, 50));
SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
SetRenderState(D3DRS_NORMALIZENORMALS, true);
SetRenderState(D3DRS_ALPHABLENDENABLE, true);
SetRenderState(D3DRS_ALPHATESTENABLE, true);
SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD);
SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

This topic is closed to new replies.

Advertisement