

In this case, you have to find where the fog begins and ends, instead of the total distance between the view point and the destination point. Sometimes, the entire scene might not be in fog. You can consider the point of reflection as the “view point” for the purpose of fogging. In this case, you are just finding out how much fog there is between the point where the reflection happened and the closest intersection. If you are doing ray based rendering, like ray tracing or ray marching, you might find yourself trying to find how much fog is between points that don’t involve the view point – like if you are calculating the reflection portion of a ray. For instance, looking up at a mountain from inside the fog, the mountain won’t be fogged at all, even though it should be because you are inside of the fog.Ī better way to do it, if you intend for the camera to be able to go into the fog, is to calculate a fogging amount for a pixel based on how far away it is from the view point, and how dense the fog is between the view point and the destination point. That can make some fog that looks like this:Ī strange side effect of doing that though, is if you go down “into” the fog, and look out of the fog, things that should be fogged won’t. For instance you might say that pixels with a y axis value above 15 are unfogged, pixels with y axis values between 15 and 10 progressively get more fogged as they get closer to 10, and pixels with y axis values less than 10 are completely fogged.

One way is to “fake it” and do something like set the color of a pixel on an object to be based on it’s height.
#Fog math calculator how to
This blog post will explain how to render fog that has varying density, based on a function of X,Y,Z location in space, like in the picture above.

There are a number of ways to implement the effect of fog with modern real time rendered graphics.
