Group Group Group Group Group Group Group Group Group

How can I create SKLightNode from top that cast on the ground?

Hi,
I’m working on a 2D game with spriteKit and I’d like to create a sunlight from zPosition 10 that would cast zPosition 3 Nodes on the ground zPosition 0.
Can’t manage to achieve that like my image example (from photoshop).

Any help or explanation would be appreciated or any suggested tutorial.

Use directional light for Sun simulation (Sun has parallel rays that for us are primary rays from very distant light source) and use ambient light for simulating fake secondary rays (in case you do not use Global Illumination).

// DIRECTIONAL LIGHT for primary light rays simulation
let lightNode = SCNNode()
lightNode.light = SCNLight()
lightNode.light!.type = .directional
lightNode.light!.castsShadow = true
lightNode.light!.shadowMode = .deferred
lightNode.light!.categoryBitMask = -1
lightNode.light!.automaticallyAdjustsShadowProjection = true
//lightNode.light!.maximumShadowDistance = 11000
lightNode.position = SCNVector3(x: 0, y: -5000, z: 0)
lightNode.rotation = SCNVector4(x: -1, y: 0, z: 0, w: .pi/2)
scene.rootNode.addChildNode(lightNode)
Tip: The position of directional light could be any (in the following code it is even under the plane y:-5000), the most important thing is direction of directional light!

Also directional light has no falloff parameter or, so called, quadratic light decay.

// AMBIENT LIGHT for fake secondary light rays simulation
let ambientLightNode = SCNNode()
ambientLightNode.light = SCNLight()
ambientLightNode.light!.type = .ambient
ambientLightNode.light!.intensity = 1000
ambientLightNode.light!.color = NSColor.white
scene.rootNode.addChildNode(ambientLightNode)
Do not mistakenly use this Boolean value:

lightNode.castsShadow = true
instead of this one:

lightNode.light!.castsShadow = true
The Boolean value lightNode.castsShadow determines whether SceneKit renders the node’s contents into shadow maps.

Thanks a lot for your answer.
I’m going to try it.

I wish I could find some detailed tutorial on all the light possibilities.