glslfog

Range Based Fog in GLSL


I've found a number of posts stating that the fog fragment distance can easily be obtained using gl_Position.z or gl_FragCoord.z/gl_FragCoord.w.

The problem is this makes a boundary where the fog begins.

What I want to do is determine this distance based on player's position such that there is a radius of fog around the player.

For simplicity say I want fog to be interpolated based on a pixel's distance from (0, 0, 0) in world space. Only pixels within fog_end of this coordinate are visible.


Solution

  • After some more searching I found what I am referring to is called range based fog rather than plane based fog.

    I also had a problem with having to few vertexes for this to work properly. As such the distance calculation needs to be in the fragment shader.

    Some helpful details can be found here.
    http://web.archive.org/web/20160615092925/http://in2gpu.com/2014/07/22/create-fog-shader/