Page 3 of 3

Re: (libogc) hardware lights

Posted: Sun Sep 05, 2010 6:24 pm
by shagkur
Hi,

basically that's not completely wrong what you do. The difference to mine is that, for a point light, i don't initialize the light direction.
Furthermore i have angle attenuation turned off. And the distance attenuation function i use is GX_DA_MEDIUM.
So here's, pretty short, the way i do it (for a point light):

Code: Select all

   guVector lpos = {0,-50,50};

   guVecMultiply(view,&lpos, &lpos);

   GX_InitLightPos(&lobj,lpos.x,lpos.y,lpos.z);
   GX_InitLightSpot(&lobj,0.0f,GX_SP_OFF);
   GX_InitLightDistAttn(&lobj, 100.0f, 0.5f, GX_DA_MEDIUM);
   GX_InitLightColor(&lobj,SC_WHITE);
   GX_LoadLightObj(&lobj,GX_LIGHT0);
In wiirrlicht a light is a normal scenenode as well and translated/rotated/scaled by a matrix. To gain the direction, for spotlight or directional light, i use guVecMultiplySR() with an input vector of { 0.0f,0.0f,-1.0f }. But the light direction vector is only used for spotlights and directional lights.

Have a look at lightscenenode.cpp and in gxdriver.cpp at assignHardwareLight. In lightscenenode.cpp i "manually" calculate the distance attenuation coefficients but the formula is the one from GX_DA_MEDIUM.
Again: Every local light, regardless if it's a point light or spot light has a light radius, so i can calculate the DA coefficients. Also such a radius for local lights makes it possible to do some kind of culling for lights (look in gxdriver.cpp at loadLocalLights()).

Re: (libogc) hardware lights

Posted: Tue Sep 07, 2010 8:07 am
by shagkur
Hi,

you've had any success with hardware lighting now?

best regards
shagkur

Re: (libogc) hardware lights

Posted: Tue Sep 07, 2010 8:20 am
by techhnik
Well, I haven't tried much because I'm in the middle of my exams. However I've got it more-less working, though I still don't understand how can that be that two faces being at moreless the same distance from the light source can be lit or darken just depending on the orientation if we're not using the normals. That's in fact the part I don't get to work. Also I have been thinking about what causes the bad results in diffuse lighting. The thing is that AF_SPEC works bad, DF_CLAMP works bad, but AF_SPOT works right. And what do Spec and diffuse have in common, different from spot (at least as documentation says)? Normals. Spot lights don't use normals in calculations. Spec and diffuse do. Is there a possibilitiy that normal matrix gets bad loaded or the transformation has a bug?

Re: (libogc) hardware lights

Posted: Tue Sep 07, 2010 11:40 am
by shagkur
Well, in my setup GX_DF_CLAMP is still used even though i've GX_AF_SPOT turned on too. So for my understanding in this setup the vertex normals are used aswell in the lighting calculation. As a little sidenote: I didn't renormalize the normals in the RMS mesh loader when i ported it over to wiirrlicht.
I never use AF_SPEC. For specularity i use the TEV and a texture (seen in example 6 & 8).
About the matrix, i presume you load the modelview matrix into the position matrix and a inverse-transpose matrix of the modelview matrix into the normal matrix slot?

best regards
shagkur

Re: (libogc) hardware lights

Posted: Tue Sep 07, 2010 3:50 pm
by techhnik
Now it works fine shagkur. Thank you so much, Hardware lighting will speed up my engine a lot. Also, for specular lighting I think i'll follow your path and use per-pixel lighting. Once again, thank you so much.

Re: (libogc) hardware lights

Posted: Tue Sep 07, 2010 6:23 pm
by shagkur
Hi,

that's great news! Nice to hear you got it working! :)

best regards
shagkur