Jump to content
  • Advertisement
Sign in to follow this  
RabidSquirrel89

OpenGL Alpha Blending With Fog

This topic is 3117 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to give my game some fog as well as use alpha blended textures. I haven't had any issues doing either individually however I'm having some trouble when both are being rendered. I'm still new to OpenGL and I don't fully understand the mechanics of the calls such as glBlendFunc. Anyways, I posted some pictures of the results I get with the ways I'm blending. Also I've circled some of the edges of my alpha blended textures. image1 image1 image1 image1 image1 For each of these setups I'm using a nearly pure white fog color, except for the last image which the fog color is pure black. The objective is to have the alpha blending look like the first and last image, but with a fog color other than black (I have no idea why pure black fog works fine). The third image looks as if the fog and textures with alpha blending are being rendered out of order (not from furthest to closest), and I'm not sure how I'd fix that if it were the case. Any suggestions would be very much appreciated! EDIT: My apologies for the large pictures

Share this post


Link to post
Share on other sites
Advertisement
First, let me congratulate your detailed description with lots of useful screenshots and the very clear text. It surely helps alot comprehending the problem.

About fog and blending, without entering too much in details, when an object is rendered, fog affects the RGB color of the object being rendered, not the alpha ; then the computed RGBA color is then blended with the contents of the existing fragments in the framebuffer, using the blending equation you defined.

What you are trying to achieve is impossible with blending like (GL_ONE, GL_ONE_MINUS_SRC_ALPHA) because your blending technique consists in adding texels that fade to black when alpha fade to black, but the black texels will be bypassed by the fog (at least, the RGB part) and won't be black anymore, thus the problem in the third image.

My guess is that your alpha texture is passed as a modulation to the color texture. I'd say your color channel and alpha channel look like this, respectively :


In order to obtain the desired effect with blending + fog, first you have to build a full RGB texture, i.e. do NOT modulate the alpha channel into RGB. For instance the above texture example would yield the following RGB and alpha channels, respectively :


Then use this texture with (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA). You tried it and showed seams, but you did with alpha modulation into the RGB channel, please try it without alpha modulation and I'm pretty sure the render will be correct (i.e. no seam). With all that said and done, fog is yours : put the color you wish, be it white or black or grey or whatever groovy color and everything should be fine... at least, in theory !

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!