I’m engaged on an ARKit mission the place I take advantage of ARView (or ARSCNView) to put nodes in the actual world. I need to apply a black and white filter to the digital camera feed background whereas protecting my 3D node objects coloured. I heard this may be completed utilizing Steel shaders or customized rendering, however I’m uncertain methods to implement this.
May somebody information me on methods to obtain this impact or share a working demo or code snippet?
I’m utilizing Swift for improvement. Any assist can be appreciated.
Right here’s a primary setup of my ARSCNView with node placement:
import UIKit
import ARKit
class ViewController: UIViewController, ARSCNViewDelegate {
@IBOutlet var sceneView: ARSCNView!
override func viewDidLoad() {
tremendous.viewDidLoad()
let configuration = ARWorldTrackingConfiguration()
sceneView.session.run(configuration)
sceneView.delegate = self
let tapGesture = UITapGestureRecognizer(goal: self, motion: #selector(handleTap(_:)))
sceneView.addGestureRecognizer(tapGesture)
}
@objc func handleTap(_ gesture: UITapGestureRecognizer) {
let location = gesture.location(in: sceneView)
let hitResults = sceneView.hitTest(location, varieties: .featurePoint)
if let hitResult = hitResults.first {
let sphere = SCNSphere(radius: 0.05)
sphere.firstMaterial?.diffuse.contents = UIColor.blue
let node = SCNNode(geometry: sphere)
node.place = SCNVector3(hitResult.worldTransform.columns.3.x,
hitResult.worldTransform.columns.3.y,
hitResult.worldTransform.columns.3.z)
sceneView.scene.rootNode.addChildNode(node)
}
}
}
What I’ve Tried
I seemed into customized fragment shaders with Steel, however I’m unsure methods to apply it solely to the digital camera feed whereas protecting the nodes unaffected. Most examples have an effect on the whole view.