Jump to content
  • Advertisement
Sign in to follow this  
Tispe

dds Alpha channel not working on mesh

This topic is 2499 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 ) ?

Share this post


Link to post
Share on other sites
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].

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
lol fixed it:

SetRenderState(D3DRS_ALPHAREF , 0x80);
SetRenderState(D3DRS_ALPHAFUNC , D3DCMP_GREATER);

Share this post


Link to post
Share on other sites
What DireCt version and what compiler and windows version are you using? I have problem finding AlphaBlend myself

Share this post


Link to post
Share on other sites
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);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!