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.
Asked
Active
Viewed 573 times
0
-
The vertices that you are drawing, how far away from the origin are they? I know this will be a problem if the model/world matrix transforms the vertices to a far enough distance when calculating the lighting on them will result in single floating point precision inaccuracies, which will cause a sort of flicker. – Zebrafish Feb 28 '18 at 09:10
-
They are far away, yes its float point errors that cause this. Can I lock the shadow camera somehow? – J mott Feb 28 '18 at 09:44
-
In your case I'm not sure if the flickering is of the shadows or the surfaces when the lighting calculation is done. The way I solved it was to transform all position by the inverse world/model matrix, in other words bring stuff back to near the origin, including anything else like light sources, calculate, then send them back to their original position. I can't remember whether I did this in the vertex shader or the fragment shader but I think it should be possible in either. Though, remember, I'm not sure if the problem you're having is this. – Zebrafish Feb 28 '18 at 10:06
-
Thanks, makes sense. – J mott Feb 28 '18 at 10:21
1 Answers
0
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.

solidpixel
- 10,688
- 1
- 20
- 33
-
You have to find a balance between the two - it's the somewhat unavoidable issue with shadows so you just need to find a trade-off which works for you ... – solidpixel Mar 01 '18 at 09:32
-
I have read that you can stop the flicker by locking the shadow matrix to the nearest texel but I cannot get it to work, I am talking about shadow flicker here - not shadow acne. – J mott Mar 05 '18 at 10:14