using pixel textures in NV_texture_shader

Hello,

I’m trying to use the pixel texturing function in NV_texture_shader. I’m trying to do something pretty basic - use the R and G channels of one texture as the texture coordinates for another. I have the following code snippet. What am I doing wrong?!?!

// Pixel Texture Map. First texture used as
// texture coordinates. R and G channels go
// from 0.0 to 1.0. Alpha is set to 1.0.
glEnable(GL_TEXTURE_SHADER_NV);
glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexEnvi(GL_TEXTURE_ENV,
GL_TEXTURE_ENV_MODE, GL_REPLACE);
glTexEnvi(GL_TEXTURE_SHADER_NV,
GL_SHADER_OPERATION_NV, GL_TEXTURE_2D);

// Texture that I’m trying to map.
glEnable(GL_TEXTURE_SHADER_NV);
glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[1]);
glTexEnvi(GL_TEXTURE_ENV,
GL_TEXTURE_ENV_MODE, GL_REPLACE);

// Drawing a square w/texture map.
glBegin(GL_QUADS);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0f,
0.0f);
glVertex3f(-1.0f, -1.0f, 1.05f);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1.0f,
0.0f);
glVertex3f( 1.0f, -1.0f, 1.05f);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1.0f,
1.0f);
glVertex3f( 1.0f, 1.0f, 1.05f);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0f,
1.0f);
glVertex3f(-1.0f, 1.0f, 1.05f);
glEnd();
glDisable(GL_TEXTURE_SHADER_NV);
glFlush();

What I’m getting is the first texture mapped onto the square as a color texture instead of being used as texture coordinates. I’ve tried several combinations of these statements and still didn’t get the right mapping. It seems to work if I use the DEPENDENT_GB_TEXTURE_2D_NV, but I wanted to avoid using that. Thanks in advance for any help!

  • Q.

You can’t use the R and G channels of the first texture to index into the second. You must use the G and B, or the A and R channels.

Once you have the appropriate texture coordinates in tex0, you need to set the shader operation of tex1 to DEPENDENT_GB_TEXTURE_2D_NV or DEPENDENT_AR_TEXTURE_2D_NV.

Thanks for your reply!

Yes, what you suggest above works - using DEPENDENT_AR_TEXTURE_2D_NV. But, according to the specs, there’s the option to use conventional textures. Here’s what it says:
“TEXTURE_2D - Accesses a 2D texture via (s/q,t/q).”

where s and t is defined as the R and G channels. I’ve also seen examples (w/o code) that describe using the R and G channels as the pixel texture…

I’m concerned about using G and B or A and R, because I’m not sure that the DEPENDENT_AR_TEXTURE_2D_NV specification will work w/3D textures (which I’ll soon need to do). But, maybe it does?

  • Q.

The TEXTURE_2D operation just does a standard 2D texture lookup on the texture unit its specified on, it’s not a dependent texture lookup.

Yes, you can use the DEPENDENT_RGB_TEXTURE_3D_NV operation if you want to fetch from a 3D texture. This is exposed in the GL_NV_texture_shader3 extension, which is only supported on GeForce4 (NV25) and higher.

Ahh, ok great! Thanks for the info!

  • Q.