Dot3 terrain engine

Member
Posts: 509
Joined: 2002.05
Post: #1
After creating a fast terrain engine that dynamically makes a 10000 triangle level of detail terrain out of a 1024x1024 16 bit height map, I have had some problems texturing it. I eventually came to this tutorial http://www.cs.auckland.ac.nz/~jvan006/mu...titex.html that uses dot3 and 2 texture units for 4 detail textures (one per channel) mixed over a RGB lightmap.

Here is how it SHOULD work

1. glColor3f is used to get the weights of each detail texture (R,G,B)
2. glColor3f dot3 detail texture = Texture Unit 0
3. Texture Unit 0 * Texture Unit 1 (lightmap) = Final value

Here is how mine is working

1. X,Y Pixel value of texture zero is used to get the weights of each detail texture (R,G,B)
2.X,Y Pixel value of texture zero dot3 detail texture = Texture Unit 0
3. Texture Unit 0 * Texture Unit 1 (lightmap) = Final value

So basically my problem is that the X,Y Pixel value of texture zero is being used instead of glColor3f. Can someone tell me whats wrong with this code?

Code:
glActiveTexture(GL_TEXTURE0);
            glEnable( GL_TEXTURE_2D );
            glBindTexture( GL_TEXTURE_2D, gv->texture[tdetail] );
            
            glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_DOT3_RGB);
            glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE0);
            glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
            glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PRIMARY_COLOR);
            glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
            
            glActiveTexture(GL_TEXTURE1);
            glEnable( GL_TEXTURE_2D );
            glBindTexture( GL_TEXTURE_2D, gv->texture[theightmap] );
            
            glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
            glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
            glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE1);
            glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
            glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_TEXTURE0);
            glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_ONE_MINUS_SRC_COLOR);

Thanks!
Quote this message in a reply
Member
Posts: 509
Joined: 2002.05
Post: #2
Can someone tell me if this code uses the primary color (glColor3f) value along with the value of texture tdetail in the dot3 function?


Code:
glBindTexture( GL_TEXTURE_2D, gv->texture[tdetail] );
                        
                        glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_DOT3_RGB);
                        glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE0);
                        glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
                        glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PRIMARY_COLOR);
                        glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
Quote this message in a reply
Hog
Member
Posts: 151
Joined: 2002.09
Post: #3
Jake Wrote:
Code:
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
    glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
    glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE1);
    glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
    glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_TEXTURE0);
    glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_ONE_MINUS_SRC_COLOR);

shouldn't you be using the result of the previous coloring instead of GL_TEXTURE0 there? ( glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PREVIOUS); )
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #4
If you didn't change GL_TEXTURE_ENV_MODE for unit0, then it defaults to GL_MODULATE and all of your other setup on that unit is ignored.

Also, be aware that if you specify GL_TEXTUREn as a source, then you're using ARB_texture_env_crossbar which is supported on less hardware than ARB_texture_env_combine. It is exported on Radeon7000+ on 10.3 and Radeon9600+ on 10.2. It won't work on Rage128. It isn't exported on any nvidia card, but it will work as long as you don't specify a texture unit that is unbound or bound to an invalid texture (I verified this in the ADC lab yesterday.)
Quote this message in a reply
Member
Posts: 509
Joined: 2002.05
Post: #5
I got it working, here was the correct code. Thanks for the help!!!

Code:
glActiveTexture(GL_TEXTURE0);
    glEnable( GL_TEXTURE_2D );
    glBindTexture( GL_TEXTURE_2D, gv->texture[tdetail] );
    
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
    glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_DOT3_RGB);
    glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE0);
    glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
    glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PRIMARY_COLOR);
    glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
    
    glActiveTexture(GL_TEXTURE1);
    glEnable( GL_TEXTURE_2D );
    glBindTexture( GL_TEXTURE_2D, gv->texture[theightmap] );
    
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
    glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
    glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE1);
    glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
    glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PREVIOUS);
    glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_ONE_MINUS_SRC_COLOR);
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  DOT3 Bump (Normal)Mapping Example isgoed 5 8,898 Apr 11, 2005 12:09 AM
Last Post: isgoed
  Best way to add roads/objects to a terrain engine? Jake 6 3,820 Sep 6, 2004 07:25 AM
Last Post: Jake
  Water gfx in a terrain engine Mars_999 3 2,989 Sep 4, 2003 04:32 PM
Last Post: David