Re: Fog question

New Message Reply Date view Thread view Subject view Author view

Dave Akers (dla)
Thu, 4 Nov 1999 15:01:00 -0800


Mark,

  So, there are actually several problems with the sample code for fog
that you presented. If you are using GL_EXP as your fog mode, then
GL_FOG_START and GL_FOG_END have no effect. I can see that you were trying
to set them to the near and far clipping planes, but that's not how fog
works in EXP mode.. Here are the equations in OpenGL for calculating the
"fog factor" used to blend the incoming fragment color with the fog color:

GL_EXP:
  f = e^(-density*z)

GL_EXP2:
  f = e^(-density*z)^2

GL_LINEAR:
  f = (end-z)/(end-start)

where z is the eye coordinate distance between the viewpoint and the
fragment center. (In orthographic viewing projections, z is just the z
coordinate of the transformed point, in camera coordinates!) The final
computed color C = f*C_i + (1-f)*C_f, where C_i is the incoming fragment's
color and C_f is the fog color you specified. All of this is straight from
the red book, by the way..

Since you're working in orthographic projection mode (in voglSimple),
you're getting a tiny little band of volume right through the center of
your volume (i.e., halfway between the near and far clipping planes), and
the color quickly fades to the fog color on either side of this band. This
makes perfect sense, since this band represents z ~= 0, and your fog
density is extremely high given the range of z values you have.

So, the solution is to either use GL_LINEAR with end and start set
appropriately, or (if you want to use GL_EXP) adjust your viewing matrix
with an extra translate so that z=0 becomes the near clipping plane.
(You'll also need to adjust the clipping planes themselves, of course.)
Then find an appropriate density (much lower) using the equations above.

By the way, it looks like you have GL_FOG_START and GL_FOG_END reversed in
the code you gave. Remember that glOrtho() specifies -near and -far, not
near and far clipping planes.

Let us know if you still have problems..

-Dave

On Thu, 4 Nov 1999, Mark Davey wrote:

> Concerning the depth enhancement question. I had looked into fog but
> things were not clear!
>
> I included the following code into the file voglSimpleVolume.cxx at the
> beginning of the my_DrawVolume() function but without success. The
> result was a thin band of lit volume, with everything else being in the
> dark.........Help........!
>
>
>
> void
> my_DrawVolume(
> voIndexedTetraSet * aTetraSet, voBrickSetCollection * aVolume)
> {
> int brickNo;
> GLdouble modelMatrix[16], projMatrix[16];
>
> // Extra code
>
> glEnable(GL_FOG);
> GLfloat fogColor[4] = {0.0,0.0,0.0,1.0};
> glFogi(GL_FOG_MODE,GL_EXP);
> glFogfv(GL_FOG_COLOR,fogColor);
> glFogf(GL_FOG_DENSITY,0.35);
> glFogf(GL_FOG_START,-modelSize[2]*2.5);
> glFogf(GL_FOG_END,modelSize[2]*2.5);
>
> //----------
>
>
> Regards
> Mark...
>
>
>
>
> --
> From: Mark Davey
> Dept. of Medical Physics, UCL.
>
> TEL: +44 (0)171 915 1673.
> FAX: +44 (0)171 837 9279.
>
> Institute of Laryngology and Otology,
> 330 Gray's Inn Road,
> London.
> WC1X 8GE.
>
>
>


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Thu Nov 04 1999 - 17:17:08 PST