• Advertisement
Sign in to follow this  

Variable Alpha in Direct3D

This topic is 4505 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 am writing a quad based 2D graphics engine, using Andy Pikes tutorials as a base. There are many circumstances in my game where it would be useful to change the transperancy of a panel on the fly. I have read in many places that it is bad practice to reach into the vertex buffer and change the transperancy values there, so I have been resorting to a fairly sloppy technique: I create 255 different quads of size 2 * 2 on startup, each with an alpha value between 0 and 255 applied to all vertices. When it is time to render a panel, the application checks the current transperancy of the panel and selects the appropriate quad, scales and rotates it to the appropriate dimensions for the panel, sets the texture, and renders. This works absolutely fine in 2D where only quads are used, but doesn't seem like very good practice. It also wouldn't work when I move onto 3D, as it would be horribly innefficient to make 255 copies of complex meshes. Is it possible to change the alpha values of an object on the fly without manipulating the vertex buffer? I already know how to apply a RGB tint to my quads, but the same technique doesn't seem to work for alpha.

Share this post


Link to post
Share on other sites
Advertisement
Andy Pikes tutorials are available at http://www.andypike.com/tutorials/DirectX8/

Another site with good Direct3D tutorials that can eventually be used for 2D via quads and billboarding is Drunken Hyena at
http://www.drunkenhyena.com/

Share this post


Link to post
Share on other sites
There are a couple of methods I know of. If you are using DX 9+, then you can set the texture stage state.

SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_CONSTANT);
SetTextureStageState(0, D3DTSS_CONSTANT, SomeValue);

Earlier approaches are similar, but use the D3DTA_TFACTOR instead. Also, I can't remember if you have to use ALPHA or COLOR above for this to work. If you use COLOR, then you'd set the alpha value of the color, so SomeValue would be a full RGBA color, with only the alpha value set.

Share this post


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

  • Advertisement