oFog = 1 - (distance(vertex_w, vecViewPos) - vecFog.x) * vecFog.z;

i use this for fog. vertex_w = vertex in world space.