PDA

View Full Version : Fog alpha values



02-15-2005, 01:41 AM
I've been trying to fade out distant hex grid lines in my game using fog, I assumed that if I set the line color to 0,0,0,0 and the fog color to 1,1,1,1 the alpha value of the lines should increase with the distance from the camera. With the blend func GL_ONE,GL_SRC_ALPHA this should fade out the lines in the manner I'm looking for. However, the line color changes but the alpha value doesn't. I tried using glAlphaTest to show any change in alpha value and none was apparent. Does GL 1.1 suppport alpha in fog? Any ideas how I can fade the lines to transparent without using alpha?

ZbuffeR
02-15-2005, 05:07 AM
Actually you should set the fog color to exactly the same as the line color, save the alpha.
- line color (0,0,0,0) to fog color (0,0,0,1)

02-15-2005, 11:29 AM
Thanks for the reply. However, the color seems to make no difference. I set it to white just to prove to myself that the fog was affecting the lines :)

Here's the map with white fog and increasing alpha
http://www.codehead.co.uk/images/hexfadetowhite.jpg

Here's the same shot with the fog set to 0,0,0,1
http://www.codehead.co.uk/images/hexfadetest.jpg

I don't get it, unless the lines alpha value is not affected by the fog.

vincoof
02-15-2005, 12:45 PM
Fog alpha doesn't matter.
The specification explicitly states that the fog stage doesn't change the alpha value, so if you call glColor(r,g,b,0) you will always get alpha=zero no matter the alpha you set up in the fog color.

02-15-2005, 02:14 PM
Thanks vincoof, that confirms what I thought.

I've managed to get the effect working using black lines, white fog and glBlendFunc(GL_DST_COLOR,GL_SRC_COLOR)

Screenshot of fade effect (http://www.codehead.co.uk/images/hexfade.jpg)

This avoids the need for alpha values.