0
votes

I understand how a simple GLSL fog shader works, but how can it be applied? Applying it directly to a terrain mesh does not produce the desired "fog" result. How would one mimic the built-in fog effects of OpenGL with a shader? The only thing that I can think of is applying the shader to a series of encased spheres around the camera, but that seems like a lot of work for just some fog.

Update: Some images to further explain.

This is the shader I have applied to my terrain mesh, and the result is not what I want:

http://puu.sh/31dft.jpg

This is the kind of effect I am looking to replicate:

http://mw2.google.com/mw-panoramio/photos/medium/4503932.jpg

2
How does it not produce the desired result? You have any screenshots some reference as to how you want it to look like?Grimmy
@Grimmy, see my updated postLucasS
So you want volumetric fog?Grimmy
@Grimmy, yes, if that is what accurately describes what I am trying to accomplish.LucasS
"simple" fog is, as the name suggests, simple. Reality isn't simple.Nicol Bolas

2 Answers

1
votes

Semi-realistic atmosphere rendering is an complex problem to which many (ongoing-) research is dedicated. In your reference photo there are essentially three major factors that can contribute to the particular composition: i. fog/haze ii. atmospheric scattering iii. altitude.

Simply put applying fog solely on objects such as terrain, is an inherently flawed concept, because fog occludes/obscures the transmittance of light. This includes the light from the sky. So in order to cover the scenario of fog being applied to the 'sky' another approach is required, involving post-processing. Essentially the position of every pixel needs to be reconstructed in 3d-space, and the fog algorithm needs to run over each of these.

Depending on particular the art-style this might be sufficient for your needs, however it's more complicated. This document, http://developer.amd.com/wordpress/media/2012/10/D3DTutorial_Crytek.pdf gives a nice starting point regarding atmospheric rendering (it includes volumetric fog).

0
votes

You have to set the fog color and the background color to be the same. Otherwise the effects look bizarre. The point of fog is to make distant objects "fade into the background". The problem with your image is that your background is bright blue, as if you wanted it to be a sunny, clear day. But the objects in your scene are fading to white, as if there was a very very thick fog. I suggest you find some compromise--use a grayish blue for both.