Post

Replies

Boosts

Views

Activity

Scenekit spotlight with Gobo effect
I saw it's possible that you can use a gobo as light effect like in the real world, flag some lights off. Can someone help me to get the gobo effect to work? In the following example you will see a cube with a plane below it and a spotlight above it. I would like to load a pattern (image) in front off the spotlight-source which would flag (block) certain parts of the light. Expected behaviour would be that you will see part of the pattern on the top of the cube as you will see part of the blocked light pattern on the plane. Could anyone help me with solving this gobo puzzle? 	view.backgroundColor = .blue let sceneView = SCNView(frame: self.view.frame)     self.view.addSubview(sceneView)     view.bringSubviewToFront(sceneView)     sceneView.backgroundColor = .clear     sceneView.allowsCameraControl = true     let scene = SCNScene()     sceneView.scene = scene     // Add camera node     let camera = SCNCamera()     let cameraNode = SCNNode()     cameraNode.camera = camera     cameraNode.position = SCNVector3(x: 0, y: 0, z: 0)     scene.rootNode.addChildNode(cameraNode)     // Add a cube to the scene     let cubeGeometry = SCNBox(width: 0.5, height: 0.5, length: 0.5, chamferRadius: 0.0)     let cubeNode = SCNNode(geometry: cubeGeometry)     cubeNode.position = SCNVector3(x: 0.0, y: -0.5, z: -1.5)       // Make the cube white     let whiteMaterial = SCNMaterial()     whiteMaterial.diffuse.contents = UIColor.white     cubeGeometry.materials = [whiteMaterial]     scene.rootNode.addChildNode(cubeNode)     // Add a plane to the scene so we can see the lights & shadows     let planeGeometry = SCNPlane(width: 100.0, height: 100.0)     let lightGrayMaterial = SCNMaterial()     lightGrayMaterial.diffuse.contents = UIColor.lightGray     planeGeometry.materials = [lightGrayMaterial]     let planeNode = SCNNode(geometry: planeGeometry)     planeNode.eulerAngles = SCNVector3(x: GLKMathDegreesToRadians(-90), y: 0, z: 0)     planeNode.position = SCNVector3(x: 0, y: -15, z: 0)     scene.rootNode.addChildNode(planeNode)           // Create a spotlight     let light = SCNLight()     light.type = SCNLight.LightType.spot     light.castsShadow = true     // Create a Gobo mask: //    if let gobo = light.gobo //    { //      gobo.contents = UIImage(named: "gobo") //      gobo.intensity = 0.5 //      //light.categoryBitMask = -1 //    }           // Create al lightNode     let lightNode = SCNNode()     lightNode.light = light     lightNode.position = SCNVector3(x: 0, y: 10, z: -1.5)     let lightAngle = -90 * Float.pi / 180 // light facing down     lightNode.eulerAngles = SCNVector3(x: lightAngle, y: 0, z: 0)     scene.rootNode.addChildNode(lightNode)
1
0
889
Oct ’20