为什么SceneKit的聚光灯角度会影响阴影?

时间:2019-03-19 06:06:30

标签: swift scenekit augmented-reality arkit shadow

我正在尝试在场景中使用聚光灯并向对象添加阴影。但是,我注意到当我增加spotInnerAngle时,对象的阴影会显着改变。这是一个示例:

enter image description here

这些图像中的两个阴影看起来都大不相同-有人知道为什么增加光斑角度会导致阴影不那么明显吗?

这是我用来创建聚光灯/向场景添加阴影的代码:

    let spotLight = SCNNode()
    spotLight.light = SCNLight()
    spotLight.light?.type = SCNLight.LightType.spot
    spotLight.light?.spotInnerAngle = 120
    spotLight.light?.spotOuterAngle = 120
    spotLight.light?.color = UIColor.white
    spotLight.light?.castsShadow = true
    spotLight.light?.automaticallyAdjustsShadowProjection = true
    spotLight.light?.shadowSampleCount = 32
    spotLight.light?.shadowRadius = 8
    spotLight.light?.shadowMode = .deferred
    spotLight.light?.shadowMapSize = CGSize(width: 2048, height: 2048)
    spotLight.light?.shadowColor = UIColor.black.withAlphaComponent(1)
    spotLight.position = SCNVector3(x: 0,y: 5,z: 0)
    spotLight.eulerAngles = SCNVector3(-Float.pi / 2, 0, 0)

2 个答案:

答案 0 :(得分:0)

SceneKit的引擎计算阴影的方式与3D软件应用程序(例如Maya或3dsMax)略有不同。在SceneKit框架中,Spotlight的positionscale及其值cone angle对于生成阴影至关重要。主要规则如下:当SceneKit中的聚光灯的光线区域变大时,阴影边缘将变得更加模糊(又称为模糊)。

以下是使用聚光灯时必须考虑的属性:

let lightNode = SCNNode()
lightNode.light = SCNLight()
lightNode.light!.type = .spot
lightNode.rotation = SCNVector4(x: 0, y: 0, z: 0, w: 1)
lightNode.castsShadow = true

/* THESE SEVEN SPOTLIGHT PROPERTIES AFFECT SHADOW'S APPEARANCE */
lightNode.position = SCNVector3(0, 10, 0)
lightNode.scale = SCNVector3(7, 7, 7)
lightNode.light?.spotOuterAngle = 120
lightNode.light?.shadowRadius = 10
lightNode.light?.zNear = 0
lightNode.light?.zFar = 1000000
lightNode.light?.shadowSampleCount = 20

lightNode.light?.shadowColor = UIColor(write: 0, alpha: 0.75)
lightNode.light?.shadowMode = .deferred
scene.rootNode.addChildNode(lightNode)

此外,我建议您使用Ambient LightIntensity非常低的亮度来照亮3D模型上的暗区

希望这会有所帮助。

答案 1 :(得分:0)

摘自Apple文档: “ [spotInnerAngle]确定完全照明区域的宽度。”

此属性的默认值为0,这意味着只有聚光灯照亮的区域的中心才以全强度照亮。

增加内角会增加全强度照明的区域,从而为场景增加更多的光线。在您的情况下,这些额外的光正在从该角度减小可见阴影。