Skip to main content
gamedev.net
🔒 Locked

Problems after adding vfog

Started by Fahrenheit451 Nov 29, 2004 at 5:55 AM 1 replies 600+ views
Original Post
Fahrenheit451
Fahrenheit451
Hi all. I thought my terrain generation was going well until I added volumetric fog. I have progressed to procedural texturing and multi-texturing and the results were quite good, but when I added fog a number of annomalies showed up in my rendering. Here is a shot of the terrain with and without fog: I really didnt see these problems with the terrain without fog, but now I have started zooming in and scrutinize the terrain, it looks as if there might be a problem, but I wonder if it's actually something to do with the way I configure the fog. eg. Per vertex fog works only cw, but I am rendering ccw - or something like that. Any ideas? btw. I am following examples in the Trent Polack book for the techniques. Here is my render routine:

// draw terrain mesh
// multi texturing
//bind the primary color texture to the first texture unit
glActiveTextureARB( GL_TEXTURE0_ARB );
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, m_texture.GetID() );
//bind the appropriate detail color texture to the second texture unit
glActiveTextureARB( GL_TEXTURE1_ARB );
glEnable( GL_TEXTURE_2D );
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB );
glTexEnvi( GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 2 );
glBindTexture( GL_TEXTURE_2D, detail.GetID() );

float a,b,c,d;
for ( int row = 0; row < (terrain.size-1); row++ ) {
  // draw triangle strip
  glBegin(GL_TRIANGLE_STRIP);
  for ( int col = 0; col < terrain.size; col++ ) {
    // caclulate texture coordinates
    a = (float)row/terrain.size;
    b = (float)col/terrain.size;
    c = (float)(row+1)/terrain.size;
    d = (float)(col+1)/terrain.size;

    // set normal 
    glNormal3f(terrain.CNormal[row][col].x,terrain.CNormal[row][col].y,terrain.CNormal[row][col].z);
    if ( terrain.volumetricFog ) {
      // Set the fog coordinate for this vertex
      SetFogCoord(terrain.vfogHeight, terrain.CPoint[row][col].y);
    }
    if ( terrain.textureMode ) {
      glMultiTexCoord2fARB( GL_TEXTURE0_ARB, a, b );
      glMultiTexCoord2fARB( GL_TEXTURE1_ARB, a*terrain.detailRepeat, b*terrain.detailRepeat );
    }
    glVertex3f(terrain.CPoint[row][col].x*terrain.scale,terrain.CPoint[row][col].y*terrain.scale,terrain.CPoint[row][col].z*terrain.scale);

    if ( !terrain.PPNormal )
      glNormal3f(terrain.CNormal[row+1][col].x,terrain.CNormal[row+1][col].y,terrain.CNormal[row+1][col].z);
    if ( terrain.volumetricFog ) {
      // Set the fog coordinate for this vertex
      SetFogCoord(terrain.vfogHeight, terrain.CPoint[row][col].y);
    }
    if ( terrain.textureMode ) {
      glMultiTexCoord2fARB( GL_TEXTURE0_ARB, c, b );
      glMultiTexCoord2fARB( GL_TEXTURE1_ARB, c*terrain.detailRepeat, b*terrain.detailRepeat );
    }
    glVertex3f(terrain.CPoint[row+1][col].x*terrain.scale,terrain.CPoint[row+1][col].y*terrain.scale,terrain.CPoint[row+1][col].z*terrain.scale);
  }
  glEnd();
}
//unbind the texture occupying the second texture unit
glActiveTextureARB( GL_TEXTURE1_ARB );
glDisable( GL_TEXTURE_2D );
//unbind the texture occupying the first texture unit
glActiveTextureARB( GL_TEXTURE0_ARB );
glDisable( GL_TEXTURE_2D );




[Edited by - Fahrenheit451 on January 7, 2006 10:24:15 AM]
Ilici
Ilici
Show the code for SetFogCoord, and the code for initializing fog (glFog calls)

It looks like the fog coordniates are not assigned properly.

Also, use the glFogCoordPointerARB function (hm, not sure about the name, find it in the extension registry) to speed up everything and also create an array with the normals. You'll get a big speed boost.


EDIT: in your code, when setting the second fog coordinate why are you not using SetFogCoord(terrain.vfogHeight, terrain.CPoint[row + 1][col].y?
Fahrenheit451
Fahrenheit451
OMG I am an ass. I spent 4 hours troubleshooting this :( I wished there was another set of eyes in this house to help before I have to make an embarassing post! Thanks a lot! Works fine now.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.