Sign in to follow this  

Alpha Blending

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this