在所有节点 SCNLight 上投射阴影

Cast shadow on all nodes SCNLight

我正在尝试从场景的左侧投射一个短的暗影。我的灯光设置如下:

func setupLights() {

    // Create shadow
    let spotLight = SCNLight()
    spotLight.type = SCNLightTypeSpot
    spotLight.spotInnerAngle = 30.0
    spotLight.spotOuterAngle = 80.0
    spotLight.castsShadow = true
    let spotLightNode = SCNNode()
    spotLightNode.light = spotLight
    spotLightNode.position = SCNVector3(1.5, 1.5, 1.5)
    rootNode.addChildNode(spotLightNode)

    // Create ambient light
    let ambientLight = SCNLight()
    ambientLight.type = SCNLightTypeAmbient
    ambientLight.color = UIColor.whiteColor()
    let ambientLightNode = SCNNode()
    ambientLightNode.name = "AmbientLight"
    ambientLightNode.light = ambientLight
    ambientLightNode.castsShadow = true
    rootNode.addChildNode(ambientLightNode)

    // Create an omni-directional light
    let omniLight = SCNLight()
    omniLight.type = SCNLightTypeOmni
    omniLight.color = UIColor.whiteColor()
    let omniLightNode = SCNNode()
    omniLightNode.name = "OmniLight"
    omniLightNode.light = omniLight
    omniLightNode.position = SCNVector3(x: -10.0, y: 20, z: 10.0)
    omniLightNode.castsShadow = true
    rootNode.addChildNode(omniLightNode)
}

使用这段代码,我得到了一个明亮的场景,其中有一些非常亮且长的阴影不是来自左侧。我试图改变当前 SCNVector3(1.5, 1.5, 1.5) 的位置,但是无论我放在哪个其他位置,阴影都会消失。有什么想法吗?

如果您想在场景的所有部分使用定向光,请使用 SCNLightTypeSpot 作为灯光的 type。或者 SCNLightTypeDirectional

根据 SCNLight.castsShadow:

的文档

Geometries illuminated by the light cast shadows only if the value of this property is YES and the type property of the light is SCNLightTypeSpot. The default value is NO.

然而,@mnuages 在 SceneKit shadows on wall 中声明定向光可以投射阴影。