【问题标题】:Cast shadow on all nodes SCNLight在所有节点上投射阴影 SCNLight
【发布时间】:2016-02-01 21:02:56
【问题描述】:

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

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

【问题讨论】:

  • 值得注意的是zFar的默认值,会产生阴影的光和物体之间的最大距离是1.0。移动聚光灯的位置可能意味着您超出了这个距离,因此最终没有阴影。拥有全向光、环境光和聚光灯对于场景来说可能有点多。对于“暗影”,我会尝试使用灰色的环境光,只使用聚光灯(无全向光)。

标签: ios scenekit


【解决方案1】:

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

根据SCNLight.castsShadow: 的文档

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

不过,@mnuages 在SceneKit shadows on wall 中指出,定向光可以投射阴影。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-20
    • 2015-11-30
    • 2016-06-21
    • 1970-01-01
    相关资源
    最近更新 更多