Advertisement

Converting GPU assembly to Cg code....

Started by May 09, 2005 07:27 AM
-1 comments, last by Steve-B 19 years, 5 months ago
Hi peeps I'm learning Cg at the moment and it's going fairly well. However I like to understand the underlying mechanics also. I've been going through some source code on my computer and I'm trying to convert the assembly code to Cg code. The program is a very simple one so does anyone know what the Cg equivalent would be?? I've tried to understand the code by heavily commenting it. I think I'm on the right lines although the lighting code has got me a little confused. The object being rendered is a GLUT torus with it's own internal normals and the light is simply pointing in the positive z-axis (0,0,1). Here is the source I'm trying to convert:

// These four instructions convert the vertices from object space -> eye space

 DP4 R0.x,v[OPOS],c[0];		// ModelView transformation (Store the results in register R0)
 DP4 R0.y,v[OPOS],c[1];		// Register v[OPOS] contains the object-space vertex coordinates
 DP4 R0.z,v[OPOS],c[2];		// Registers c[0] to c[3] contain the modelview matrix
 DP4 R0.w,v[OPOS],c[3];		// Calculation = (object space coordinates * modelview matrix)
							
// These four instructions convert the vertices from eye space -> clip space

 DP4 R1.x,R0,c[4];		// Projection transformation (Store the results in register R1)
 DP4 R1.y,R0,c[5];		// Register R0 contains the eye-space vertex coordinates
 DP4 R1.z,R0,c[6];		// Registers c[4] to c[7] contain the projection matrix
 DP4 R1.w,R0,c[7];		// Calculation = (eye space coordinates * projection matrix)

// These four instructions convert the vertex normals from object space -> eye space??? Is this right??

 DP3 R2.x, c[0], v[NRML];	// Normal transformation (Store the results in register R2)
 DP3 R2.y, c[1], v[NRML];	// Register v[NRML] contains the vertex normal coordinates)
 DP3 R2.z, c[2], v[NRML];	// Calculation = modelview matrix * vertex normal)
 DP3 R2.w, c[8], R2;		// Lighting calculation (Register c[8] contains the light direction) Not sure About this one!

// This instruction multiplies the current vertex colour with the new lighting colour
// This new vertex colour is then stored in register R3 ready to be output to the GPU

 MUL R3.xyzw,v[COL0].xyzw,R2.wwww;

 MOV o[COL0],R3;		// Copy register R3 to the COL0 output register (vertex colour)
 MOV o[HPOS],R1;		// Copy register R1 to the HPOS output register (clip-space position)


This topic is closed to new replies.

Advertisement