PDA

View Full Version : fog not respecting depth?



DJ Tricky S
08-15-2000, 09:10 PM
Hello,

I've decided to add fog to my rendering engine. After I setup and enable fog however, the scene is fogged a constant amount irrespective of the depth (ie, objects at the near clip plane are fogged just as much as objects at the far clip plane). I set up fogging as shown in the GL red book, like so:

// gl is a struct I have to hod my GL globals
gl->fog_start= 0.f;
gl->fog_end= 10000.f; // far clip plane distance
gl->fog_density= 0.35f;
gl->fog_color.r= 0.f;
gl->fog_color.g= .5f; // make fog green so it's easy for me to see
gl->fog_color.b= 0.f;
gl->fog_color.a= 1.f;

glEnable(GL_FOG);
glFogi(GL_FOG_MODE, GL_EXP2);
glHint(GL_FOG_HINT, GL_DONT_CARE);
glFogf(GL_FOG_DENSITY, gl->fog_density);
glFogf(GL_FOG_START, gl->fog_start);
glFogf(GL_FOG_END, gl->fog_end);
glFogfv(GL_FOG_COLOR, (float *)&gl->fog_color);

glClearColor(gl->fog_color.r, gl->fog_color.g, gl->fog_color.b, gl->fog_color.a);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


Does anyone have any ideas what might cause OpenGL to behave in this fashion? Any help is greatly appreciated!

Relic
08-15-2000, 10:33 PM
FOG_START and FOG_END do not apply to EXP or EXP2 fog, only to linear fog.

You probably have full fog at the distance you're rendering. EXP2 goes up quickly.

Watch out, the fog calculation is working from the origin. Don't translate the projecttion matrix.

DJ Tricky S
08-17-2000, 03:58 PM
That was my typo there... I am actually using linear fog, but thanks for the tip; I realized what I was doing wrong - I was modifying the projection matrix elsewhere when I should not have been :P I am learning, slowly but surely... heheh