Hi,
I was able to fix the shadows when I change the following methods too look like this
private final void drawObjectShadow(GL gl, Occluder object, Point3f lightPosition)
{
object.getLocalToVworld().getOpengl(openGLProjMatrix);
gl.glPushMatrix();
gl.glMultMatrixf(openGLProjMatrix, 0);
gl.glDisableClientState(GL.GL_COLOR_ARRAY);
gl.glDisableClientState(GL.GL_NORMAL_ARRAY);
gl.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY);
gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
object.getBuffer().getCoordinateData().getFloatBuffer().rewind();
gl.glVertexPointer(3, GL.GL_FLOAT, 0, object.getBuffer().getCoordinateData().getFloatBuffer());
gl.glDrawArrays(GL.GL_TRIANGLES, 0, object.getBuffer().getValidVertexCount());
addTriangles( object.getBuffer().getValidVertexCount() / 3 );
gl.glPopMatrix();
}
/**
* draws the shadow volumns in the render bin
*
* @param bin
*/
protected final void drawShadows(GL gl, ShadowBin bin)
{
//ProfileTimer.startProfile("CanvasPeerImpl::drawShadows");
final int FULLMASK = 0xffffffff;
final int STENCIL_VAL = 128;
// determine edges
for (int i = 0; i < bin.size(); i++)
{
bin.getOccluder(i).determineVisibleEdges( bin.getLightSource() );
}
gl.glDisable(GL.GL_LIGHTING); // Turn Off Lighting
gl.glEnable(GL.GL_CULL_FACE);
gl.glCullFace(GL.GL_BACK);
gl.glDepthMask(false); // Turn Off Writing To The Depth-Buffer
gl.glDepthFunc(GL.GL_LEQUAL);
gl.glEnable(GL.GL_STENCIL_TEST); // Turn On Stencil Buffer Testing
gl.glColorMask(false, false, false, false); // Don't Draw Into The Colour Buffer
gl.glStencilFunc(GL.GL_ALWAYS, 1, 0xffffffff);
gl.glFrontFace(GL.GL_CCW);
// First Pass. Increase Stencil Value In The Shadow
gl.glStencilOp(GL.GL_KEEP, GL.GL_KEEP, GL.GL_INCR);
for (int i = 0; i < bin.size(); i++)
{
drawObjectShadow( gl, bin.getOccluder(i), bin.getLightSource() );
}
// Second Pass. Decrease Stencil Value In The Shadow
gl.glFrontFace(GL.GL_CW);
gl.glStencilOp(GL.GL_KEEP, GL.GL_KEEP, GL.GL_DECR);
gl.glColor3f(0f, 0f, 0f);
for (int i = 0; i < bin.size(); i++)
{
drawObjectShadow( gl, bin.getOccluder(i), bin.getLightSource() );
}
gl.glFrontFace(GL.GL_CCW);
gl.glColorMask(true, true, true, true); // Enable Rendering To Colour Buffer For All Components
// Draw A Shadowing Rectangle Covering The Entire Screen
gl.glColor4f(0.0f, 0.0f, 0.0f, 0.2f);
gl.glEnable(GL.GL_BLEND);
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
gl.glStencilFunc(GL.GL_NOTEQUAL, 0, 0xffffffff);
gl.glStencilOp(GL.GL_KEEP, GL.GL_KEEP, GL.GL_KEEP);
gl.glPushMatrix();
gl.glLoadIdentity();
gl.glBegin(GL.GL_TRIANGLE_STRIP);
gl.glVertex3f(-1f, 1f, -0.20f);
gl.glVertex3f(-1f, -1f, -0.20f);
gl.glVertex3f(1f, 1f, -0.20f);
gl.glVertex3f(1f, -1f, -0.20f);
gl.glEnd();
gl.glPopMatrix();
gl.glDisable(GL.GL_BLEND);
gl.glDepthFunc(GL.GL_LEQUAL);
gl.glDepthMask(true);
gl.glEnable(GL.GL_LIGHTING);
gl.glDisable(GL.GL_STENCIL_TEST);
gl.glShadeModel(GL.GL_SMOOTH);
}
Cheers
Vlad