在所有节点SCNLight上投射阴影

时间:2016-02-01 21:02:56

标签: ios scenekit

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

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)的位置,但无论我放置哪个位置,阴影就会消失。有什么想法吗?

1 个答案:

答案 0 :(得分:4)

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

SCNLight.castsShadow:

的每个文档
  

仅当此属性的值为YES且灯光的type属性为SCNLightTypeSpot时,由投光阴影照亮的几何图形。默认值为NO。

但是,@ SceneKit shadows on wall中的@mnuages指出方向灯可以投射阴影。