### Re: (libogc) hardware lights

Posted:

**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):

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

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);
```

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