Reputation: 28952
I have a cube, a wall and two lightNodes in my SceneKit application and I would like to make the cube throw a shadow onto the wall.
My lightNodes are here:
let lightNode = SCNNode()
lightNode.light = SCNLight()
lightNode.light!.type = SCNLightTypeSpot
lightNode.position = SCNVector3(x: 0, y: 0, z: 15)
lightNode.castsShadow = true
scene.rootNode.addChildNode(lightNode)
// create and add an ambient light to the scene
let ambientLightNode = SCNNode()
ambientLightNode.light = SCNLight()
ambientLightNode.light!.type = SCNLightTypeAmbient
ambientLightNode.light!.color = UIColor.darkGrayColor()
ambientLightNode.castsShadow = true
scene.rootNode.addChildNode(ambientLightNode)
This is my wall:
var wall = SCNNode(geometry: SCNBox(width: 400, height: 100, length: 4, chamferRadius: 0))
wall.geometry?.firstMaterial!.emission.contents = UIColor.lightGrayColor()
wall.geometry?.firstMaterial!.doubleSided = false
wall.castsShadow = true
wall.position = SCNVector3Make(0, 0, -5)
wall.physicsBody = SCNPhysicsBody.staticBody()
scene.rootNode.addChildNode(wall)
As you can see all of the nodes (including the cube) have the property to cast shadow, since it is true
.
How does it come that there is no shadow on the wall?
Upvotes: 1
Views: 3116
Reputation: 1396
I'm not sure why this is the case, but I was having a similar issue and found that setting the light
's shadowMode
to SCNShadowModeDeferred
fixed it.
Upvotes: 2