How to Reduce the Opacity of the Shadows in Realitykit

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

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

Sample Image

Unhide Image

Sample Image

Object Difference with hidden and scaled actions

Sample Image

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 – How to edit or add a Lighting?

At the moment you can't do it in Reality Composer, you need to use a RealityKit. So, you need to create a custom class that inherits from Entity class and conforms to HasPointLight protocol. Run this code in macOS project to find out how a PointLight setup works:

import AppKit
import RealityKit

class Lighting: Entity, HasPointLight {

required init() {
super.init()

self.light = PointLightComponent(color: .red,
intensity: 100000,
attenuationRadius: 20)
}
}

class GameViewController: NSViewController {

@IBOutlet var arView: ARView!

override func awakeFromNib() {

arView.environment.background = .color(.black)

let pointLight = Lighting().light
let boxAnchor = try! Experience.loadBox()

boxAnchor.components.set(pointLight)
arView.scene.anchors.append(boxAnchor)

boxAnchor.steelBox!.scale = [9,9,9]
boxAnchor.steelBox!.position.z = -0.5
}
}

Sample Image

The same way you can add a Directional Light to the scene. But remember: a position of Directional Light does not important, but an orientation does! By default it's oriented to north (-Z).

class Lighting: Entity, HasDirectionalLight {

required init() {
super.init()

self.light = DirectionalLightComponent(color: .red,
intensity: 100000,
isRealWorldProxy: true)
}
}

Sample Image

Also can read my STORY about lights on Medium.

How can I get an entity to constantly look at the camera in RealityKit similar to Billboard Constraint from SceneKit

I was able to figure out an answer to my question. Adding the following block of code allowed the entity to constantly look at the camera:

func session(_ session: ARSession, didUpdate frame: ARFrame) {
planeModelEntity.look(at: arView.cameraTransform.translation, from: planeModelEntity.position(relativeTo: nil), relativeTo: nil)
}


Related Topics



Leave a reply



Submit