Archived

This topic is now archived and is closed to further replies.

Alpha transparency in texture quads?

This topic is 5044 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

Alright, so I finally finished my texture quad engine (thanks to some help from people here) and it is fully optimized using dynamic vertex buffers. The frame rates are nearly 3 times higher than my D3DXSprite engine but I''m left with one last problem... How do I set the alpha transparency of the texture quad? With D3DXSprite, I would just change the alpha section of the color variable you pass to the Draw function... in my texture quad engine, my vertex format has a color to it, but when I set all the vertexes of a sprite to a color, it doesn''t take into account the alpha part of that color at all and draws them all at 100%. Is there anything special I have to do to get directx to look at the alpha part of the color set to my vertexes?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
make sure alpha blend is on. If your FVF has color then set the alpha value of your vertexes (you have to lock them first). If your are doing alpha by binding a material you need to enable lighting. Also you need to set up you src and destination blend states and possibly texture stage (it prob defaults ok)
here are some key words for the dxsdk docs
D3DRS_SRCBLEND
D3DRS_DESTBLEND
D3DRS_ALPHABLENDENABLE

Share this post


Link to post
Share on other sites
I know that you have to set those in order to alpha blend, right now I''m using:
pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
pd3dDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);

the alpha blending works fine when it''s part of the actual texture, but when I try to set the alpha transparency of a vertex, it doesn''t change it at all. I''ve looked through the sdk docs and they''re completley unhelpful with this...

Share this post


Link to post
Share on other sites
You also need to tell the texture stages where to take the color and alpha from and how to mix the together.

Use
From DX8:

SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );

SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE );
SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_TEXTURE );
SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );

This tells D3D to take the color and alpha values from texture and from the vertex and modulate (multiply) them. This way you can also set the colors of your quads to tint your textures.

Share this post


Link to post
Share on other sites
quote:

the alpha blending works fine when it''s part of the actual texture, but when I try to set the alpha transparency of a vertex, it doesn''t change it at all. I''ve looked through the sdk docs and they''re completley unhelpful with this...



Vertex colors are used when d3dlighting is off. When it''s on it uses the material that''s set instead. And you will have to do a
D3DTA_DIFFUSE for one of the alphaargs so that it gets used.

Share this post


Link to post
Share on other sites