ARKit – Rendering a 3D object under an invisible plane

孤人 提交于 2019-12-11 06:55:18

问题


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:


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)


来源:https://stackoverflow.com/questions/52135402/arkit-rendering-a-3d-object-under-an-invisible-plane

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!