Jump to content
  • Advertisement
Sign in to follow this  

Object Translucency

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

Does anyone know an easy way to do per-object translucency without using a shader. I am just using DX9 Vertex Streams/Defs and have opted so far to avoid using shaders to make sure I have the best HW cross-compatibility. On PS2 and PSP I set the ambient light alpha down low prior to rendering a piece that needs to be translucent (and make sure it is drawn last). Setting ambient alpha on DX9 does not seem to affect translucency. This is for pieces that I want to conditionally make translucent depending on gameplay, camera, player, or other issues, and I am not talking about pieces that are always translucent based on texture alpha - which I have working ok. Any help is appreciated!

Share this post

Link to post
Share on other sites
Will just have to make a quick reply as I'm short on time...

Have a look at the FF texture cascade (SetTextureStageState(), look up "texture blending" in the programming guide) and especially the D3DTA_TFACTOR and D3DRS_TFACTOR - should allow you to get what you want.


Share this post

Link to post
Share on other sites

Let's say you are rendering something with a single texture and you are not attempting any form of lighting or other effects.

// Set the operation of stage zero of the texture cascade to an alpha operation
// and set that operation to be (arg1 * arg2)
d3dd->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);

// Argument one will be the pixel from the texture in stage zero
d3dd->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);

// Argument two will be a constant that you set
d3dd->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_CONSTANT);

// You set that constant like this
d3dd->SetTextureStageState(0, D3DTSS_CONSTANT, D3DCOLOR_ARGB(a,r,g,b));

Now, assuming you have alpha blending turned on and your source and destination
blend values set to 'source' and '1 - source' respectively the hardware is
going to multiply the pixel from you texture by the constant you set and pass
the result down the pipeline were the alpha blending will happen.

To get things to look transparent or fade them from fully visible to fully
invisible adjust the value of 'a' when you set the second alpha argument
constant; just vary it between 0 and 255. Keep r, g, and b at 255 unless you
want to muck with the color of your object.

Like jollyjeffers said have a look at the texture cascade (aka multitexturing
via calls to SetTextureStateState()) to get a better idea of all your options.
It's a little confusing at first...but simple once you get it.

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!