PDA

View Full Version : Light mapping



fenris
03-24-2000, 03:53 AM
Ok. Here's the situation. I have a surface and a point. The point represents a light. The light has a radius, color and intensity value. The intensity value of the light is anywhere from 1 to 0, 1 being full intensity, 0 beign totaly dimmed. The color is just an RGB val used to multiply color components of the light map. My question is, how can I determine the light's point of impact on the surface's plane, and generate a radial lightmap based on the distance of the light from the surface, the radius and the intensity values? I beleive the point of impact is (in pseudo-code):

impactx=light.origin.x - plane.normal.x*dist
impacty=light.origin.y - plane.normal.y*dist
impactz=light.origin.z - plane.normal.z*dist

where dist is:

dist=dotproduct(light.origin,plane.normal)-
planedistance(light.orign)

But I think this may be TOTALY wrong, but it seems right. Anyone have any ideas? Any online docs explaining the same, or near the same situation? Any help on this would be great! http://www.opengl.org/discussion_boards/ubb/smile.gif

FATBUDDHA
03-29-2000, 10:23 AM
I'm not sure exactly what you mean, but this is the way that I'd do it:

Get the values a, b, and c that describe your polygon, for the equation below:

0 = a*pointOnPoly.x + b*pointOnPoly.y
+ c*pointOnPoly.z

Then get the minimum distance to the plane using these values (I couldn't fit the z dimensions in the text box http://www.opengl.org/discussion_boards/ubb/wink.gif):

MinDist = a*light.ori.x + b*light.ori.y ...
---------------------------------
a*norm.x + b*norm.y ...

It's then pretty easy to get the coordinates of the closest point on the polygon if you need it (assuming your normals are normalised):

impactPos.x = light.ori.x + norm.x * MinDist

Presumably, you want to reduce the problem to a 2D one (so that you can get the distance from the light, based on the radial distance on the surface from the impactPos, and the surface normal.)

For large distances you can say (approximately):
lightNorm = radialDist/minDist
lightDist = minDist

And for small distances (or full accuracy) you can say:
lightNorm = inverseTan(radialDist/minDist)
lightDist = sqrRt(minDist^2 + radialDist^2)

I hope that I've explained this properly (besides which, you probably had the right idea yourself anyhow...)