I’m engaged on an ARKit challenge 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 digicam feed background whereas maintaining my 3D node objects coloured. I heard this may be performed utilizing Metallic shaders or customized rendering, however I’m uncertain learn how to implement this.
Might somebody information me on learn how 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 regarded into customized fragment shaders with Metallic, however I’m undecided learn how to apply it solely to the digicam feed whereas maintaining the nodes unaffected. Most examples have an effect on the whole view.