Archived

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

Tom

Vertex alpha-blending in DirectX 7?

Recommended Posts

Hi. Perhaps someone could help me out. When I change the RGBA components of my vertices, the RGB channels of my textures are affected properly (I can make an object look red by making all the vertices red), but the alpha channel doesn''t change at all. Even when I set the alpha component to zero, the texture is still 100 percent opaque. Is there a renderstate setting I need to activate for vertex alpha-blending to work properly? Knowing this is critical to me, because I plan to fade TLVertices using the vertex alpha component so I don''t have to manipulate the alpha components of individual pixels. Thanks for your help.

Share this post


Link to post
Share on other sites
1. Make sure the texture stage states are set up properly (ALPHAOP = SELECTARG1, ALPHAARG1 = DIFFUSE of stage 0 with SetTextureStageState()). These control where the alpha comes from and how it is blended with the polygon. If you also want to use texture alpha, set ALPHAARG2 of stage 0 to TEXTURE and the ALPHAOP to MODULATE.


2. Make sure you''ve set up the blending render states (SetRenderState()) these control how the pixel at the end of the pipeline is blended with whatever is already in the frame buffer:

D3DRS_ALPHABLENDENABLE = TRUE
D3DRS_SRCBLEND = D3DBLEND_SRCALPHA
D3DRS_DESTBLEND = D3DBLEND_INVSRCALPHA


3. Remember to turn off Z writes, draw all the alpha polygons last and do manual Z sorting if necessary. (Look in the archives for more details).

--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites
Hey, thanks a lot. It works fine now.

Just one other question: is there anyway to have vertex blending with other blend modes, most importantly D3DBLEND_ONE? Because I'd like to have particle effects that fade, and changing the alpha value of four vertices is much easier than setting the alpha value of every pixel in the image (especially since I plan to use 8-bit textures!).



Edited by - Tom on November 6, 2001 10:44:05 AM

Share this post


Link to post
Share on other sites
Yep (provided your gfx hardware supports it - check the caps - athough it''s only really old ones that don''t).

The TextureStageState stuff just determines how the alpha gets to the frame buffer blend so that won''t affect anything.

A blend mode you could use to perform alpha channel controlled glowing effects would be SRC=D3DBLEND_SRCALPHA, DST=D3DBLEND_ONE.

That expands to the following operation:

FINALrgb = (SRCa * SRCrgb) + (1 * DESTrgb)

i.e. 1*something=something so the existing contents of the frame buffer aren''t affected. And the source R, G and B are multiplied by the alpha (it''s treated as if it ranges from 0 to 1 [0=0, 255=1])

--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites