PDA

View Full Version : no light with light class



SirKnight
05-17-2002, 02:51 PM
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 \n"
"DP4 o[HPOS].x, c[0], v[OPOS]; \n"
"DP4 o[HPOS].y, c[1], v[OPOS]; \n"
"DP4 o[HPOS].z, c[2], v[OPOS]; \n"
"DP4 o[HPOS].w, c[3], v[OPOS]; \n"

// 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]; \n" // Computes the surface to light vector
"DP3 R2.x, R0, c[4]; \n"
"DP3 R2.y, R0, c[5]; \n"
"DP3 R2.z, R0, c[6]; \n"

// Divide tangent space light by brightness (R, or radius), then scale it to fit in combiners
"RCP R1, c[7].w; \n" // c[7].w contains the brightness (R)
"MUL R3, R1, R2; \n" // R2 contains the tangent space light vector

// Scale to fit in combiners
"MOV R4.x, c[8].x; \n" // c[8].x containts 0.5
"MAD R3, R3, R4.x, R4.x; \n"

// Pass this into col0 and tex0 as tex coords
"MOV o[COL0], R3; \n"
"MOV o[TEX0], R3; \n"

// Pass the tangent space light (not scaled by brightness (R)) into col1
"MAD o[COL1], R2, R4.x, R4.x; \n"

"END \n";





const char vtxprog_diffuse_2of3[] =
"!!VP1.0 \n"
"DP4 o[HPOS].x, c[0], v[OPOS]; \n"
"DP4 o[HPOS].y, c[1], v[OPOS]; \n"
"DP4 o[HPOS].z, c[2], v[OPOS]; \n"
"DP4 o[HPOS].w, c[3], v[OPOS]; \n"

// 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]; \n" // Computes the surface to light vector
"DP3 R1.x, R0, c[4]; \n"
"DP3 R1.y, R0, c[5]; \n"
"DP3 R1.z, R0, c[6]; \n"

"MOV o[COL0], v[COL0]; \n"

"MOV o[TEX0], v[TEX0]; \n" // Move bumpcoords into tex0
"MOV o[TEX1], R1; \n"

"END \n";





const char vtxprog_diffuse_3of3[] =
"!!VP1.0 \n"
"DP4 o[HPOS].x, c[0], v[OPOS]; \n"
"DP4 o[HPOS].y, c[1], v[OPOS]; \n"
"DP4 o[HPOS].z, c[2], v[OPOS]; \n"
"DP4 o[HPOS].w, c[3], v[OPOS]; \n"

"MOV o[COL0], v[COL0]; \n"

"MOV o[TEX0], v[TEX0]; \n"
"MOV o[TEX1], v[OPOS]; \n"

"END \n";


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. http://www.opengl.org/discussion_boards/ubb/wink.gif Im not sure what else to say, um, if anyone wants the whole project ill zip it up. Thanks for any help given.

-SirKnight

SirKnight
05-17-2002, 02:58 PM
Well i guess the nvparse code would help some. http://www.opengl.org/discussion_boards/ubb/wink.gif




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





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





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


-SirKnight

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

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

knackered
05-17-2002, 03:31 PM
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.

SirKnight
05-17-2002, 04:54 PM
Yes, yes and yes. http://www.opengl.org/discussion_boards/ubb/smile.gif 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

Tandy
05-18-2002, 12:08 AM
Tre blend func lessequal.That worked for me.

LaBasX2
05-18-2002, 01:37 AM
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).]

SirKnight
05-18-2002, 08:02 AM
I already tried the LEQUAL thing and it dont help, i just tried it again 10 seconds ago too. http://www.opengl.org/discussion_boards/ubb/smile.gif 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

SirKnight
05-20-2002, 05:15 PM
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. http://www.opengl.org/discussion_boards/ubb/smile.gif 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 \n"
"{ \n"
" discard = expand( col1.b ) * unsigned_invert( zero ); \n"
" discard = expand( col1.b ) * unsigned_invert( zero ); \n"
" spare1 = sum(); \n"
" scale_by_four(); \n"
"} \n"


To this:




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


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. :p

-SirKnight