Quote:Original post by Christian Johansson
Think of he pointlight as this: A light bulb, that i think might clear some of ur confusiness! ;P
Nope, it doesn't. A light bulb is modeled often as a point light (what actually discards the penumbra shadows, but makes the life much easier). That is actually the assumption I've already made. However, you don't compute the shadow volume for a light bulb but for something like a _sun_.
The difference is as follows: The light bulb is positioned in the room of your scenery, e.g. a latern dangling from the ceiling. The bulb radiates in all directions, so it illuminates all walls, the floor and the ceiling. The light is emitted _spherically_ from the idealized point of the light. Moving the light source around makes a difference, at least if the light is moved out of the room ;-)
In comparison the sun is far away from the earth. Moving the sun a kilometer in any direction makes no difference here on earth, so that the position of the sun (as a light source) plays no role. The light rays coming here are nearly _parallel_. So a sun could be modeled as a pure directional (parallel) light source.
For the projection of the model vertices one needs the "ray" of a light from the source to the vertex. Expressed in code, it may look like this:
// a light basis classclass Light {public: virtual void getProjectorForVertex(const Vector& positionOfVertex,Vector& projector) =0;};// a point light, as a model of a light bulbclass PointLight : public Light {public: Vector ownPosition; // a position vector !! void getProjectorForVertex(const Vector& positionOfVertex,Vector& projector) { projector.x = positionOfVertex.x - ownPosition.x; projector.y = positionOfVertex.y - ownPosition.y; projector.z = positionOfVertex.z - ownPosition.z; // here should possibly be done some normalization }};// a pure directed light, as a model of the sun (as long as staying on earth)class DirectedLight : public Light {public: Vector ownDirection; // a direction vector !! void getProjectorForVertex(const Vector& positionOfVertex,Vector& projector) { projector.x = ownDirection.x; projector.y = ownDirection.y; projector.z = ownDirection.z; }};
When applying this stuff to a given vertex position P, one has to get the projector for the vertex P, and to add the projector to P. So one gets
P1' := P + d in case of a directed light w/ direction d, and
P2' := P + ( P - L ) in case of a point light w/ position L.
Since P isn't constant, the (direction) vector P-L isn't constant, too. In opposite to d, that actually _is_ constant. So there is definitely a difference in the two light sources.
Now look at your code. You compute the projected vertex like
P' := P - 500*L
Besides the fact that you scale and subtract a position vector (what I've said it earlier, has no geometrical meaning), the _structure_ of this formula is that of P1', and also L is a constant as is d of P1'! So you actually do _not_ compute a lighting as from a bulb, but from a directed source!!!
EDIT: Please bear in mind that the spaces of the model and the lights must be the same; I haven't shown that in the snippet above for clarity (and convenience ;-)
EDIT: To make clear what the geometrical difference is: If a ball is lit by the sun, it casts a (nearly) cylindrical shadow. If, on the other hand, the ball is lit by a point light, it casts a conical shadow. At least if the point light is moved to "infinity" (where the sun approximately is), the difference of a point light and a pure directed light disappears!
[Edited by - haegarr on November 10, 2005 2:26:41 AM]