Vertex shader

I’m tring to so some per-pixel bumpmapping but I’m new att vertex shaders and I can’t get the specular lighing right. Im using two cubemaps for the normalization. Here’s my code:

const unsigned char State1[] =
{
“!!VSP1.0”

//Convert light in v[0] to local space in c[30]
“DP4 c[30].x, v[0], c[12];
DP4 c[30].y, v[0], c[13];
DP4 c[30].z, v[0], c[14];
DP4 c[30].w, v[0], c[15];”

“END”
};

const unsigned char Bump[]=
{
“!!VP1.0”

//Convert Vertex position into clip space, using combined matrix. (modelview and projection)
“DP4 o[HPOS].x,v[OPOS],c[0];
DP4 o[HPOS].y,v[OPOS],c[1];
DP4 o[HPOS].z,v[OPOS],c[2];
DP4 o[HPOS].w,v[OPOS],c[3];”

//Get surface to light vector.
“ADD R0,c[30],-v[0];”

“DP3 R3.x, c[4],v[4];
DP3 R3.y, c[4],v[5];
DP3 R3.z, c[4],v[6];”

//MOV tangent space surface to light vector into Texture 3, for auto normalization per fragment.
“MOV o[TEX2], R3;”

//Output coords for bumpmap.
“MOV o[TEX0],v[1];
MOV o[TEX1],v[1];”

// Calculate half angle vector

//#Add specular
“MOV R1, c[5];
ADD R0, R1, R0;”
//ADD R0, R0, R1;"

//# Convert to tangent space
“DP3 R0.x, R0,v[4];
DP3 R0.y, R0,v[5];
DP3 R0.z, R0,v[6];”

//#Pass to unit 2
“MOV o[TEX3], R0;” \

“END”
};

void SetupVertexProgram(void)
{
glEnable(GL_VERTEX_PROGRAM_NV);

glGenProgramsNV(1, &g_state_program);
glLoadProgramNV(GL_VERTEX_STATE_PROGRAM_NV, g_state_program, strlen((char*) State1), State1);

glGenProgramsNV(1, &g_bump_program);
	
glBindProgramNV(GL_VERTEX_PROGRAM_NV, g_bump_program);
glLoadProgramNV(GL_VERTEX_PROGRAM_NV, g_bump_program, strlen((char * ) Bump), Bump);


//Load the Modelview matrix into Vector Registers c[0] to c[3].
glTrackMatrixNV(GL_VERTEX_PROGRAM_NV, 0, GL_MODELVIEW_PROJECTION_NV, GL_IDENTITY_NV);

//Load the concatenation of modelview and Projection matrix into Vector Registers c[4] to c[7].

// glTrackMatrixNV(GL_VERTEX_PROGRAM_NV, 4, GL_MODELVIEW_PROJECTION_NV, GL_IDENTITY_NV);

//Load the inverse transpose of the Modelview matrix. For transforming normals. Into registers c[8] to c[11].
glTrackMatrixNV(GL_VERTEX_PROGRAM_NV, 8, GL_MODELVIEW, GL_INVERSE_TRANSPOSE_NV);

//Load inverse modelview for converting the light position into local space. Registers c[12] to c[15]
glTrackMatrixNV(GL_VERTEX_PROGRAM_NV, 12, GL_MODELVIEW, GL_INVERSE_NV);

glTrackMatrixNV(GL_VERTEX_PROGRAM_NV, 16, GL_MODELVIEW, GL_TRANSPOSE_NV);

glProgramParameter4fNV(GL_VERTEX_PROGRAM_NV, 24, 0.5f, 0.0f, 0.0f, 0.0f);
glProgramParameter4fNV(GL_VERTEX_PROGRAM_NV, 25, 0.5f, 0.5f, 0.5f, 0.5f);

// glProgramParameter4fvNV(GL_VERTEX_PROGRAM_NV,26, view_direction);
glProgramParameter4fNV(GL_VERTEX_PROGRAM_NV, 26, -1.0f, 0.5f, 0.5f, 0.5f);

glProgramParameter4fNV(GL_VERTEX_PROGRAM_NV, 27, 1.0f, 0.0f, 0.0f, 0.0f);
glProgramParameter4fNV(GL_VERTEX_PROGRAM_NV, 28, 0.0f, 1.0f, 0.0f, 0.0f);
glProgramParameter4fNV(GL_VERTEX_PROGRAM_NV, 29, 0.0f, 0.0f, 1.0f, 0.0f);

glProgramParameter4fvNV(GL_VERTEX_PROGRAM_NV, 4, light_pos);
glProgramParameter4fvNV(GL_VERTEX_PROGRAM_NV, 5, objectViewDirection);

}

I have borrowed some code from Nuttys tutorials.
Anyone see the problem?

Regards, Ninja

Not sure I can’t help you with your problem, but I have two other suggestions.

  1. Use the ARB extension instead of the NV, it’ll let the app run on more hardware. They are so similar there’s no excuse for going with the NV extension on new applications.
  2. Use text files for your shaders instead of constant strings like that. It’s much more handy to deal with.

Ok thanks,
I think I know where the problem is now.
In my vertex shader I just do
//#Add specular
“MOV R1, c[5];
ADD R0, R1, R0;”

where c[5] is the viewdirection. But I think should add viewpos-vertexpos instead, as I did in the diffuse case.

If I instead put the viewpos in c[5], how could I do the calculation then? Do I have to covert the viewpos to localspace first, and then do like “ADD c[5] - v[0]” to get it right ?

//Regards, Ninja

Sorry, I can´t answer your questions (currently I read the VP specs), but I had to give a short remark.
Don´t say Vertex Shader, I DISlike that D3D term.
Use Vertex Program or VP instead .

Regards,
Diapolo

If you found a problem in my code, and need help, use these forums;
http://opengl.nutty.org/forum/

Thanks,
Nutty