Results 1 to 9 of 9

Thread: OpenGL Fog

  1. #1
    Join Date
    Feb 2004
    Location
    U.K.
    Posts
    590

    OpenGL Fog

    Hey guys,

    In my application, i'm trying to add some simple fog. Its basically a skydome with certain colours applied to it. Now, I am getting the colour of the dome at the horizon and using that as the fog colour. If I set the clear colour to that aquired colour I see what I would expect. However when I apply that to the fog covering the terrain it goes pink! Have I done something wrong or is my game just gay?

    Here are some screenshots, one without any fog, and then with the fog turned on.

    Can anyone help me get my fog to a sensible colour?
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	scr1.jpg 
Views:	793 
Size:	62.0 KB 
ID:	51546   Click image for larger version. 

Name:	scr2.jpg 
Views:	690 
Size:	52.7 KB 
ID:	51547  

  2. #2
    Join Date
    Jan 2004
    Location
    South Pole
    Posts
    1,519
    Those are some nice looking screenshots. Where did you get the skydome texture?

    Could you show us the fog code?

  3. #3
    Join Date
    Feb 2004
    Location
    U.K.
    Posts
    590
    Thanks for the reply.

    Here is the fog code.
    Code:
    glFogi(GL_FOG_MODE, GL_EXP2);
    glHint(GL_FOG_HINT, GL_NICEST);
    glFogf(GL_FOG_START, 250.0f);
    glFogf(GL_FOG_END, 750.0f);
    glFogf(GL_FOG_DENSITY, 0.002f);
    
    Colour4f fogColour = dome->GetHorizonColor(cameraView);
    glClearColor (fogColour.r, fogColour.g, fogColour.b, fogColour.a);
    
    float fc[4];
    fc[0] = fogColour.r;
    fc[1] = fogColour.b;
    fc[2] = fogColour.g;
    fc[3] = fogColour.a;
    
    glFogfv(GL_FOG_COLOR, fc);
    You can see the clear colour is being set to the same colour as the fog colour, but the fog comes out pink even when the clear colour looks ok.

    Its not a texture i'm using for the sky colour. I'm working it out dynamically using perez equations which calculate the colour of a vertex based on its position, and the position of the sun. So i can change the time of day interactively and the colours of the sky change. Looks good but can beat your CPU up a bit if its old.

    You can download a beta version of the app from my website if you want a play:

    http://www.liquidhelium.net/download...cSky_Alpha.zip

  4. #4
    Join Date
    Jan 2004
    Location
    South Pole
    Posts
    1,519
    Interesting, what are these perez equations?

    The terrain surface, is it a material with lighting applied, or just a mesh with different colors applied to the vertices?

  5. #5
    Join Date
    Feb 2004
    Location
    U.K.
    Posts
    590
    The terrain is a model loaded in with the OBJ loader from the VTMs. I just have a plain grey material applied to it. It is lit by a directional light pointing from the suns position to the centre of the world (also the centre of the terrain).

    Perez developed a sky-luminance-distribution model. It takes the luminance at the zenith, darkening or brightening of the horizon, luminance gradient, intensity and width of the circumsolar region and relative back scattered light. From these the equations can work out the luminance and chromaticity of any point on sphere (like the earths atmosphere). Convert those values to rgb and you have your vertex colour!

    This link talks about the kinda stuff i'm doing:
    http://www.cs.utah.edu/vissim/papers/sunsky/

    You can dowload a pdf from there that talks about the perez equations.
    (Theirs looks a lot better than mine )

  6. #6
    Join Date
    Jan 2004
    Location
    South Pole
    Posts
    1,519
    The game is just gay.

    Other than that, the only thing I can think of is if you're doing something weird with blending. Perhaps you still have blending turned on when you're drawing the terrain? If so, I think that's the problem; try turning off blending when you're drawing terrain.

  7. #7
    Join Date
    Feb 2004
    Location
    U.K.
    Posts
    590
    Thanks for the suggestion Halma.

    I'm about to leave to go camping for the weekend so i'll give it a try when I get back.

    Cheers,

    Ian.

  8. #8
    Join Date
    Feb 2004
    Location
    U.K.
    Posts
    590
    Well it wasn't the blending. But I finally figured it out.

    It was in this bit :
    Code:
    float fc[4];
    fc[0] = fogColour.r;
    fc[1] = fogColour.b;
    fc[2] = fogColour.g;
    fc[3] = fogColour.a;
    I was setting it as RBG instead of RGB!

    Why is it always these stupid little things that keep me perplexed for ages!!!

    Oh well at least its fixed now!

  9. #9
    Join Date
    Jan 2004
    Location
    South Pole
    Posts
    1,519
    Well, I'm glad you found the problem.

    I've made it a habit to check little things like that very carefully after I write them, because I know that if it's wrong, debugging will be a nightmare. So for example if I have a vector class, I'll make sure all the operators (addition, subtraction, etc.) are correct, because if I have sum.x=a.x+b.y instead of sum.x=a.x+b.x, I'm going to be really confused for hours.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •