是否可以在 ARKit 中将光投射到透明的 SCNFloor 上?

Is it possible to project light on a transparent SCNFloor in ARKit?

我想放一个SCNLight节点并投射光到透明的SCNFloor?这将在真实表面上产生光投射效果。类似于投射阴影的 shadowOnly 光照模型。这可能吗?

是的,您可以通过投射白色(或流血色)阴影而不是黑色阴影来做到这一点。为此,您必须使用在 post 处理过程中呈现的 deferred 阴影类型。

考虑一下,您必须在场景中使用两个单独的灯——第一个用于投射白色阴影,第二个用于照亮投射这些白色阴影的对象。您可以在实现 categoryBitMask 属性.

的照明方案中包含和排除对象
// SETTING A SHADOW CATCHER
let plane = SCNPlane(width: 10, height: 10)
plane.firstMaterial?.isDoubleSided = true
plane.firstMaterial?.lightingModel = .shadowOnly
let planeNode = SCNNode(geometry: plane)
planeNode.eulerAngles.x = -.pi / 2
scene.rootNode.addChildNode(planeNode)

// SETTING A LIGHT
let lightNode = SCNNode()
lightNode.light = SCNLight()
lightNode.light?.type = .directional
lightNode.light?.intensity = 50
lightNode.light?.color = UIColor.black
lightNode.eulerAngles.x = -.pi / 2
scene.rootNode.addChildNode(lightNode)
    
// DEFERRED SHADOWS
lightNode.light?.castsShadow = true
lightNode.light?.shadowMode = .deferred          // important
lightNode.light?.forcesBackFaceCasters = true    // important
lightNode.light?.shadowRadius = 10
lightNode.light?.shadowColor = UIColor.white

这创造了我想要的效果。我在 material 混合模式设置为屏幕模式的平面上添加了 IES 类型的光节点。

let light = SCNLight()
light.type = .IES
light.intensity = 10000

let lightNode = SCNNode()
lightNode.light = light
//set slightly above of the plane, set on Z bc it's rotated on x axis
lightNode.position = SCNVector3Make(0, 0, 0.01)

let planeMaterial = SCNMaterial()
planeMaterial.blendMode = .screen

let planeForLight = SCNPlane(width: 0.9, height: 0.9)
planeForLight.materials = [planeMaterial]

let planeNodeForLight = SCNNode(geometry: planeForLight)
planeNodeForLight.transform = SCNMatrix4MakeRotation(-Float.pi / 2, 1, 0, 0)