View Full Version : point light with fragment program

12-21-2004, 06:22 AM
I am lighting a square with a point light. When there is some distance between the light and polygon, the polygon is lit correctly. it will lost the lighting effect when the light source is very close to the polygon center. I think maybe it is because the length of the interpolate result of light direction vector at the center is nearly 0, so the normalize returns incorrect result. I don't know if i am right. Anyone can help me with that?

12-21-2004, 12:41 PM
only when it is near the polygon center or generaly near the polygon.

well... if the light has no attenuation then if the light goes closer to the polygon then the polygon will become more and more darker. this is mathematicaly correct but in real life not exactly like that cause there are some photons that hit some surface and the lighen an other too. to achieve that you must use radiosity or photonmapping. ;)

12-21-2004, 02:28 PM
Supposing that your normals are right across the square this effect is correct when using ‘lambertian light’ (n dot l). Think about it: When the light is away from the surface the normals and the light vector to each point have a ‘similar’ direction so (n dot l) are not near zero.
When the light is closer to the surface those normals are near perpendicular to the light direction to the points that are not above the light point so (n dot l) tend to zero as you are going away from the point light in your square.

Hope this helps

12-21-2004, 08:24 PM
i am using fragment program to calculate the lighting per fragment on the polygon. Even the light direction is almost perpendicular to the vertex normal, the interpolated light direction near the center of the polygon is not, only the length of the vector is very small.

I found the same vertex/fragment program does not have that lighting problem on another program. I am still looking into it, hope there are more suggestions coming.

12-22-2004, 09:47 PM
You should try renormalizing the light vector in the fragment program. The interpolated value from the vertex program will have a length below 1 in the middle of the polygon.

Matt Zamborsky
12-23-2004, 10:03 PM
yes, this is the problem. I had the same problem, when I normalized the light vector only in vertex program, you must normalize it in fragment program.