SceneKit Culling Plane

前端 未结 2 803
野性不改
野性不改 2020-12-17 01:48

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

相关标签:
2条回答
  • 2020-12-17 02:07

    Here's a solution

    1. For the cube, use a material with constant as its lightingModel. It's the cheapest one.
    2. This material will have writesToDepthBuffer set to 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.
    3. Set the cube's renderingOrder to -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.
    0 讨论(0)
  • 2020-12-17 02:28

    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.

    0 讨论(0)
提交回复
热议问题