SceneKit: adding directional light to camera node does not affect

Based on the advice in this answer , the goal is to add ambient light to the scene along with the directional light on the camera.

This works in the Xcode script editor with directional light set to 70% white and ambient light set to 50% white. Euler angles for directional light use the default values.

Encoding of this scheme is not performed. As if directional light is not added. There is no effect on the scene; it is as if only the surrounding light exists.

Different values ​​for the component x the Euler angles do not matter - PI / 2, PI and other values ​​were tested, but still did not change.

Adding directional light to the root of the scene node ( scene.rootNode.addChildNode(directionalLightNode) ), however, does add 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) } 
+5
source share
1 answer

Create an SCNNode, for example, named cameraNode. Create an SCNCamera and assign it to the cameraNode property. Add a CameraNode to the scene (as a child of the rootNode).

After that, you can add the light node as a child node for the CameraNode or, given its only camera, as a child of the pointOfView node (which now represents the CameraNode you created and is added to the scene). The default camera and its pointOfView node are not part of the scene object hierarchy.

+3
source

Source: https://habr.com/ru/post/1275489/


All Articles