# Exp2 Fog and direction in GLSL

Hi, I have a giant single quad that I’m using as a surface of water. I’m using the orange books implementation of the wobble shader from chapter 16 to create a really cool effect. I need to add fog on the top of this shader. I tried doing this the way the orange book recommends with ecPosition.z for the fog frag coord but this only seems to work properly if I’m facing a certain direction. When you face that direction it’s amazing, but any other way and the fog is far too thick. Here are my shaders, can anyone help?
vs:

`````` void main(void)
{
gl_Position     = ftransform();

vec3 ecPosition = vec3(gl_ModelViewMatrix * gl_Vertex);
gl_TexCoord  = gl_MultiTexCoord0;
gl_FogFragCoord = abs(ecPosition.z);
}
``````

fs:

`````` const float C_PI    = 3.1415;
const float C_2PI   = 2.0 * C_PI;
const float C_2PI_I = 1.0 / (2.0 * C_PI);
const float C_PI_2  = C_PI / 2.0;

uniform vec2  Freq;
uniform vec2  Amplitude;
float fog;

uniform sampler2D WobbleTex;
uniform int mode;

void main (void)
{
if (mode==1)
{
vec2  perturb;
vec4  color;

// Compute a perturbation factor for the x-direction

// Wrap to -2.0*PI, 2*PI

// Center in -PI, PI

// Center in -PI/2, PI/2

// Now compute a perturbation factor for the y-direction

// Wrap to -2*PI, 2*PI

// Center in -PI, PI

// Center in -PI/2, PI/2

color = texture2D(WobbleTex, perturb + gl_TexCoord.st);
color = vec4(mix(color.rgb,vec3(0.0, 0.08, 0.2),0.72), 0.72);
fog = exp(-gl_Fog.density * gl_Fog.density * gl_FogFragCoord * gl_FogFragCoord);
fog = clamp(fog, 0.0, 1.0);
color.rgb = mix(vec3(gl_Fog.color),color.rgb, fog);
gl_FragColor = color;
}
else