Augmented Reality – Lighting Real-World objects with Virtual light
At the low level, RealityKit is only responsible for rendering virtual objects and overlaying them on top of the camera frame.
If you want to illuminate the real scene, you need to post-process the camera frame.
Here are some tutorials on how to do post-processing:
Tutorial1⃣️
Tutorial2⃣️
If all you need is an effect like This , then all you need to do is add a CGImage-based post-processing effect for the virtual object (lights).
More specifically, add a bloom filter to the rendered image(You can also simulate bloom filters with Gaussian blur).
In this way, the code is all around UIImage and CGImage, so it's pretty simple/p>
If you want to be more realistic, consider using the depth map provided by LiDAR to calculate which areas can be illuminated for a more detailed brightness.
Or If you're a true explorer, you can use Metal to create a real world Digital Twin point cloud in real time to simulate occlusion of light.
I have added a Human 3d Model in Scene Kit , its background is black how to make it as white as front view?
- Remove all the camera control code
- See How to rotate object in a scene with pan gesture - SceneKit for rotating an object
- Put in a light node at a negative z facing the object
Orienting a directional light and adding to scene in ARKit
Use the following code to control orientation of directional light:
Take into consideration that position of Directional Light is not important!
import ARKit
import RealityKit
class Lighting: Entity, HasDirectionalLight, HasAnchoring {
required init() {
super.init()
self.light = DirectionalLightComponent(color: .green,
intensity: 1000,
isRealWorldProxy: true)
}
}
class ViewController: UIViewController {
@IBOutlet var arView: ARView!
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
let light = Lighting()
light.orientation = simd_quatf(angle: .pi/8,
axis: [0, 1, 0])
let boxAnchor = try! Experience.loadBox()
let directLightAnchor = AnchorEntity()
directLightAnchor.addChild(light)
boxAnchor.addChild(directLightAnchor)
boxAnchor.steelBox!.scale = [30,30,30]
boxAnchor.steelBox!.position.z = -3
arView.scene.anchors.append(boxAnchor)
}
}
If you want to know how implement directional light's orientation in SceneKit, read this post.
Is there a way to make a dark/low light SceneKit scene?
Had to try this for myself, as it didn't sound right. Removing all lights from the default SceneKit game template does indeed result in a model lit with an ambient light. I expect it's some kind of default that kicks into action when SceneKit identifies you have no lights in your scene.
Adding a black ambient light doesn't seem to change this, however adding a single dark non-ambient (omni, directional, spot) does result in a dark scene. The following image is with a dark gray omni light, and no ambient light.
I don't think this matters too much in real use, you'd be unlikely to have a scene with no non-ambient lights. Certainly understand the confusion in this instance however.
Related Topics
How to Perform Face Detection in Swift
Textfield Delegate Shouldchangecharactersinrange
Why Can't I Use .Reduce() in a One-Liner Swift Closure with a Variadic, Anonymous Argument
Expression Resolves to an Unused Function
Swift: How to Flush Stdout After Println
Unresponsive Uibutton in Subview Added to Uistackview
How to Get Notification Authorization Status in Swift 3
What Is Darwinboolean Type in Swift
Mfmailcomposeviewcontroller Error [Mc] Filtering Mail Sheet Accounts for Bundle Id
Background Upload with Share Extension
Any or a Trouble with Sequence of Functions
Gmail API: How to Send Attachments to The Drafts on Swift
Calling Stop() on Avaudioplayernode After Finished Playing Causes Crash