Based on the advice in this answer, the goal is to add an ambient light to a scene along with a directional light to the camera.
This works in the Xcode Scene Editor, with the directional light set at 70% white and the ambient light at 50% white. The Euler angles for the directional light use default values.
Coding this arrangement fails. It's as if the directional light isn't being added. There is no effect on the scene; it's as if only the ambient light exists.
Different values for the x
component of the Euler angles make no difference -- PI/2, PI, and other values were tried but still no change.
Adding the directional light to the scene's root node (scene.rootNode.addChildNode(directionalLightNode)
), however, does indeed add the light to the scene.
fileprivate func addLightNode() {
// Create ambient light
let ambientLightNode = SCNNode()
ambientLightNode.light = SCNLight()
ambientLightNode.light!.type = .ambient
ambientLightNode.light!.color = UIColor(white: 0.70, alpha: 1.0)
// Add ambient light to scene
scene.rootNode.addChildNode(ambientLightNode)
// Create directional light
let directionalLight = SCNNode()
directionalLight.light = SCNLight()
directionalLight.light!.type = .directional
directionalLight.light!.color = UIColor(white: 1.0, alpha: 1.0)
directionalLight.eulerAngles = SCNVector3(x: 0, y: 0, z: 0)
// Add directional light to camera
let cameraNode = sceneView.pointOfView!
cameraNode.addChildNode(directionalLight)
}