objects with alpha in fog look too light

Started by
2 comments, last by Erik Rufelt 15 years, 3 months ago
hello, i use the blendmode glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); in combination with premultiplied alpha glColor(r*a,g*a,b*,a); to correctly alphablend all of my objects. now i also use GL_FOG to fade my objects into a specific color at the horizon. the problem is, that semitransparent objects are not very well faded out when they are in the fog. instead they look lighter where they should actually have the exact same color as the fog. here is a screenshot: how can i avoid this, while still keeping the blendfunc i use? thanks!
Advertisement
anyone? :)
one more try, anyone? :-)
You probably can't.. do you need that particular blend function?
You use SourceColor + DestColor*(1 - SourceAlpha).. now I'm not entirely sure how the fog blending works.. but I would assume that it just changes the SourceColor to be more fog-like. Say that your source alpha is 0.5, and you're completely in the fog, that would make the result color as 1.5 * FogColor, which makes it lighter than it should. Is your alpha constant?
I don't remember if fog contains alpha, but if it does you could try changing the fog alpha to match the correct value..
The reason is that you do 1.0 * source + (1 - alpha) * destination, so if 1-alpha isn't zero, you will have more than 1.0 of color.

If you use shaders you can draw everything without fog first, then draw a fullscreen quad and blend everything to the fog-color in a pixel-shader, using the depth at each pixel, though it still won't be perfect since there won't be fog behind blended objects..
Perhaps draw the scene without blended objects with fog.. then blend the objects in without fog, then draw the fog on top of those objects or something =)

This topic is closed to new replies.

Advertisement