Sign in to follow this  

Translucency

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

How is this done? I was thinking maybe HLSL, but the examples I've seen so far that create supposedly see-through meshes still occlude (or block the view of) other meshes (and indeed parts of themselves). So is there some easy way to make mesh's translucent (still visible but see-through)? I dont need any crazy refraction effect atm.. What methods do people use for this?

Share this post


Link to post
Share on other sites
(Assuming you're not using any mesh object not written by you, or the mesh object is flexible enough, since I don't really know what various prewritten mesh objects are like...)

There are a few relevant render states, D3DRS_ALPHABLENDENABLE, D3DRS_SRCBLEND, and D3DRS_DESTBLEND, typically set to TRUE, D3DBLEND_SRCALPHA, and D3DBLEND_INVSRCALPHA. In addition, to easily add translucency to objects, you can set the texture stage states D3DTSS_ALPHAOP, D3DTSS_ALPHAARG1, D3DTSS_ALPHAARG2 to D3DTOP_MODULATE, D3DTA_TEXTURE, and D3DTA_DIFFUSE. You'll then need to make sure your vertices include a diffuse component. The diffuse component's alpha value will then affect the overall transparency, but a texture's transparency will still also be used.

And important thing to note though is that when doing alphablending, the order of rendering triangles is important. You need to draw all translucent items from back to front to get them to look correct. (Sometimes a loose ordering works well enough, though.)

Share this post


Link to post
Share on other sites
This is not so simple. To get a good (and correct) effect you must also render transparent polygons by distance, so the polygon furthest away from the eye always gets drawn first.

Share this post


Link to post
Share on other sites
As long as your object is convex, you shouldn't have as many problems. You will have to draw the furthest parts first as Victor suggested...unless you get lucky and the vertices are stored in the vertex buffer based on distance (which perhaps you could write a routine to sort them that way). There's an easy way to make an entire mesh transparent. Just before drawing it, set the render states so that Alpha Arg 1 is used for all alpha and then set Alpha Arg 1 to FORCE_DWORD and then set CONSTANT to your alpha value. Enable alpha blending and draw.

Chris

Share this post


Link to post
Share on other sites

This topic is 4838 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.

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