PDA

View Full Version : ATI GreenBlue Dependent Texture Reads



fuzzywells
12-16-2003, 02:24 PM
Okay, I am sure this is not an uncommon problem, converting software from Nvidia to ATI. What I am trying to do is take the color values from a Green Blue texture map and use them for the S & T coords for a texture lookup for the current texture (a normal map). Thus: result = N1(G0,B0)

Here is the original code:




// setup texture 1: normal texture
// using dependent texture read:
// n(G, B) = normal vector encoded in RGB
// using dot3 texture environment
// result = light_direction dprod surface_normal
// output1 = constant dprod texture
opengl->ActiveTexture(GL_TEXTURE1);
opengl->BindTexture(GL_TEXTURE_2D, m_texture[NORMAL]);
opengl->TexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_DEPENDENT_GB_TEXTURE_2D_NV);
opengl->TexEnvi(GL_TEXTURE_SHADER_NV, GL_PREVIOUS_TEXTURE_INPUT_NV, GL_TEXTURE0);
opengl->Disable(GL_TEXTURE_GEN_S);
opengl->Disable(GL_TEXTURE_GEN_T);
opengl->TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);


And with practically no experience with ATI_FRAGMENT_SHADER, here is my conversion:




opengl->glSampleMapATI(GL_REG_0_ATI, GL_TEXTURE0, GL_SWIZZLE_STR_ATI);
opengl->ColorFragmentOp1ATI(GL_MOV_ATI, GL_REG_2_ATI, GL_NONE, GL_NONE, GL_NONE, GL_NONE, GL_NONE);
opengl->ColorFragmentOp1ATI(GL_MOV_ATI, GL_REG_2_ATI, GL_RED_BIT_ATI, GL_NONE, GL_REG_0_ATI, GL_GREEN, GL_NONE);
opengl->ColorFragmentOp1ATI(GL_MOV_ATI, GL_REG_2_ATI, GL_GREEN_BIT_ATI, GL_NONE, GL_REG_0_ATI, GL_BLUE, GL_NONE);
opengl->ColorFragmentOp1ATI(GL_MOV_ATI, GL_REG_0_ATI, GL_NONE, GL_NONE, GL_REG_2_ATI, GL_NONE, GL_NONE);
opengl->SampleMapATI(GL_REG_1_ATI, GL_REG_0_ATI, GL_SWIZZLE_STR_ATI);


And it's giving me blackness, naturally. Thus, I think there MUST be a smarter way of extracting the green & blue values and using them as the S&T values for the texture 1 lookup than the admittedly hokey way I'm doing it here.

Ideas?

Fuzzy

[This message has been edited by fuzzywells (edited 12-16-2003).]

zeckensack
12-17-2003, 02:31 PM
I've become a bit rusty on this, but here goes


opengl->glSampleMapATI(GL_REG_0_ATI, GL_TEXTURE0, GL_SWIZZLE_STR_ATI);

opengl->ColorFragmentOp1ATI(GL_MOV_ATI, GL_REG_2_ATI, GL_RED_BIT_ATI, GL_NONE, GL_REG_0_ATI, GL_GREEN, GL_NONE);

opengl->ColorFragmentOp1ATI(GL_MOV_ATI, GL_REG_2_ATI, GL_GREEN_BIT_ATI, GL_NONE, GL_REG_0_ATI, GL_BLUE, GL_NONE);

opengl->SampleMapATI(GL_REG_1_ATI, GL_REG_2_ATI, GL_SWIZZLE_STR_ATI);

opengl->ColorFragmentOp1ATI(GL_MOV_ATI, GL_REG_0_ATI, GL_NONE, GL_NONE, GL_REG_1_ATI, GL_BLUE, GL_NONE);

The only notable change is the move to REG_0 in the second pass. REG_0 is the output and must be written to in the "output pass" IIRC.

I've also eliminated two moves that I think weren't necessary.

Hope this works http://www.opengl.org/discussion_boards/ubb/wink.gif