Occlusion Material or Hold-Out Shader in ARKit and SceneKit

拜拜、爱过 提交于 2021-02-06 12:30:41

问题


I have seen some examples demo of ARKit where material A is blocking material B, kind of creating occlusion effect, or black hole, or masking. But all of them seems to be using Unity engine (I might be wrong). I wanted to do this using what Apple provide already. Or maybe using Metal Shader.

Wondering if anyone knows a trick that allows this for ARKit or even in SceneKit term, when 2 objects are overlapping, but wanting one object to occlude the other object, leaving the other object empty. It cannot be CSG right, because that would be too expensive?


回答1:


Yes, it's definitely possible to use a 3D object as a hold-out mask, a.k.a. Occlusion Material in iOS and macOS apps. An instance property, called .colorBufferWriteMask, actually writes depth channel information when rendering the material. So you need the following value for this property for masking object:

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

...and don't forget to assign an appropriate rendering order (closest to the camera):

sphere.renderingOrder = -50  

..and give two values that determine whether SceneKit produces depth information when rendering the material or not:

sphere.geometry?.firstMaterial?.writesToDepthBuffer = true
sphere.geometry?.firstMaterial?.readsFromDepthBuffer = true



来源:https://stackoverflow.com/questions/45772265/occlusion-material-or-hold-out-shader-in-arkit-and-scenekit

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