(libogc) hardware lights

shagkur
Posts: 53
Joined: Thu Sep 08, 2005 8:40 pm

Re: (libogc) hardware lights

Post by shagkur » Sun Sep 05, 2010 6:24 pm

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()).

shagkur
Posts: 53
Joined: Thu Sep 08, 2005 8:40 pm

Re: (libogc) hardware lights

Post by shagkur » Tue Sep 07, 2010 8:07 am

Hi,

you've had any success with hardware lighting now?

best regards
shagkur

techhnik
Posts: 15
Joined: Sun Jun 20, 2010 9:21 pm

Re: (libogc) hardware lights

Post by techhnik » Tue Sep 07, 2010 8:20 am

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?

shagkur
Posts: 53
Joined: Thu Sep 08, 2005 8:40 pm

Re: (libogc) hardware lights

Post by shagkur » Tue Sep 07, 2010 11:40 am

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

techhnik
Posts: 15
Joined: Sun Jun 20, 2010 9:21 pm

Re: (libogc) hardware lights

Post by techhnik » Tue Sep 07, 2010 3:50 pm

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.

shagkur
Posts: 53
Joined: Thu Sep 08, 2005 8:40 pm

Re: (libogc) hardware lights

Post by shagkur » Tue Sep 07, 2010 6:23 pm

Hi,

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

best regards
shagkur

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests