I finally got my new per pixel lighting class engine to a point where i can actually use it and there seems to be a problem i cant seem to figure out. It’s pretty much based from the advanced per pixel lighting demo by Ron Frazier but different in many ways, like i use nvparse for example and i use vertex programs, etc. Well, when i run the program all i get is my little room with all the textures and its like there is no light at all, its all at full bright. It all looks good to me, iv’e looked over the code over and over for hours and it just doesnt make sence.
What i do is first draw the scene w/ their base textures and any ambient if i specify. Then i set the depth func to gl_equal and turn z-writes off. Then draw the light/s. After that is done i turn back on z-writes and put the depth func back to gl_less. Everything that the vertex programs needs is passed through glprogramparameter and stuff. All my tga’s are loaded and good to go, iv’e checked it to make sure. Im only messing w/ diffuse right now and will enable specular when diffuse works. Um…let me show you my three vertex programs, i have three b/c the diffuse takes three passes, likewise for specular.
const char vtxprog_diffuse_1of3 =
"!!VP1.0
"
"DP4 o[HPOS].x, c[0], v[OPOS];
"
"DP4 o[HPOS].y, c[1], v[OPOS];
"
"DP4 o[HPOS].z, c[2], v[OPOS];
"
"DP4 o[HPOS].w, c[3], v[OPOS];
"// Transform the light vector into tangent space
// c[4] - c[6] contains the tangent space matrix
// c[9] contains the object space light vector
"ADD R0, c[9], -v[OPOS];
" // Computes the surface to light vector
"DP3 R2.x, R0, c[4];
"
"DP3 R2.y, R0, c[5];
"
"DP3 R2.z, R0, c[6];
"// Divide tangent space light by brightness (R, or radius), then scale it to fit in combiners
"RCP R1, c[7].w;
" // c[7].w contains the brightness (R)
"MUL R3, R1, R2;
" // R2 contains the tangent space light vector// Scale to fit in combiners
"MOV R4.x, c[8].x;
" // c[8].x containts 0.5
"MAD R3, R3, R4.x, R4.x;
"// Pass this into col0 and tex0 as tex coords
"MOV o[COL0], R3;
"
"MOV o[TEX0], R3;
"// Pass the tangent space light (not scaled by brightness (R)) into col1
"MAD o[COL1], R2, R4.x, R4.x;
""END
";
const char vtxprog_diffuse_2of3 =
"!!VP1.0
"
"DP4 o[HPOS].x, c[0], v[OPOS];
"
"DP4 o[HPOS].y, c[1], v[OPOS];
"
"DP4 o[HPOS].z, c[2], v[OPOS];
"
"DP4 o[HPOS].w, c[3], v[OPOS];
"// Transform the light vector into tangent space
// c[4] - c[6] contains the tangent space matrix
// c[9] contains the object space light vector
"ADD R0, c[9], -v[OPOS];
" // Computes the surface to light vector
"DP3 R1.x, R0, c[4];
"
"DP3 R1.y, R0, c[5];
"
"DP3 R1.z, R0, c[6];
""MOV o[COL0], v[COL0];
""MOV o[TEX0], v[TEX0];
" // Move bumpcoords into tex0
"MOV o[TEX1], R1;
""END
";
const char vtxprog_diffuse_3of3 =
"!!VP1.0
"
"DP4 o[HPOS].x, c[0], v[OPOS];
"
"DP4 o[HPOS].y, c[1], v[OPOS];
"
"DP4 o[HPOS].z, c[2], v[OPOS];
"
"DP4 o[HPOS].w, c[3], v[OPOS];
""MOV o[COL0], v[COL0];
""MOV o[TEX0], v[TEX0];
"
"MOV o[TEX1], v[OPOS];
""END
";
My register combiner nvparse code looks correct (well the vtx programs look correct to me to). Lets see…I’m sure i am computing the tangent space matrix correctly, my function that computes it turned out looking just like the one in the nvidia headers, pretty wierd, since i wrote it all myself with out looking at theirs. But anyway, im only computing it per poly and i am using that, I havn’t computed it for each vertex but i think it still should work, just not look as great like around corners and stuff.
I’m going to keep hacking at it but in the mean time any tips would be great. I hate it when i look at code and it looks correct yet doesnt work. Im not sure what else to say, um, if anyone wants the whole project ill zip it up. Thanks for any help given.
-SirKnight