如何降低 RealityKit 中阴影的不透明度? [英] How can I reduce the opacity of the shadows in RealityKit?

查看:21
本文介绍了如何降低 RealityKit 中阴影的不透明度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我尝试在 RealityKit 中使用来自

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

解决方案

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

缩放图像

取消隐藏图片

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

导入 UIKit导入 RealityKit导入 ARKit类照明:实体,HasDirectionalLight {必需的 init() {超级初始化()self.light = DirectionalLightComponent(颜色:.red,强度:1000,isRealWorldProxy:true)}}类 SpotLight:实体,HasSpotLight {必需的 init() {超级初始化()self.light = SpotLightComponent(颜色:.黄色,强度:50000,内部角度InDegrees:90,externalAngleInDegrees: 179,//更大的角度——更柔和的阴影衰减半径: 10)//不能为零}}类视图控制器:UIViewController {@IBOutlet var arView:ARView!枚举 TapObjects {案例 无案例隐藏的椅子案例 ScaledChair}var FurnitureAnchor : Furniture._Furniture!var tapObjects : TapObjects = .None覆盖 func viewDidLoad() {super.viewDidLoad()家具锚=尝试!Furniture.load_Furniture()arView.scene.anchors.append(furnitureAnchor)添加TapGesture()}func addTapGesture() {让 tapGesture = UITapGestureRecognizer(target: self, action: #selector(onTap))arView.addGestureRecognizer(tapGesture)}@objc func onTap(_ 发送者:UITapGestureRecognizer) {切换 tapObjects {案例.无:家具Anchor.notifications.unhideChair.post()tapObjects = .HiddenChair案例 .HiddenChair:家具Anchor.notifications.scaleChair.post()tapObjects = .ScaledChair默认:休息}}}

I composed a scene in Reality Composer and added 3 objects in it. The problem is that the shadows are too intense (dark).

I tried using the Directional Light in RealityKit from this answer rather than a default light from Reality Composer (since you don't have an option to adjust light in it).

Update I implemented the spotlight Lighting as explained by @AndyFedo in the answer. The shadow is still so dark.

解决方案

The shadows appear darker when I use "Hide" action sequence on "Scene Start" and post a notification to call "Show" action sequence on tap gesture. The shadows were fixed when I scaled the Object to 0% and post Notification to call "Move,Rotate,Scale to" action sequence on tap gesture.

Scaled Image

Unhide Image

Object Difference with hidden and scaled actions

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
        }

    }
}

这篇关于如何降低 RealityKit 中阴影的不透明度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆