WebGL - How to draw fog with W

In this episode, I discuss how to use gl_Position.w to draw fog.
Fog factor = (end point - distance from eye point) / (end point - starting point)
Where starting point less than distance from eye point less than end point if fog factor == 1, then object is completely shown; if fog factor == 0, object completely hidden
fragment color = surface color fog factor + fog color (1-fog factor)
  • https://github.com/davidwparker/programmingtil-webgl/tree/master/0081-fog-part-2-w
© programmingtil.com