Hi
I’m implementing lightmaps, and i’m using the tecnique described for the apparition engine, to get the light impact on a surface.
Well, briefly, what i do is the following:
First, i seek in the polygon, wich ones have the same axis coordinate, if all the X’s are equals then i work in Z/Y, if all the Y’s are equal i work in XZ, and if all the Z’s are equal i work in XY.
lets’s imagine i’m working in XY
My next step, is to find out the biggest X and the lowest X, the biggest Y, and the lowest Y.
X = BIG_X - MIN_X;
Y = BIG_Y - MIN_Y;
As i’m using 16x16 lightmaps, i’m going to get the u,v steps to scan the polygon
u_steps = X /16;
v_steps = Y /16;
for(float xx=MIN_X; xx<= BIG_X; xx=xx + u_steps)
{
for(float yy=MIN_Y; yy<=BIG_Y; yy = yy + v_steps)
{
float position[3];
position[0] = xx;
position[1] = yy;
position[2] = next_dados->z[0]; // this is from the structure where my poly is stored
// Get the distance from the light
float distancia=Distance(position,light_source);
attenuation = (distancia*distancia) / (RADIUS*RADIUS);
intensity = 1 - attenuation;
Value[p] = intensity;
p++;
}
}
p=0;
To render the lightmap, i doing this:
Using normal polygon coordinates, but divided by the lightmap height/lenght.
glTexCoord2f(next_dados->u[i]/16,next_dados->v[i]/16);
Now, my lightmaps don’t look correct, they appear dark/bright where they shouldn’t.
Also, the variable Value, that is where i’m storing the values of the lightmaps, i see that for 0 i get total darkeness, 1 total darkeness, but 0.50 it’s bright!! how come ?
shouldn’t be 0, total dark, 1 total brightness?
I’m using GL_LUMINANCE!
thanks for any help
Bruno