Skip to main content
GameDev.net gamedev.net
🔒 Locked

Shadow matrix

Started by raydog Jul 30, 2005 at 10:23 AM 1 replies 900+ views
Original Post
raydog
raydog
I have this shadow matrix I would like to use, but I read drawing the model twice gives z-buffer artifacts. Is there something out there I can pass as input my intersecting shadow polys and return one (or more) combined polys?

void 
shadowMatrix(GLfloat shadowMat[4][4], GLfloat groundplane[4], GLfloat lightpos[4]) { 
GLfloat dot; 
/* Find dot product between light position vector and ground plane normal. */ 
dot = groundplane[X] * lightpos[X] + 
groundplane[Y] * lightpos[Y] + 
groundplane[Z] * lightpos[Z] + 
groundplane[W] * lightpos[W]; 
shadowMat[0][0] = dot - lightpos[X] * groundplane[X]; 
shadowMat[1][0] = 0.f - lightpos[X] * groundplane[Y]; 
shadowMat[2][0] = 0.f - lightpos[X] * groundplane[Z]; 
shadowMat[3][0] = 0.f - lightpos[X] * groundplane[W]; 
shadowMat[X][1] = 0.f - lightpos[Y] * groundplane[X]; 
shadowMat[1][1] = dot - lightpos[Y] * groundplane[Y]; 
shadowMat[2][1] = 0.f - lightpos[Y] * groundplane[Z]; 
shadowMat[3][1] = 0.f - lightpos[Y] * groundplane[W]; 
shadowMat[X][2] = 0.f - lightpos[Z] * groundplane[X]; 
shadowMat[1][2] = 0.f - lightpos[Z] * groundplane[Y]; 
shadowMat[2][2] = dot - lightpos[Z] * groundplane[Z]; 
shadowMat[3][2] = 0.f - lightpos[Z] * groundplane[W]; 
shadowMat[X][3] = 0.f - lightpos[W] * groundplane[X]; 
shadowMat[1][3] = 0.f - lightpos[W] * groundplane[Y]; 
shadowMat[2][3] = 0.f - lightpos[W] * groundplane[Z]; 
shadowMat[3][3] = dot - lightpos[W] * groundplane[W]; 
}
S1CA
S1CA
Render the shadow(s) into the stencil buffer instead of to the screen. Then apply a shadow coloured quad/sprite over the whole screen with stencil test set to only render shadow coloured pixels for those pixels which are set in the stencil buffer (i.e. the shadowed parts).
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site
raydog
raydog
I'm doing this for some older graphics cards without stencil support, so I would like to render
it as a non-intersecting poly.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.