ARKit – 在不可见平面下渲染 3D 对象 [英] ARKit – Rendering a 3D object under an invisible plane
问题描述
我有一个带有隐形 SCNPlane
的 ARKit 场景:
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.
我想渲染另一个 SCNPlane
,它应该与不可见平面(相同的 Z
坐标)处于同一级别.问题是,每次新对象在不可见平面下时,它根本没有被渲染.
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?
推荐答案
您可以使用以下代码行来实现:
You can achieve it using the following lines of code:
shadowsPlane.geometry?.materials.first?.writesToDepthBuffer = true
shadowsPlane.geometry?.materials.first?.readsFromDepthBuffer = true
为 .colorBufferWriteMask
选择两个实例属性之一:
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
当然,使用适当的 .lightingModel
实例属性:
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)
这篇关于ARKit – 在不可见平面下渲染 3D 对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!