Skip to main content
GameDev.net gamedev.net
🔒 Locked

Alpha Blending

Started by MeshMan Nov 29, 2004 at 2:16 PM 1 replies 600+ views
Original Post
MeshMan
MeshMan
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
DesignerX
DesignerX
Try the following

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

Render state : D3DRS_TEXTUREFACTOR
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_ALPHAOP, D3DTOP_MODULATE);
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.
There is nothing that can't be solved. Just people that can't solve it. :)
Aldenar
Aldenar
Hello,

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 :)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.