【问题标题】:How can I reduce the opacity of the shadows in RealityKit?如何降低 RealityKit 中阴影的不透明度?
【发布时间】:2020-05-04 01:46:25
【问题描述】:

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

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

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

【问题讨论】:

  • 这只是将物体从光源移开或相反的问题,对吧?

标签: swift augmented-reality arkit realitykit reality-composer


【解决方案1】:

当我在“场景开始”上使用“隐藏”动作序列并发布通知以在点击手势上调用“显示”动作序列时,阴影看起来更暗。 当我将对象缩放到 0% 并发布通知以在点击手势上调用“移动、旋转、缩放到”动作序列时,阴影已修复。

缩放图像

取消隐藏图片

对象差异与隐藏和缩放动作

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
        }

    }
}

【讨论】:

  • 您对 SpotLight 和 Lighting 类有什么看法?您没有在代码中使用它们
  • 我使用了不同的通知而不是使用灯光
【解决方案2】:

如果您需要在场景中使用柔和和半透明的阴影,请使用SpotLight 照明设备,当您使用SpotLight 类或实现HasSpotLight 协议时可用。默认情况下,SpotLight 是北向的。目前,RealityKit 中没有用于阴影的 opacity 实例属性。

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

在房间中,将 SpotLight 灯具保持在距离模型 2...4 米的高度。

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

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


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

【讨论】:

  • 我添加了这个,但阴影似乎没有改变:(
  • 模型和灯具之间的距离是多少?
  • 我没有改变任何照明距离。我刚刚在我的 ARView 中添加了模型。我没有使用深色背景。
  • 这个模型的格式是什么:rcproject or usdz?
  • 这个模型是谁做的,你还是不是?
猜你喜欢
  • 1970-01-01
  • 2023-02-07
  • 1970-01-01
  • 2014-05-31
  • 1970-01-01
  • 2018-02-13
  • 2012-07-17
  • 2018-01-31
  • 1970-01-01
相关资源
最近更新 更多