Search code examples
ios3dscenekitscnlight

SceneKit Directional Light causing flickering


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?


Solution

  • 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.