【问题标题】:Why does SceneKit spotlight angle affect shadow?为什么 SceneKit 聚光灯角度会影响阴影?
【发布时间】:2019-08-09 14:27:43
【问题描述】:

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

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

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

    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】:

    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 Light 和非常低的 Intensity 来照亮 3D 模型上的黑暗区域

    希望这会有所帮助。

    【讨论】:

      【解决方案2】:

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

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

      增加内角会增加全强度照明的区域,从而为场景添加更多光线。在你的例子中,这个额外的光从那个角度减少了可见的阴影。

      【讨论】:

        猜你喜欢
        • 2019-01-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-12-09
        • 1970-01-01
        • 2017-08-29
        • 2015-08-31
        • 2016-10-19
        相关资源
        最近更新 更多