I'm trying to add lighting in my RealityKit AR Scene. And I can't find the Lighting option in Reality Composer. If there's a way to add Directional Light
or edit it then please tell me. I've tried Apple Documentation but can't understand how to add them.
Asked
Active
Viewed 3,319 times
3

Andy Jazz
- 49,178
- 17
- 136
- 220

Saad Tahir
- 325
- 2
- 13
-
Can you add your image in stackoverflow rather than using an external service. If your image gets removed, the question will not make sense for future people having a similar issue. – Constantin Chirila Jan 15 '20 at 08:04
-
Ok I'll give it a try – Saad Tahir Jan 15 '20 at 08:27
-
It won't allow me to add image. – Saad Tahir Jan 15 '20 at 08:30
-
since I don't have enough points. It says 10 points to add image in post – Saad Tahir Jan 15 '20 at 08:32
1 Answers
7
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
}
}
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)
}
}
Also can read my STORY about lights on Medium.

Andy Jazz
- 49,178
- 17
- 136
- 220
-
1
-
1Thanks man. The lighting works. But the shadows are still too dark. Actually I want the shadows to be dimmed. Is there a way for that? – Saad Tahir Jan 17 '20 at 07:00
-
1Saad, please, publish another question (and give me a link here). I'll try to answer it. – Andy Jazz Jan 17 '20 at 07:13
-
1I asked the question here: https://stackoverflow.com/questions/59782819/how-can-i-reduce-the-intensity-of-the-shadows-of-these-models-in-reality-kit – Saad Tahir Jan 17 '20 at 07:23