Shadows z-fighting, glPolygonOffset

I’m having a z-fighting issue with shadows when the shadow become parallel to a polygon. This is with softShadows disabled. However I would like to have softShadows enabled but here z-fighting is a constant issue.

Without softShadows:

I’ve read that glPolygonOffset would be a good solution, but can’t find how to enable this. Any advice or other solutions to avoid z-fighting when in softShadows mode?

With softShadows:

Welcome to the Cesium community @jonas.rodningen!

I believe CesiumJS already applies this glPolygonOffset fix when the browser supports it (according to the PR here I don’t know that there’s an easy fix the application can do to improve these artifacts on shadows other than increase the size of the shadow map perhaps.

@sean_lilley is this something that would require a different approach to shadows in the engine, or something we should have a GitHub issue for? This also came up again here: How to use glPolygonOffset inside fragmentShader to reduce z-fighting

Hi @jonas.rodningen

To check if polygon offset is supported you can add console.log(viewer.scene.shadowMap._polygonOffsetSupported); or step into the code here:

We also apply normal offset bias, which helps, but there are still shadow artifacts. It looks like your model does have normals and can use this technique. You can try tweaking some of the values here and see if it helps:

What device are you running on? Some mobile devices have less depth buffer precision. We’ve seen issues like and

@sean_lilley I’m running on windows laptop, with Chrome. I tried tweaking all the parameters in _primitiveBias, without any difference unfortunately.

I’m currently using 4096 shadow size (on the screenshots), and the app crashes with values like 6000