Sign in to follow this  
Ardor

Multiple Alpha blending factors

Recommended Posts

Ardor    122
Hi, I'm trying to do alphablending with some rendered text and the fixed function pipeline. It goes like this: there is a font texture. This texture contains all letters. An alpha channel is included to have the letters transparent. So far so good. However, what if I want to fade in/out the text? Somehow I need to specify the total alpha factor. Thus, I have TWO factors. One alpha factor from the alpha channel of the texture, and another one I specified. The usual alpha blending equation goes like this: result = source + ( dest - source ) * alpha However, I need something like this: result = source + ( dest - source ) * ( alpha_texture * alpha_specified ) I can do this easily in a pixel shader. But how is it possible with the fixed function pipeline?

Share this post


Link to post
Share on other sites
Kalidor    1087
This is assuming you are using OpenGL, I'm sure Direct3D has something very similar but I'm not sure on the terminology.

You just need to make sure your texture environment is set to modulate and then use glColor4f(r,g,b,a) before you render where a is your alpha_specified.

Check here for more advanced texture env combiner modes.

Share this post


Link to post
Share on other sites
If it is D3D, the alpha used for blending is the alpha after the last TextureStage, or at the end of your pixel shader.

Definately read up on texture stages. They're kinda like a mini, limited, pixel shader. They're what people used before shaders came around.

Lets say you want color to be diffuseTexture * lighting, and you want alpha to be diffuseTexture * someScalingFactor.

// Color = texture * diffuse(light or vertex color)
pDev->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
pDev->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
pDev->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTOP_DIFFUSE);
// Alpha = texture * scale
pDev->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
pDev->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
pDev->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_TFACTOR);
// Use first set of UVs for texture lookup
pDev->SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);

// Terminate at stage 1
pDev->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
pDev->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);

pDev->SetRenderState(D3DRS_TEXTUREFACTOR, 0x80000000); // Blend with alpha = 50%. Note that this texturefactor is the TFACTOR you see in the stages above.

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