在 scenekit 中的透明 floor/plane 上显示阴影

Showing a shadow on a transparent floor/plane in scenekit

试图弄清楚如何在不可见的平面上渲染阴影,所以我的 sceneView 的背景显示出来。

THREE.js 有一个 ShadowMaterial 正是这样做的 - 只渲染阴影。

目前的想法是制作一个看起来很简单的自定义金属着色器,但我不确定如何敲掉地板以显示阴影以外的所有内容。

这里有一个影子捕手的例子:https://knowledge.autodesk.com/search-result/caas/sfdcarticles/sfdcarticles/Maya-2015-Shadow-Catching-with-Use-Background-material.html

好的,请查看 Github 上的示例项目:

https://github.com/carolight/Metal-Shadow-Map/blob/master/Shadows/Shader.metal#L67

link 是执行阴影贴图测试的着色器。基本上,它标准化正在渲染的片段的 Z 位置,并将其与阴影贴图的 Z 缓冲区进行比较。如果它小于阴影 Z,则像素完全点亮(第 67 行),否则它会稍微着色(第 69 行)。

您要做的是为第 69 行写入 (0,0,0, shadow_opacity) 并为第 67 行写入 (0,0,0,0)。这应该会发出透明像素。将 shadow_opacity 设置为 [0.0..1.0] 的制服。

设置的其余部分显示在 example. Tilt the plane/camera to the desired setting, skip drawing the cube/vase/whatever in the main pass if you don't really want it in the scene (line 279) 中。 (但是,请注意 shadow pass 并将其保留在那里)。