Jump to content
  • Advertisement
Sign in to follow this  
Fahrenheit451

Problems after adding vfog

This topic is 5132 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
Advertisement
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!