Skip to content

Instantly share code, notes, and snippets.

@csrohit
Created January 1, 2024 19:24
Show Gist options
  • Save csrohit/42e50058e6f1c2304176828eba53606e to your computer and use it in GitHub Desktop.
Save csrohit/42e50058e6f1c2304176828eba53606e to your computer and use it in GitHub Desktop.
Projective Shadows in OpenGL
void setShadowMatrix(GLfloat *destMat, float *lightPos, double *plane)
{
GLfloat dot;
// dot product of plane and light position
dot = plane[0] * lightPos[0] + plane[1] * lightPos[1] + plane[2] * lightPos[2];
// first column
destMat[0] = dot - plane[0] * lightPos[0];
destMat[4] = 0.0f - lightPos[0] * plane[1];
destMat[8] = 0.0f - lightPos[0] * plane[2];
destMat[12] = 0.0f - lightPos[0] * plane[3];
// second column
destMat[1] = 0.0f - lightPos[1] * plane[0];
destMat[5] = dot - lightPos[1] * plane[1];
destMat[9] = 0.0f - lightPos[1] * plane[2];
destMat[13] = 0.0f - lightPos[1] * plane[3];
// third column
destMat[2] = 0.0f - lightPos[2] * plane[0];
destMat[6] = 0.0f - lightPos[2] * plane[1];
destMat[10] = dot - lightPos[2] * plane[2];
destMat[14] = 0.0f - lightPos[2] * plane[3];
// fourth column
destMat[3] = 0.0f - lightPos[3] * plane[0];
destMat[7] = 0.0f - lightPos[3] * plane[1];
destMat[11] = 0.0f - lightPos[3] * plane[2];
destMat[15] = dot - lightPos[3] * plane[3];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment