I’ve just added lightmapping to my engine but

lightmaps does not look perfect because I cant get my lumel lighting equation to work.Can anyone help?(I have position of lumel in worldspace, it’s normal, distance to pointlight and light’s radiur).

# Lightmap generation

Can you give more details about “not perfect”?

Well, faces with lightmaps look nice but some of them are black even if distance to the light source is shorter than light radius. I use this equation:

Brightness = (1 - 1 / LightRadius * Distance ) * (cosAngle-0.5).

Here is mine:

Brightness=MIN (cos Angle*2.5 , 1 - 1.3 * Distance / Radius )

I’m also searching a better one

Y.

Isn’t the light intensity just the dot of

the face normal and the normalized direction

to the light, divided by the square of the

distance to the light? At least, I believe

that’s how physics works in general.

Then you apply the light function (i e

color, specular, etc).

I e if the point is P and the light is L and

the point normal is N, you’d get brightness

like this:

B = fL( N . Norm( L - P ) / ( | L - P | ** 2) )

(B = brightness, fL == light function).

Note that fL should probably return the

ambient value for negative arguments (i e

things facing away from the light).

Oh, and this argument to fL simplifies

reasonably well when you start writing it out

as coordinate operations. Especially the

| L - P | ** 2 part

Just copy the OpenGL lighting model and it’ll look good.

brightness = (1 / (c + d * length + e * length^2)) * dot(norm(L-P),Vertex_Normal);

where c,d,e are arbitrary constants.