SceneKit Directional Light causing flickering

1.2k Views Asked by At

I'm trying to add a directional light in Scenekit to cast shadows, but it is causing weird artefacts on objects.

The orange block below has a material with default settings and the diffuse set to orange. The directional light is pointing downwards, and the scale is increased, otherwise it has default settings. (Making the scale smaller still has the same issue).

When I pan the camera around the texture is covered in flickering lines and dots, it looks terrible.

enter image description here

This isn't visible on the simulator, only the device. What is going on and how can I fix it?

2

There are 2 best solutions below

1
On BEST ANSWER

Thanks to Toyos I now know that self-shadowing is what's causing the lines. The docs for shadowBias say setting this value should correct it, but for me it made no difference.

In the end I fixed it by rotating the directional light by 2 degrees. It was originally at -90, pointing straight down. Changing this to -88 has completely removed all the artefacts.

1
On

Configure the zNear/zFar range of your light to make it as small as possible (but not clipping your world). The smaller the zRange is the more precision you will get.

You can also play with the shadowBias to limit the self shadowing artefacts