Categories

Fog

Fog is not that hard to implement, in fact it’s easy that it doesn’t pull down and doesn’t need much effort to integrate it into your code.

To do it, you just insert the following equation into your effect file, then calculate the result color as normal.

float l =  saturate((dist - fogNear) / (fogFar - fogNear) / clamp(world.y / (fogAltitude +1), 1, fogThinning))

From that equation, dist is the distance between the object’s position in world space and your camera (which is already in the world space), for other fog’s properties that are
- fogNear => the range that you will see clearly
- fogFar => how far you can look ahead (actually it’s radius from the camera’s position)
- fogAltitude => height that the fog is still effect the scene
- fogThinning => it’s just the reducer magnitude (to reduce l for even more)

Thus we get the percentage of  fog influenced in the particular pixel from that equation, l.
After that we take this l-value, to do the linear interpolation with the base color from the model (or just the color from the model, or even have previously calculated with another technique such as diffuse, specular highlight) to the fog color itself.

Now, we have the lovely mixed of both the color from fog and model’s color.

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">