PDA

View Full Version : Lightning



Ievgen
10-23-2009, 02:44 PM
Hi guys,

I wrote a very simple program and faced with a next thing.
I am drawing the next picture : there is a plane drawed by a rectangle function, from one side of the plane there is a directed light source, and from the opposite site there is a sphere. The problem is next i cannot observe light on the rectangle, but i can see it on the sphere, when the cut off angle is small. But when i increase a cut off angle i see alight of whole plane. I can't see the real light effect on the plane.

To solve this problem i can do next :
to break to smaller pieces my entire plane and this solution works.
But this is some harder job for PC to draw a lot of rectangles than just one.

So are the some specific functions in OpenGL to overcome this problem?

aqnuep
10-23-2009, 05:04 PM
You probably use a point light.

Legacy fixed function OpenGL lighting is based on per-vertex lighting calculations which means that light contribution is done only for the vertices that makeup your geometry. In case of a rectangle these are the four corners of it. This means that if e.g. the light is situated near the middle of the rectangle, the whole rectangle seems to be dark.

To overcome this problem I would advice you the following solutions:

1. use a directional light because it works fine also for vertex-lighting
2. if point light is a must then tesselate the rectangle (i.e. break to smaller pieces)
3. if you want to achieve better lighting quality use some per-pixel lighting techniques if the hardware can do it