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

问题描述 投票:3回答:1

我正在尝试在场景中使用聚光灯并为对象添加阴影。但是,我注意到当我增加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)
swift scenekit augmented-reality arkit shadow
1个回答
0
投票

SceneKit的引擎计算阴影的程度与3D软件应用程序略有不同,如Maya或3dsMax。在SceneKit框架中,聚光灯的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 Light和非常低的Intensity来照亮3D模型上的暗区。

希望这可以帮助。

© www.soinside.com 2019 - 2024. All rights reserved.