Skip to main content
gamedev.net
🔒 Locked

Problem with transparencies

Started by pamaro Nov 28, 2004 at 3:49 PM 0 replies 750+ views
Original Post
pamaro
pamaro
Hi I've ran into something weird while checking out an OpenGL program... not sure what's causing it or if it can be fixed. Anyway, here's the problem. In the program, there's a model which is placed in the middle of two "walls". One of the walls is solid, while we can control the transparency of the other wall. We can also controlo the transparency of the model. When placing the second wall as semi transparent and the model as transparent, the expected result would be seeing only the two walls. However, I can see the outline of the model. Anyone knows why this happens? Here's a screenshot: http://img37.exs.cx/img37/5830/pic248.jpg
nihilisticod
nihilisticod
Your problem is Z-Buffering.

Drawing multiple translucent objects in a scene is always tricky... even more so if these objects are concave.

Basically, when you draw your model you have z buffering enabled. Even if it is transparent it still writes and checks against every pixel of the z-buffer.

So if you drew the model before the wall, even though it is clear, it is still setting z-depth at those pixels. The result is that when you draw the back wall with depth testing, the shillouete of the model will not be drawn.

The simplest fix would be to draw the opaque wall first. Then call DepthMask(GL_FALSE);. Then draw the model and the wall in either order.

This tells opengl to do depth compares, but not write anything new to the z-buffer. Which means that you can draw new things behind transparent polygons.

Depending on the blend operation you use, things may not look correct. Try changing the glBlendFunc or do somethign like: draw all transparent objects from farthest to nearest so it is consistant.

[Edited by - nihilisticod on November 28, 2004 4:19:29 PM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.