1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
glDisable(GL_LIGHTING);
glDepthMask(GL_FALSE);
glDepthFunc(GL_LEQUAL);
glEnable(GL_STENCIL_TEST);
glColorMask(0, 0, 0, 0);
glStencilFunc(GL_ALWAYS, 1, 0xffffffff);
// first pass, stencil operation decreases stencil value
glFrontFace(GL_CCW);
glStencilOp(GL_KEEP, GL_KEEP, GL_INCR );
mShadowList::const_iterator it;
for(it=mShadowLocalList.begin(); it!=mShadowLocalList.end(); ++it)
{
Shadow* pShadow = *it;
HardwareVertexBuffer* vb = pShadow->getVertexBuffer();
float* vShadow = pShadow->getVertexShadow();
size_t numberVertex = pShadow->getNumberVertexShadow();
float* currentShadow = vb->lock();
for(int i = 0; i < numberVertex; i++)
currentShadow[i] = vShadow[i];
vb->unlock();
glColor3f(0.0, 0.0, 0.0);
//glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
render(vb, NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
NULL, GPT_QUADS);
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}
// Now we render the shadow volume again and this time we decrement the stencil every
// where that is not in the area being rendered. In other words this is for every
// thing outside the shadow area.
glFrontFace(GL_CW);
glStencilOp(GL_KEEP, GL_KEEP, GL_DECR);
for(it=mShadowLocalList.begin(); it!=mShadowLocalList.end(); ++it)
{
Shadow* pShadow = *it;
HardwareVertexBuffer* vb = pShadow->getVertexBuffer();
//glColor3f(1.0, 1.0, 0.0);
render(vb, NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
NULL, GPT_QUADS);
}
glFrontFace(GL_CCW);
glColorMask(1, 1, 1, 1);
//draw a shadowing rectangle covering the entire screen
glColor4f(0.0f, 0.0f, 0.0f, 0.4f);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glStencilFunc(GL_NOTEQUAL, 0, 0xffffffff);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
glPushMatrix();
glLoadIdentity();
glBegin(GL_TRIANGLE_STRIP);
glVertex3f(-0.1f, 0.1f,-0.10f);
glVertex3f(-0.1f,-0.1f,-0.10f);
glVertex3f( 0.1f, 0.1f,-0.10f);
glVertex3f( 0.1f,-0.1f,-0.10f);
glEnd();
glPopMatrix();
glDisable(GL_BLEND);
glDepthFunc(GL_LEQUAL);
glDepthMask(GL_TRUE);
glEnable(GL_LIGHTING);
glDisable(GL_STENCIL_TEST);
glShadeModel(GL_SMOOTH); |
Partager