【问题标题】:SceneKit shadows on wall墙上的 SceneKit 阴影
【发布时间】:2015-07-01 20:48:14
【问题描述】:

我的 SceneKit 应用程序中有一个立方体、一面墙和两个 lightNode,我想让立方体在墙上投射阴影。

我的 lightNode 在这里:

    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

墙上怎么没有影子?

【问题讨论】:

    标签: ios swift shadow scenekit lighting


    【解决方案1】:

    here 相同的问题?您必须在灯光上设置castsShadow(而不是在持有灯光的节点上)。

    另请注意,全向光和环境光不能投射阴影。只有定向灯和聚光灯可以。

    【讨论】:

    • 嗯,把Omni-LightNode 变成了Spot 一个,但它仍然没有投射任何阴影......:/
    • 如果你让它成为一个点,确保它指向墙壁。例如let lightConstraint = SCNLookAtConstraint(target: wall); lightNode.constraints = [lightConstraint]
    • 是否有特殊情况需要用定向光触发阴影?我们似乎只能用聚光灯生成阴影。
    【解决方案2】:

    我不确定为什么会这样,但我遇到了类似的问题,发现将lightshadowMode 设置为SCNShadowModeDeferred 解决了这个问题。

    【讨论】:

      猜你喜欢
      • 2016-06-11
      • 2019-03-10
      • 2017-11-17
      • 2021-02-19
      • 2016-02-07
      • 2020-05-06
      • 2016-09-16
      • 2015-06-29
      相关资源
      最近更新 更多