Iam trying to render some 3d objects using opengl. Requirement is that i need to hide all the transparent objects which are z-behind another transparent object. All the triangles are in single triangle buffer and will be drawn at once. Please throw some light.
Asked
Active
Viewed 6,906 times
3
-
Can you comment on how your objects are transparent and what version(s) of OpenGL you are dealing with? – masebase Oct 05 '11 at 01:07
-
i am dealing with opengl 1.1 .. for example there are some glass vases inside a room which has glass doors. user should be able to see only opaque objects inside the room like wooden furniture through the glass door but not the glass vases inside the room. – user942502 Oct 05 '11 at 01:31
2 Answers
5
Try using glDepthMask():
//Render all opaque objects
glDepthMask(false); //disable z-testing
//Render all transparent objects*
glDepthMask(true); //enable z-testing (for the next frame)
*Technically, you should render the transparent objects from back to front, but it is rarely noticeable if you don't.

fintelia
- 1,201
- 6
- 17
3
You can do this by sorting your scene, which is what you have to do anyway to get transparency working correctly.
Here's what you need to do:
- Enable z-buffer writes and tests
- Render all opaque objects
- Render all transparent objects front to back. The z-buffer will prevent transparent objects from being displayed behind other transparent objects.

geofftnz
- 9,954
- 2
- 42
- 50
-
Thanks for the reply. yes i can achieve this by sorting the transparent triangles(front to back). but all the triangles of transparent objects are drawn in one go. when i rotate the scene, the effect should preserve. unfortunately sorting is not allowed in my task because i am dealing with half a million of triangles in a scene. do you think i can achieve this using some combimation of blendfunction. – user942502 Oct 05 '11 at 02:37
-
I'm not sure this is possible, at least with OpenGL 1.1 functionality. Can you split into 2 buffers? – geofftnz Oct 05 '11 at 02:58
-
No i cannot split in to 2 buffers as i do not have classification of which triangles form vase and which triangles form door in my triangle buffer. – user942502 Oct 05 '11 at 03:05
-
You don't need to know that... I mean split buffer into opaque triangles and transparent ones. – geofftnz Oct 05 '11 at 03:16
-
yes that splitting i have already done.. i am drawing all opaque triangles first and then all transparent triangles.. but i have conflict among transparent triangles here. an transparent object should not be visible through another another transparent object. Between opaque and transparency everything works fine. – user942502 Oct 05 '11 at 03:19
-
2Just out of interest, why should transparent objects behind other transparent objects not be displayed? – geofftnz Oct 05 '11 at 03:21
-
Looks like you'll need to do your own depth-sorting or occlusion-culling on your transparent triangle buffer. – geofftnz Oct 05 '11 at 03:23
-
i would like to have a transparency effect similar to catia's implementation. yes have gone through dual-depth peeling algorithm from nvidia.. probably it might be of some help if it is fast enough. – user942502 Oct 05 '11 at 03:54