SceneKit: zFar or Far Clipping value influences directional lights and their shadows?

589 views Asked by At

Would love help understanding directional lights and scene shadows in Scene Kit.

The class reference on SCNLight says zFar represents the maximum distance between the light and a visible surface for casting shadows. It further suggests this value only applies to spot lights.

However, in the Xcode Scene Editor, under the Attributes Inspector, there is a field for Far Clipping. Changing this value affects shadows projected by a directional light as illustrated by the screenshots below.

The scenes below were produced by dragging a directional light into the scene and changing the X Euler Angle value to -60 and ticking the "Casts Shadows" box. The floor texture is taken from the WWDC Fox demo,

  • Is Far Clipping the same as zFar? If not, what's the difference?

  • Since directional lights ignore the position property, why does changing the Far Clipping value affect the shadows produced by a directional light?

  • The goal is to light the whole scene, and project shadows on nodes, as if the sun was at 3 PM in the afternoon on a cloudless day. Is it possible to use a directional light to achieve this? So far, using directional lights can achieve the look where the whole scene is lit, but cannot control shadows as well as a spotlight.

Screenshot #1: Far Clipping value is 10.

enter image description here

Screenshot #2: Far Clipping value is 30.

enter image description here

1

There are 1 answers

1
Curyous On

Despite what Apple's documentation says, the position of a directional light is very important when it casts shadows. zNear and zFar are distances from the directional light position.

To remove the artifact you are seeing, you will need to increase zFar or move the directional light closer to the ground. The artifact you are seeing is caused by the shadowed part being further away from the directional light than zFar.