Originally posted by Nutty:
[b]I’m not really bothered about the arguments passed into v[0], but I just happened to find it not working when I was experimenting.
Theres a limit to the number of C constants you can access in a single instruction. I was doing.
[/b]
Actually, now that we know that v[0] works, you can save 1 instruction in your vertex state program !!!
Here is what I did:
I created a Vector 4 class:
typedef struct
{
float x, y, z, w;
}Vector4;
This class is used for your light_pos variable:
// This is the position of the light.
Vector4 light_pos={0.0f, 2.0f, 4.0f, 1.0f};
Change your vertex state program to:
const unsigned char State1 =
{
“!!VSP1.0”
//Convert light in v[0] to local space in c[19]
“DP4 c[19].x,v[0],c[20];
DP4 c[19].y,v[0],c[21];
DP4 c[19].z,v[0],c[22];
DP4 c[19].w,v[0],c[23];”
“END”
};
Now, change your call to glExecuteProgramNV by:
//Execute state program. This converts the light position into local space!
glExecuteProgramNV(GL_VERTEX_STATE_PROGRAM_NV, 2, &light_pos.x);
You can delete the declaration of state_args as well as this piece of code:
//Reload the light position into register 8 for the vertex program to use.
glProgramParameter4fNV(GL_VERTEX_PROGRAM_NV, 8, light_pos.x, light_pos.y, light_pos.z, 1); // Light position.
Instead of passing the light position in c[8], you pass it as an argument to the vertex state programs via v[0]. And you can access v[0] in your DP4 without using a Rx register… Saved one instruction !
Regards.
Eric
P.S.: I e-mailed the modified source to you !