如何降低 RealityKit 中阴影的不透明度?

How can I reduce the opacity of the shadows in RealityKit?

我在 Reality Composer 中合成了一个场景,并在其中添加了 3 个对象。问题是阴影太强烈(暗)。

我尝试使用来自 答案的 RealityKit 中的定向光,而不是来自 Reality Composer 的默认光(因为您没有在其中调整光的选项)。

更新 正如@AndyFedo 在答案中所解释的那样,我实现了聚光灯照明。影子还是那么黑

In case you need soft and semi-transparent shadows in your scene, use SpotLight lighting fixture which is available when you use a SpotLight class or implement HasSpotLight protocol. By default SpotLight is north-oriented. At the moment there's no opacity instance property for shadows in RealityKit.

outerAngleInDegrees实例属性不得超过179 degrees.

import RealityKit

class Lighting: Entity, HasSpotLight {
    
    required init() {
        super.init()
        
        self.light = SpotLightComponent(color: .yellow,
                                    intensity: 50000,
                          innerAngleInDegrees: 90,
                          outerAngleInDegrees: 179,  // greater angle – softer shadows
                            attenuationRadius: 10)   // can't be Zero
    }
}

然后创建shadow个实例:

class ViewController: NSViewController {
    
    @IBOutlet var arView: ARView!
    
    override func awakeFromNib() { 
        arView.environment.background = .color(.black)
        
        let spotLight = Lighting().light
        let shadow = Lighting().shadow
        let boxAndCurlAnchor = try! Experience.loadBoxAndCurl()
                
        boxAndCurlAnchor.components.set(shadow!)
        boxAndCurlAnchor.components.set(spotLight)

        arView.scene.anchors.append(boxAndCurlAnchor)
    }
}

这是一张没有这条线的图像:boxAnchor.components.set(shadow!)

这是使用以下值生成的图像 outerAngleInDegrees = 140:

这是使用以下值 outerAngleInDegrees = 179 生成的图像:

In a room keep SpotLight fixture at a height of 2...4 meters from a model.

对于更大的对象,您必须为 intensityattenuationRadius 使用更高的值:

self.light = SpotLightComponent(color: .white,
                            intensity: 625000,
                  innerAngleInDegrees: 10,
                  outerAngleInDegrees: 120,
                    attenuationRadius: 10000)


您也可以阅读我的 STORY 关于 Medium 上的 RealityKit 灯。

当我在 "Scene Start" 上使用 "Hide" 动作序列并且 post 通知在点击手势时调用 "Show" 动作序列时,阴影看起来更暗。 当我将对象缩放到 0% 并且 post 通知调用 "Move,Rotate,Scale to" 点击手势的动作序列时,阴影被修复了。

缩放图像

取消隐藏图像

隐藏和缩放操作的对象差异

import UIKit

import RealityKit

import ARKit


class Lighting: Entity, HasDirectionalLight {
    required init() {
        super.init()
        self.light = DirectionalLightComponent(color: .red, intensity: 1000, isRealWorldProxy: true)
    }
}

class SpotLight: Entity, HasSpotLight {

    required init() {
        super.init()
        self.light = SpotLightComponent(color: .yellow,
                                        intensity: 50000,
                                        innerAngleInDegrees: 90,
                                        outerAngleInDegrees: 179, // greater angle – softer shadows
            attenuationRadius: 10) // can't be Zero

    }
}

class ViewController: UIViewController {

    @IBOutlet var arView: ARView!

    enum TapObjects {
        case None
        case HiddenChair
        case ScaledChair
    }    
    var furnitureAnchor : Furniture._Furniture!
    var tapObjects : TapObjects = .None

    override func viewDidLoad() {
        super.viewDidLoad()

        furnitureAnchor = try! Furniture.load_Furniture()
        arView.scene.anchors.append(furnitureAnchor)

        addTapGesture()

    }

    func addTapGesture() {
        let tapGesture = UITapGestureRecognizer(target: self, action: #selector(onTap))
        arView.addGestureRecognizer(tapGesture)
    }

    @objc func onTap(_ sender: UITapGestureRecognizer) {

        switch tapObjects {
        case .None:
            furnitureAnchor.notifications.unhideChair.post()
            tapObjects = .HiddenChair
        case .HiddenChair:
            furnitureAnchor.notifications.scaleChair.post()
            tapObjects = .ScaledChair
        default:
            break
        }

    }
}