Schatten Ebene
← Schatten | ● | Raycasting Varianten →
From Chapter 14 of the OpenGL Programming Guide:
Every possible projection of three−dimensional space to three−dimensional space can be achieved with a suitable 4×4 invertible matrix and homogeneous coordinates. If the matrix isn’t invertible but has rank 3, it projects three−dimensional space onto a two−dimensional plane. Every such possible projection can be achieved with a suitable rank−3 4×4 matrix.
To find the shadow of an arbitrary object on an arbitrary plane from an arbitrary light source (possibly at infinity), you need to find a matrix representing that projection, multiply it on the matrix stack, and draw the object in the shadow color. Keep in mind that you need to project onto each plane that you’re calling the “ground.”
As a simple illustration, assume the light is at the origin, and the equation of the ground plane is ax+by+c+d=0. Given a vertex S=(sx,sy,sz,1), the line from the light through S includes all points αS, where α is an arbitrary real number. The point where this line intersects the plane occurs when
so
Plugging this back into the line, we get
for the point of intersection.
The matrix that maps S to this point for every S is
If the light is from an infinite source, all you have is a point S and a direction D = (dx,dy,dz). Points along the line are given by
Proceeding as before, the intersection of this line with the plane is given by
Solving for α, plugging that back into the equation for a line, and then determining a projection matrix gives
Mit GLM bzw. GLSLmath:
mat4 P = mat4::parallel(p,n,d);
- p is the origin of the projection plane
- n is the normal of the projection plane
- d is the direction of the projection
Schattenebenen-Algorithmus:
Live-Demo: Shadow Plane (T#A10a)
← Schatten | ● | Raycasting Varianten →