Vertex Program Problems: texture matrix tracking

I’m having a bit of trouble with my vertex program.

  1. What is the correct way to pass the texture matrix of, say unit 2, to the vertex program?
    Is it this:-
    glActiveTextureARB(GL_TEXTURE2_ARB);
    glTrackMatrixNV(GL_VERTEX_PROGRAM_NV, 12, GL_TEXTURE, GL_IDENTITY_NV);
    Because if I use rows c[12]->c[15] I don’t seem to get any change to my texture coordinates.

  2. I’m using my vertex program in conjunction with VAR and fences. I’m getting flickering on the odd frame, as if the modelview matrix is being reset in mid-draw.
    I’m using matrix push/pops throughout my app, so could they be interfering with the geforce fetching & transforming vertices from the VAR in AGP?

I really need some kind of reply, as my absolute deadline for this stuff is Wednesday, but I need some testing time before then.
Any help would be brilliant…

You can pass the GL_TEXTUREi_ARB directly to the glTrackMatrixNV function, like so

glTrackMatrixNV( GL_VERTEX_PROGRAM_NV, 12, GL_TEXTURE2_ARB, GL_IDENTITY_NV );

I’m not sure what could be wrong with your second point - I use VAR/Fences with vertex programs too, however I don’t track matrices ( I used to but I always forgot to untrack them ).

I’m getting just an identity for the texture matrix every time.

In my C code, I’m doing this every frame:-

glActiveTextureARB(GL_TEXTURE0_ARB);
glMatrixMode(GL_TEXTURE);
static float ang=0.0f;
glLoadIdentity();
glTranslatef(0.5fcos(kMath::conDegToRad(ang)), 0.5fsin(kMath::conDegToRad(ang)), 0.0f);
ang+=1.0f;
glMatrixMode(GL_MODELVIEW);

…in the vertex program setup (called every frame) I’m doing this:-

glTrackMatrixNV(GL_VERTEX_PROGRAM_NV, 20, GL_TEXTURE0_ARB, GL_IDENTITY_NV);

…and in the vertex program itself, I’m doing this (where R5 = the vertex position, and c[24] is a constant scaling factor to generate s,t coords on the xz plane):-

DP4 R7.x, c[20], R5;
DP4 R7.y, c[21], R5;
DP4 R7.z, c[22], R5;
DP4 R7.w, c[23], R5;

MUL o[TEX0].xyz, R7.xzyw, c[24].xzyw;

The resulting texture coordinates are unchanged. The texture doesn’t scroll, which it should do (and does when not using the vertex program).
Any ideas?

Strange…

You’ve probably already thought of this but try calling the track command before updating the matrices. Other than that it should work.

I tried using the code you posted and it works ( the texture scrolls in a circular motion - vertex arrays specified using VAR ). It doesn’t seem to matter where the track call is made either.

I’m using Detonators 27.10.

EDIT: I didn’t use the scaling factor though.

[This message has been edited by PH (edited 01-27-2002).]

Thanks for your help PH.
Sorted out the flickering - it was my own foolish fault - I was overwriting vertex information with tangents! I’ve got my own memory manager for AGP memory, so I wasn’t doing anything illegal, as the memory I was overwriting was legally allocated…but of course it screwed up my vertices.
Still hasn’t solved my texture matrix tracking problem though.

I’m having trouble with my reflection stuff.
Basically, I’m trying to implement per-pixel reflections into a cube map (from a normal map). I’m using the texture shader for the reflection. I’m trying to use a vertex program to set up the texel matrix - but I’m getting odd results.

Here’s the part of my vp that constructs the texture coordinate for the texture shader matrix:-

(c[8]->c[11] = inverse transpose modelview matrix)
(R0=normal, R1=tangent, R2=binormal, R3=NON-UNIT LENGTH eye-to-vertex vector)

// transform tangent by inverse transpose modelview matrix & move into first column of texel matrix:-
DP4 o[TEX1].x, c[8], R1;
DP4 o[TEX2].x, c[9], R1;
DP4 o[TEX3].x, c[10], R1;

// transform binormal by inverse transpose modelview matrix & move into second column of texel matrix:-
DP4 o[TEX1].y, c[8], R2;
DP4 o[TEX2].y, c[9], R2;
DP4 o[TEX3].y, c[10], R2;

// transform normal by inverse transpose modelview matrix & move into third column of texel matrix:-
DP4 o[TEX1].z, c[8], R0;
DP4 o[TEX2].z, c[9], R0;
DP4 o[TEX3].z, c[10], R0;

// move the eye-to-vertex vector into the fourth column of texel matrix:-
MOV o[TEX1].w, R3.x;
MOV o[TEX2].w, R3.y;
MOV o[TEX3].w, R3.z;

The results I’m getting are that if I tilt the camera down around the x-axis it looks correct, but if I rotate the camera around the y-axis, then tilt down the z-axis, the cube map tilts down the x-axis still. What am I doing wrong?

If I transform the eye-to-vertex vector by the modelview inverse transform and put the result in the w column I get the cube map in eye-space (ie. looks like its glued to the camera on the y-axis, but tilts correctly).

Please help me - it looks so good, but not correct. I feel I’m nearly there.

Just wanted to say that I sorted all my problems out, and I’ve now got an unbelievably beautiful seascape for my renderer. NVidias textureshader/vertexprograms/registercombiner/VAR extensions have enabled me to make it look stunning, and I’m still getting 60fps. It’s a happy day for me!
Aren’t vertex programs cool? There’s something weird about programming the card like that…

BTW, if you create a cubemap out of different sized images using glTexImage2D, your computer will hang. Not just a crash, but a complete system hang, forcing you to hit the restart button.

Originally posted by knackered:
BTW, if you create a cubemap out of different sized images using glTexImage2D, your computer will hang. Not just a crash, but a complete system hang, forcing you to hit the restart button.

You should e-mail a sample app to Matt so that he can fix that.

Regards.

Eric

The problem with vertex programs and temporaries should be fixed in a future driver.

A cubemap with different sizes on each face, or with non-square images, should cause its respective texture unit to become disabled.

  • Matt