I have a SCNScene rendering in a SCNView. I have some *.dae models that are rendered/moving in the scene.
I have a transparent cube, when one of my models goes behin
Here's a solution
true
and colorBufferWriteMask set to []
(empty option set). That way the cube will write in the depth buffer, but won't draw anything on screen.-1
so that it's drawn before any other node in the scene. This will make the cube write in the depth buffer before any other object, preventing them from being drawn if they are behind the cube.Based on @mnuages answer, you can use this class :
import SceneKit
class OccludingNode : SCNNode {
convenience init(geometry: SCNGeometry) {
geometry.materials = [OccludingMaterial()]
self.init()
self.geometry = geometry
self.renderingOrder = -1
}
}
class OccludingMaterial : SCNMaterial {
override init() {
super.init()
isDoubleSided = true
lightingModel = .constant
writesToDepthBuffer = true
colorBufferWriteMask = []
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
Create an OccludingNode
from any geometry you want and anything behind it won't be rendered.