iDevGames Forums
Dot3 terrain engine - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: Dot3 terrain engine (/thread-6135.html)



Dot3 terrain engine - Jake - Nov 1, 2004 04:31 PM

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/multitex/multitex.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!


Dot3 terrain engine - Jake - Nov 2, 2004 08:01 PM

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);



Dot3 terrain engine - Hog - Nov 3, 2004 01:06 AM

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); )


Dot3 terrain engine - arekkusu - Nov 3, 2004 01:31 AM

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.)


Dot3 terrain engine - Jake - Nov 3, 2004 06:36 PM

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);