Jump to content
  • Advertisement
Sign in to follow this  

Alpha Blending

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

Hi guys, I'm trying to peform alpha blending. I apply a texture to a mesh and enable all the alpha blend stage set things and the mesh looks blended according to the textures alpha channel. But what I'm after is also to fade the mesh using blending. So 1.0f will be the mesh fully opaque (still according to the alpha channel on the texture though), and 0.0f being totally transparent. Is there a state or stage i can set that will do this? Thanks. MeshMan

Share this post

Link to post
Share on other sites
Try the following

Use the following render state to set an alpha factor value
to be modulated with texture's alpha

In this render state you supply a color value to be used later
with the texture stage states.
So apply to the alpha section of the color (D3DCOLOR_ARGB) your desired transperacy value for the current frame

Then do the following :
D3DSetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TFACTOR);
D3DSetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_TEXTURE);

Which tells DirectX to modulate texture's alpha with your given
texture factor color, from which it takes the alpha component and uses with the alpha modulation.

Share this post

Link to post
Share on other sites

You can pretty much control all alpha operations with the ALPHAOP, ALPHAARG1 & ALPHAARG2 texture stage states. Say you want to use the texture for alpha, you'll use:

- SetTextureStageState() with ALPHAOP = SELECTARG1
- SetTextureStageState() with ALPHAARG1 = TEXTURE

If you also want to have a fadeParam [0..1] parameter to control the overall opacity of the mesh, then you can use:

- SetTextureStageState() with ALPHAOP = MODULATE
- SetTextureStageState() with ALPHAARG1 = TEXTURE
- SetTextureStageState() with ALPHAARG2 = TFACTOR
- SetRenderState() [IIRC it's a RS] with TFACTOR = ((DWORD)(fadeParam * 255.0f) << 24)

This way, the alpha value will be determined by: texture's alpha channel * fadeParam. TFactor is a ARGB color.

Sorry about the strange pseudo-code, I don't remember the exact names of the constants :)

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!