PDA

View Full Version : fog and alpha



James W. Walker
07-23-2005, 09:20 PM
Fog seems to have an odd effect on translucent objects: The fog color affects them much more than opaque objects at the same distance from the viewer, and even if the alpha is 0.99, applying fog makes the translucent object much more translucent. Any idea what I could be doing wrong?

Omaha
07-23-2005, 09:53 PM
Remember when you're blending that you are including the existing fragment in the result, thus if you overlap translucent objects you can effectively double your fog coverage.

James W. Walker
07-23-2005, 11:45 PM
Originally posted by Omaha:
Remember when you're blending that you are including the existing fragment in the result, thus if you overlap translucent objects you can effectively double your fog coverage.I don't get that. Say I'm using white fog, and I render a triangle far enough away to be turned completely white. Then I overlap that with a triangle that's a little closer, so it doesn't turn completely white, and with an alpha of 0.99. The fact that there was something behind should make little difference. White fog shouldn't be able to make anything more white that a white clear color.

Perhaps pictures can make it clearer what I'm talking about. Here's a slightly transparent torus with white fog on its far side...
http://www.jwwalker.com/images/torus-fog-1.png

That's not so weird. But here is what it looks like when it is approximately edge-on:
http://www.jwwalker.com/images/torus-fog-2.png
Why is the distant white shining through the near blue?

ZbuffeR
07-23-2005, 11:58 PM
It looks like a lack of depth sorting/zbuffer.

07-24-2005, 07:40 AM
...FYI, fog blending has no affect on the rasterized alpha (spec, page 192)...

James W. Walker
07-24-2005, 08:04 AM
Originally posted by ZbuffeR:
It looks like a lack of depth sorting/zbuffer.Yet I am sorting the triangles back to front. If I turn off the fog and reduce the alpha, everything looks right.

James W. Walker
07-24-2005, 11:53 AM
Oops, never mind, found my bug. I was using another pass to draw specular highlights on transparent stuff, and neglected to turn off fog then. With fog off in the specular pass, things look more reasonable, at least with white fog.