【发布时间】: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。移动聚光灯的位置可能意味着您超出了这个距离,因此最终没有阴影。拥有全向光、环境光和聚光灯对于场景来说可能有点多。对于“暗影”,我会尝试使用灰色的环境光,只使用聚光灯(无全向光)。