According to the derivation in the second chapter of the book "Real-time Shadow", the simplest shadow technique is realized.
Planar shadow a projection matrix to project the vertices of an object illuminated by the light in the direction of the light to the plane that receives the shadow.
The key question is how the projection matrix gets.
The shadow plane is represented by the following formula: where n is the normal, D is constant, and X is the point on the plane.
The light and the line in which the vertex is projected are represented by the following formula: where L is the position of the light source, V is the vertex being projected, and T is the coefficient.
Derivation process:
So finally the vertex coordinates that are projected onto the plane are written in the form of homogeneous coordinates:
The form of a matrix is
In order to implement in code, I added two new classes, namely mesh and program, because in the destruction involves the removal of OpenGL internal resources, so if you do not handle the copy construction and copy assignment will cause problems, So before you think about a good solution, they both become classes that can't be copied.
Code has been updated HTTP://WWW.EYESOURCECODE.COM/T/58005/1/1
Shader trip to the plane shadow (planar shadow)