PDA

View Full Version : exp2 Fog and direction in GLSL

Nick's a Novice
05-21-2006, 01:47 AM
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[0] = 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
rad = (gl_TexCoord[0].s + gl_TexCoord[0].t - 1.0 + StartRad) * Freq.x;

// 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
rad = (gl_TexCoord[0].s - gl_TexCoord[0].t + StartRad) * Freq.y;

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

// Center in -PI, PI

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