PDA

View Full Version : Problems with NV_texture_shader and DOT_PRODUCT_TEXTURE_2D_NV



zimmer
09-16-2005, 02:33 AM
We would like to create an equivalent of one of our ARB fragment programs for the old NV_texture_shader extension. The fragment program is very simple:

We have two 3D textures on texture units 0 and 1, and a 2D texture unit on texture unit 3. We take the texture coordinates to lookup the values in texture 0 and 1, and the we take this values as new texture coordinates for the 2D texture on unit 3. With this we perform a dependent texture read with two input values.

Now our approach for the NV_texture_shader: We too have the 3 textures on unit 0, 1 and 2. We create a standard texture lookup in stage 0 and 1, then we compute a GL_DOT_PRODUCT_NV in stage 2 with a constant vector (1,0,0) to get the R value of the first 3D texture. In stage 3 we also compute a dot product with (1,0,0) to get the R value of the second 3D texture, but we use GL_DOT_PRODUCT_TEXTURE_2D_NV to use the two values as new texture coordinates for the 2D texture on texture unit 3.
Well, my english is not that good so it might sound a little confusing, so I post the source code for better understanding:

float constant[] = {1.0, 0.0, 0.0};
glEnable(GL_TEXTURE_SHADER_NV);
glEnable(GL_REGISTER_COMBINERS_NV);

// stage 0 --> swizzle
glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_3D);
glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_3D); glDisable(GL_TEXTURE_3D);

// stage 1 --> swizzle
glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_3D);
glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_3D); glDisable(GL_TEXTURE_3D);

// state 2 --> get r for dependent texture lookup glActiveTextureARB(GL_TEXTURE2_ARB);
glMultiTexCoord3fv(GL_TEXTURE2_ARB, constant); glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_DOT_PRODUCT_NV); glTexEnvi(GL_TEXTURE_SHADER_NV, GL_PREVIOUS_TEXTURE_INPUT_NV, GL_TEXTURE0_ARB);

// stage 3 --> get r for dependent texture lookup and lookup in transfer glActiveTextureARB(GL_TEXTURE3_ARB);
glMultiTexCoord3fv(GL_TEXTURE3_ARB, constant); glTexEnvi(GL_TEXTURE_SHADER_NV, GL_PREVIOUS_TEXTURE_INPUT_NV, GL_TEXTURE1_ARB); glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_DOT_PRODUCT_TEXTURE_2D_NV);


// put alpha and rgb of texture unit 3 to output glCombinerParameteriNV(GL_NUM_GENERAL_COMBINERS_NV , 0); glFinalCombinerInputNV(GL_VARIABLE_A_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB); glFinalCombinerInputNV(GL_VARIABLE_B_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB); glFinalCombinerInputNV(GL_VARIABLE_C_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB); glFinalCombinerInputNV(GL_VARIABLE_D_NV, GL_TEXTURE3_ARB, GL_UNSIGNED_IDENTITY_NV, GL_RGB); glFinalCombinerInputNV(GL_VARIABLE_G_NV, GL_TEXTURE3_ARB, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);

glDisable(GL_REGISTER_COMBINERS_NV);
glDisable(GL_TEXTURE_SHADER_NV);

The problem is, that the result is very different to that of our shaders. We found out that the error might lie in the last texture shader stage: The dot product is NOT computed with the constant and the 3D texture, but with the 2D and with the 3D texture, and then used for lookup of the same 2D texture.

Do you have any ideas? We followed closely this tutorial: http://www2.imm.dtu.dk/~jab/shaderday/slides.pdf

Thanks for your help!

Greetings,
zimmer

CrazyButcher
09-16-2005, 05:29 AM
sorry for not really being a help, but you could try letting Cg compiler with fp20 profile do the job ?

jra101
09-16-2005, 08:36 AM
I don't see anything wrong with the code you posted, it should work fine.

Would you be able to send me a executable for your app that we can use to reproduce this problem internally?