Computing distance from the eye

In the preceding code, we used the absolute value of the z coordinate as the distance from the camera. This may cause the fog to look a bit unrealistic in certain situations. To compute a more precise distance, we could replace the line:

float dist = abs( Position.z ); 

With the following:

float dist = length( Position.xyz ); 

Of course, the latter version requires a square root, and therefore would be a bit slower in practice.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.127.232