1
votes

I have an ARKit scene with an invisible SCNPlane:

plane.geometry?.firstMaterial?.colorBufferWriteMask = []

This plane is placed on the ground and is used to render deferred shadows from other objects placed in the scene.

I want to render another SCNPlane which should be on the same level as the invisible plane (same Z-coordinate). The problem is, that every time the new object is under the invisible plane, it is not rendered at all.

Is there any way to render the object when it is under the invisible plane?

1

1 Answers

1
votes

You can achieve it using the following lines of code:

shadowsPlane.geometry?.materials.first?.writesToDepthBuffer = true
shadowsPlane.geometry?.materials.first?.readsFromDepthBuffer = true

Choose one of two instance properties for .colorBufferWriteMask:

shadowsPlane.geometry?.materials.first?.colorBufferWriteMask = []

Set a rendering order for your objects like:

shadowsPlane.renderingOrder = -1   // the nearest layer

And, of course, use an appropriate .lightingModel instance property:

shadowsPlane.geometry?.materials.first?.lightingModel = .constant 

Remember, there will be some tiny air gap between two planes:

shadowsPlane.position = SCNVector3(x: 0, y: 0, z: 0)
floorPlane.position = SCNVector3(x: 0, y: -0.01, z: 0)