在墙壁上的SceneKit阴影

我在SceneKit应用程序中有一个立方体,一个墙和两个lightNodes,我想让立方体在墙上投下阴影。

我的lightNodes在这里:

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) 

这是我的墙:

  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) 

正如您所看到的,所有节点(包括多维数据集)都具有投射阴影的属性,因为它是true

如何在墙上没有阴影?

和这里一样的问题? 您必须在castsShadow上设置castsShadow (而不是在持有灯光的节点上)。

另请注意,全向和环境光源无法投射阴影。 只有定向和聚光灯才可以。

我不确定为什么会出现这种情况,但我遇到了类似的问题,发现将lightshadowModeSCNShadowModeDeferred修复它。