• Advertisement

Archived

This topic is now archived and is closed to further replies.

transparency

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

I have created a scene that contains a square chainlink fenced off area. I have turned on transparency and it looks fine from inside the area but when i go outside and look through the different sides of the fenced off area you can''t see the other parts of the fence. I know this is because of the order that they are being drawn in. What is the best way to show all of the sides of the fence. I have tried turning of depth test but then the fences get drawn on top of everything so depth testing needs to be on.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
backface culling!?

Share this post


Link to post
Share on other sites
To correctly display transparency you need the following:

1. Draw opaque faces
2. turn off depth test
3. draw transparent faces back to front regarding your viewpoint
4. turn on depth test

The rendering speed will of course be affected by the way you choose to sort your faces.

I really don''t know what you mean with a chainlink "fenced off area" (my natural language isn''t english), so I really can''t tell you a good way to optimize it other than sorting the faces in real time (it will be slow).



Share this post


Link to post
Share on other sites
quote:
Original post by t0y
To correctly display transparency you need the following:

1. Draw opaque faces
2. turn off depth test
3. draw transparent faces back to front regarding your viewpoint
4. turn on depth test



Actually, depth test should not be turned off, since this would cause a tranlucent object to be blended with opaque objects located between the translucent object and the camera. The correct way is explained by Rui Martins in NeHe Tutorial 8:

"You should SORT THE TRANSPARENT POLYGONS BY DEPTH and draw them AFTER THE ENTIRE SCENE HAS BEEN DRAWN, with the DEPTH BUFFER ENABLED, or you will get incorrect results."

More info can be found at http://www.opengl.org/developers/faqs/technical/transparency.htm

Share this post


Link to post
Share on other sites
wont the alpha test do the job?

I''m assuming you are using the transparency only to show objects through the gaps in the fence.

I really like the alpha test a lot.

Share this post


Link to post
Share on other sites
quote:
Original post by sirius_black
wont the alpha test do the job?

I''m assuming you are using the transparency only to show objects through the gaps in the fence.


Good idea! Then the objects don''t even have to be sorted, right?

Could someone please send some code snippets (or link to a good code example)? What functions to use, which alpha test is recommended, possibility to use a bmp-image and use one of the colors as transparent (since bmp-images don''t have an alpha channel)?

And what about the masking technique used in NeHe Tutorial 20? Is it better, worse or just different?

Share this post


Link to post
Share on other sites
If you''re only using fully transparency/fully opaque objects, alpha testing will do the job perfectly. Map sure you''re using GL_NEAREST filtering and test for alpha>0. If you need GL_LINEAR filtering, test for alpha==1.

Share this post


Link to post
Share on other sites
quote:
Original post by nadam

Actually, depth test should not be turned off, since this would cause a tranlucent object to be blended with opaque objects located between the translucent object and the camera. The correct way is explained by Rui Martins in NeHe Tutorial 8:




I got it wrong! I meant making the depth buffer read-only.
This way transparent faces get drawn even if they can't be sorted correctly (overlap each other in 3D and 2D).

If the depth test is kept enabled and read/write, some parts of that faces would be discarded.

I'm sorry I didn't correct myself earlier, but I don't have internet access during the week


[edited by - t0y on April 26, 2002 8:10:08 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by t0y
I got it wrong! I meant making the depth buffer read-only.
This way transparent faces get drawn even if they can''t be sorted correctly (overlap each other in 3D and 2D).



Thank you for that great idea! Although it wouldn''t generate the correct result in all situations, at least it''s quicker than sorting and it would even allow intersecting triangles.

// Making the depth buffer read-only for those
// who haven''t looked it up yet...
glDepthMask( GL_FALSE );

For the "fence problem" that started this thread the glAlphaFunc seems to be the best solution. Still want to know if the usage of glAlphaFunc is better than the masking technique used in NeHe Tutorial 20. What''s the difference, logical, performance, etc? Or is the "tutorial 20 technique" just an old method used before the glAlphaFunc was added to OpenGL?

Share this post


Link to post
Share on other sites
nadam, the Alpha test is performed right after the Scissor Test. So if the fragment fails the alpha test it is discarded immediately and no stencil or depth test is performed (ie if they are enabled). Using the alpha test lets you get rid of the fragments very early in the pipeline.

The only advantage that the masking method gives is that you can do it without the alpha channel.But it requires two passes so it is not recommended.

Share this post


Link to post
Share on other sites

  • Advertisement