PDA

View Full Version : Nvidia Geforce PCX 5750 & ARB_fragment_program



MalcolmB
09-14-2004, 04:20 PM
Hi,
I'v been coding on ATI cards for a while and just got my hands on an nvidia one. I have a bunch of shaders that sample 8 textures and then do some simple calculations with them. There arn't multiple texture indirections or anything. Just the basic sample->calculate->output type shader.

They all worked fine on ATIs but the exact same shader doesn't work on this Nvidia card. The Nvidia card doesn't seem to sample the 6th,7th and 8th textures. I checked for errors using glProgramivARB and all that and it comes back saying everything is fine. The glGet calls to see how many tex coords and images that can be used in the shader came back as 8 and 16 respectively so it *should* work. Am I missing something, is this a driver bug or am I better off coding 2nd generation shaders on the NV extension instead for nvidia cards?

Thanks

Malcolm Bechard

sqrt[-1]
09-14-2004, 05:23 PM
Could you post the shader program? (or even better, an example app we can test?) I am not aware of any problems like this.

Chuck0
09-15-2004, 01:56 PM
i had a quite similar problem...
check if all your texture units are enables with glEnable(GL_TEXTURE_2D)...
ati cards seemed to even sample from texture units if they were only bound but not enabled (btw something i would wish would be standard since the type of texture sampling is defined in the fragment program anyways)

MalcolmB
09-15-2004, 02:09 PM
Here's the code. Pretty basic shader

"!!ARBfp1.0\n"
"ATTRIB texcoord0 = fragment.texcoord[0];\n"
"ATTRIB texcoord1 = fragment.texcoord[1];\n"
"ATTRIB texcoord2 = fragment.texcoord[2];\n"
"ATTRIB texcoord3 = fragment.texcoord[3];\n"
"ATTRIB texcoord4 = fragment.texcoord[4];\n"
"ATTRIB texcoord5 = fragment.texcoord[5];\n"
"ATTRIB texcoord6 = fragment.texcoord[6];\n"
"ATTRIB texcoord7 = fragment.texcoord[7];\n"
"PARAM w = program.env[0];\n"
"PARAM v = program.env[1];\n"

"OUTPUT oCol = result.color;\n"

"TEMP w1;\n"
"TEMP v1;\n"
"TEMP texCol0;\n"
"TEMP texCol1;\n"
"TEMP texCol2;\n"
"TEMP texCol3;\n"
"TEMP texCol4;\n"
"TEMP texCol5;\n"
"TEMP texCol6;\n"
"TEMP texCol7;\n"

"TEX texCol0, texcoord0, texture[0], 2D;\n"
"TEX texCol1, texcoord1, texture[1], 2D;\n"
"TEX texCol2, texcoord2, texture[2], 2D;\n"
"TEX texCol3, texcoord3, texture[3], 2D;\n"
"TEX texCol4, texcoord4, texture[4], 2D;\n"
"TEX texCol5, texcoord5, texture[5], 2D;\n"
"TEX texCol6, texcoord6, texture[6], 2D;\n"
"TEX texCol7, texcoord7, texture[7], 2D;\n"

"MUL texCol0, w1.r, texCol0;\n"
"MAD texCol0, texCol1, w1.g, texCol0;\n"
"MAD texCol0, texCol2, w1.b, texCol0;\n"
"MAD texCol0, texCol3, w1.a, texCol0;\n"
"MAD texCol0, texCol4, v1.r, texCol0;\n"
"MAD texCol0, texCol5, v1.g, texCol0;\n"
"MAD texCol0, texCol6, v1.b, texCol0;\n"
"MAD oCol, texCol7, v1.a, texCol0;\n"
"END\n";

Any ideas?

jra101
09-15-2004, 02:14 PM
Do you have a vertex program that outputs texture coordinates 0-7? If not, you'll only get texture coordinates 0-3 on NVIDIA cards as they only support 4 fixed function texture units.

MalcolmB
09-15-2004, 02:20 PM
Ya, I just noticed that while GL_MAX_TEXTURE_COORDS_ARB returns 8, GL_MAX_TEXTURE_UNITS_ARB returns 4..

I'm not using a vertex program, I'm just setting the coordinates using glMultiTexCoord for each unit.

So to get 8 sets of texture coordinates I need to calculate them in a vertex program?

jra101
09-15-2004, 02:28 PM
You can just add a passthrough vp:


!!ARBvp1.0
OPTION ARB_position_invariant;
MOV result.color, vertex.color;
MOV result.texcoord[0], vertex.texcoord[0];
MOV result.texcoord[1], vertex.texcoord[1];
MOV result.texcoord[2], vertex.texcoord[2];
MOV result.texcoord[3], vertex.texcoord[3];
MOV result.texcoord[4], vertex.texcoord[4];
MOV result.texcoord[5], vertex.texcoord[5];
MOV result.texcoord[6], vertex.texcoord[6];
MOV result.texcoord[7], vertex.texcoord[7];
END

MalcolmB
09-15-2004, 02:35 PM
Ok great, I bet thats my problem. Thanks a lot.

Isn't it kind of wierd that we are able to use commands like glActiveTexture(GL_TEXTURE7_ARB)
even when the MAX_TEXTURE_UNITS_ARB is 4?

MalcolmB
09-15-2004, 02:55 PM
Also, if I wanted to make this program dynamic so it increases/decreases the number of textures used depending on the card, should I do it according to the result of a glGet on GL_MAX_TEXTURE_COORDS_ARB?

Thanks

Korval
09-15-2004, 03:41 PM
Also, if I wanted to make this program dynamic so it increases/decreases the number of textures used depending on the card, should I do it according to the result of a glGet on GL_MAX_TEXTURE_COORDS_ARB?
Yes. As long as you are using a vertex and fragment program.

sqrt[-1]
09-15-2004, 03:42 PM
MalcomB :

I don't think it is so funny as if you read the ARB_fragment program spec (issue 16) there is a note stating that the old method is legacy with ARB_fragment_program (and ARB_fragment_shader) the two checks are now:
GL_MAX_TEXTURE_COORDS_ARB - For number of passable texture coordinates (from a Vertex program)
GL_MAX_TEXTURE_IMAGE_UNITS_ARB - For number of bindable textures

MalcolmB
09-15-2004, 06:21 PM
Hmm, using that vertex shader doesn't seem to fix it. It stops any textures from being sampled. I'm sure jra101 is right, so the question is what am I doing wrong?

I'v never used vertex shaders before, just pixel shaders. Is there anything special I need to do to use this shader? I also tried re-writing it so its using the more explicit ATTRIB and OUTPUT commands, same result (as expected I guess).

Maybe I should be moving these questions to the beginners forum now :)