PDA

View Full Version : vertex_program (general q)



V-man
04-13-2002, 12:52 PM
Here's the code from liquad example in NV OpenGL SDK.
Is C[12]...c[15] arrays of 4 elements each?
and why does it contain the inverse modelview
matrix? It's automatically generated or what?

Why a VSP file and a VP file? How about straight opengl code (an example code that _doesn't_ use nvparse would be nice to see)?

Right now, I know what each instruction does but that's all. http://www.opengl.org/discussion_boards/ubb/smile.gif

V-man


!!VSP1.0
# Transforms the directional L vector from camera to object space.
# Computes an H vector in object space.
# Pre:
# c[12]...c[15] contains the inverse modelview matrix.
# v[0] contains the eye space light vector
# c[8] contains the eye space view vector
# Post:
# c[12]...c[15] contains the inverse modelview matrix.
# c[4] contains the object space L vector
# c[5] contains the object space H vector
# c[8] contains the object space V vector

# Store object space light direction.
DP3 R1.x, c[12], v[0];
DP3 R1.y, c[13], v[0];
DP3 R1.z, c[14], v[0];
MOV c[4], -R1;

# Fetch camera space view vector.
# Transform into object space.
MOV R2, c[8];
DP3 R3.x, c[12], R2;
DP3 R3.y, c[13], R2;
DP3 R3.z, c[14], R2;
MOV c[8], -R3;

# Compute H vector in object space.
ADD R4, -R1, -R3;
DP3 R0, R4, R4;
RSQ R2.x, R0.x;
MUL R5, R4, R2.x;
MOV c[5], R5;

END

davepermen
04-13-2002, 12:57 PM
well.. i'll go for re-reading the papers/specs/documents from nvidia http://www.opengl.org/discussion_boards/ubb/smile.gif

and for demos without nvparse and source including vertexprograms and vertexstateprograms, go for www.nutty.org (http://www.nutty.org)
who has some great examples on it

mproso
04-13-2002, 02:03 PM
VSP stands for vertex state programs and they differ from ordinary vertex programs
because they work outside glBegin/glEnd commands and you execute then by calling
glExecuteProgramNV. As name says they modify vertex state.
Those c[0]..c[95] are 96 constant registers and you can write values in those like this,

glProgramParameter4fNV(GL_VERTEX_PROGRAM, 4, 0,1,2,3);

writes in c[4] register and c[4] looks like this c[4].x = 0, c[4].y = 1, c[4].z = 2 and c[4].w = 3.

You can give matrices to vertex program like this

glTrackMatrixNV(GL_VERTEX_PROGRAM_NV,0,GL_MODELVIE W,GL_IDENTITY_NV);

and GL_MODELVIEW matrix will be stored in VP like this
c[0].x c[0].y c[0].z c[0].w
c[1].x c[1].y c[1].z c[1].w
c[2].x c[2].y c[2].z c[2].w
c[3].x c[3].y c[3].z c[3].w .

Second parameters in those function calls are indexes of constant registers.
You specify vertices and texture coordinates in your code as you like and information about vertex is stored in 15 vertex attribute registers,
register v[0] or v[OPOS] stores info about vertex position.
glVertex3f(1,1,1) gives you v[OPOS].x=1, v[OPOS].y=1, v[OPOS].z=1.
Look in specs for other attribute registers mnemonics.

Maybe someone with more experience in this subject can give more details.

Thanks,
mproso

mproso
04-13-2002, 02:33 PM
Sorry, there are 16 vertex attribute registers 0..15, and 16 output or result registers o[COL0],o[OPOS],o[HPOS]... so on. There are temporary registers (R0,R1..) but I cant remember how many. You specify vertex programs just like textures

glGenProgramsNV(1, &program_id);
glLoadProgramNV(GL_VERTEX_PROGRAM_NV,program_id,pr ogram_lenght,pointer_to_vertex_programa);
glBindProgramNV(GL_VERTEX_PROGRAM_NV, program_id);

enable it with glEnable(GL_VERTEX_PROGRAM_NV), and you are ready to show those vertices who is the boss ;-)

Hope this helps!