Opengl es 2.0 shadows flickering when shadow camera moves

675 Views Asked by At

I know this is a well known issue but I cant find a solution that works for me. I have nice shadows in my app. I am using an ortho projection matrix to render the shadow map. To keep the shadow detail high I am moving the shadow camera as the players position moves within the game. The shadows flicker. I think I need to lock the shadow camera to the nearest texel but I do not know how (I know I need to adjust the shadow matrix but don't know how). All the examples I can find are for directX and I cant translate that to opengl es 2.0. Any clues folks? Thanks for your time.

1

There are 1 best solutions below

2
solidpixel On

Assuming your flickering is along the edges of the shadow, then that's due to floating point precision, so you need to add a small bias to force the decision out of the error margin.

Enable GL_POLYGON_OFFSET_FILL and use glPolygonOffset to set up a bias.