no light with light class

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

Well i guess the nvparse code would help some.

nvparse(
"!!RC1.0
"
"{
"
" rgb
"
" {
"
" discard = unsigned_invert( tex0 ) * unsigned_invert( zero );
"
" discard = -expand( col0 ) * expand( col0 );
"
" spare1 = sum();
"
" }
"
" alpha
"
" {
" discard = expand( col1.b ) * unsigned_invert( zero );
"
" discard = expand( col1.b ) * unsigned_invert( zero );
"
" spare0 = sum();
"
" scale_by_four();
"
" }
"
"}
"
"{
"
" alpha
"
" {
"
" spare1 = unsigned( spare0.a ) * spare1.b;
"
" }
"
"}
"
"out.rgb = unsigned( zero );
"
"out.a = unsigned( spare1.a );
"
);

nvparse(
"!!RC1.0
"
"{
"
" rgb
"
" {
"
" spare0 = expand( tex0 ) . expand( tex1 );
"
" }
"
"}
"
"out.rgb = unsigned( zero );
"
"out.a = spare0.b;
"
);

nvparse(
"!!RC1.0
"
"final_product = tex1 * col0;
"
"out.rgb = tex0 * final_product;
"
"out.a = unsigned_invert(zero);
"
);

-SirKnight

[This message has been edited by SirKnight (edited 05-17-2002).]

[This message has been edited by SirKnight (edited 05-17-2002).]

Can’t really help you, except to maybe point out obvious stuff in the vein hope that it triggers something…
Have you:-

  • enabled vertex programs?
  • enabled register combiners?
  • enabled the correct blending modes?

…err, that’s all my mushed up brain can come up with…sorry again.

Yes, yes and yes. Its wierd cuz its mostly like Ron’s demo, the only thing i dont do is do that funky stuff he did w/ the texture matrix but im not worried about spotlights right now, only pointlights so that part shouldnt matter.

-SirKnight

Tre blend func lessequal.That worked for me.

Do you have an ambient pass? And if yes, do you really draw that pass with black color or only to the z-buffer?

Update:
Ok, you have an ambient pass; just read your comment again…

[This message has been edited by LaBasX2 (edited 05-18-2002).]

I already tried the LEQUAL thing and it dont help, i just tried it again 10 seconds ago too. This is really wierd. Im kinda thinking it may be the tangent space stuff is not right but im not sure exactly. LEt me post my function that makes the tangent space stuff, it looks ok but maybe im making some dumb mistake im not catching.

void MakeTangentBasis( void )
{
float tex1[2] = {0},
tex2[2] = {0},
tex3[2] = {0};

for( int currObj = 0; currObj < 5; ++currObj )
{
g_objPolyArray[currObj].basis = new tangent_basis[g_objPolyArray[currObj].numPolys];

  for( int currPoly = 0; currPoly < g_objPolyArray[currObj].numPolys; currPoly+=3 )//++currPoly )
  {			
  	tex1[0] = g_objPolyArray[currObj].polys[currPoly].tex[(currPoly + 0) % 3].x;
  	tex1[1] = g_objPolyArray[currObj].polys[currPoly].tex[(currPoly + 0) % 3].y;	

  	tex2[0] = g_objPolyArray[currObj].polys[currPoly].tex[(currPoly + 1) % 3].x;
  	tex2[1] = g_objPolyArray[currObj].polys[currPoly].tex[(currPoly + 1) % 3].y;	

  	tex3[0] = g_objPolyArray[currObj].polys[currPoly].tex[(currPoly + 2) % 3].x;
  	tex3[1] = g_objPolyArray[currObj].polys[currPoly].tex[(currPoly + 2) % 3].y;	

  	TangentBasis( g_objPolyArray[currObj].polys[currPoly].v[(currPoly + 0) % 3], 
  				  g_objPolyArray[currObj].polys[currPoly].v[(currPoly + 1) % 3],
  				  g_objPolyArray[currObj].polys[currPoly].v[(currPoly + 2) % 3], 
  			      tex1,
  			      tex2, 
  			      tex3,
  			      g_objPolyArray[currObj].polyPlane[currPoly].normal, 
  				  
  			      g_objPolyArray[currObj].basis[currPoly].tangent,
  			      g_objPolyArray[currObj].basis[currPoly].binormal, 
  			      g_objPolyArray[currObj].basis[currPoly].normal 
  			    );
  }

}
}

-SirKnight

Well i realized something wrong with that last post of mine so now it computes the tangent basis like its supposed to. Im now doing it right after i compute the plane equation for each poly.

Ok well anyway, i found one thing that is a problem with my prog, when i set the PIXELFORMATDESCRIPTOR thing i had the alpha bits set to 0. So now i set it to 8 like it’s supposed to be. After this instead of my scene being fullbright it is now very dark, the only lighting thing that seems to work is the ambient. I made a change in one of my RC’s in nvparse and i now can barely see some bumps. Its still very dark and not correct at all, i see no attenuation or anything. What i changed was this:

"alpha
"
"{
"
" discard = expand( col1.b ) * unsigned_invert( zero );
"
" discard = expand( col1.b ) * unsigned_invert( zero );
"
" spare1 = sum();
"
" scale_by_four();
"
"}
"

To this:

"alpha
"
"{
"
" spare1 = expand( col1.b ) + expand( col1.b );
"
" scale_by_four();
"
"}
"

For some reason, after doing that, i see a few bumps a little bit. I thought those two pieces of code are the same. What is up with this?

I still cant figure out what the heck is going on here, the blending modes and stuff is correct. My other PPL demo works fine (no attenuation or any of the other fancy stuff) and im doing almost the same thing as im trying to do here, except im not using the alpha buffer in my other working demo. :stuck_out_tongue:

-SirKnight