我想把一个SCNLight节点投射到透明的SCNFloor?这将在真实曲面上提供灯光投影的效果。类似于投射阴影的shadowOnly照明模型。这个是可能的吗?
发布于 2021-05-27 19:57:25
是的,您可以通过投射白色(或出血颜色)阴影而不是黑色阴影来实现。为此,您必须使用在后处理过程中渲染的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发布于 2021-06-02 21:36:36
这就产生了我想要的效果。我在材质混合模式设置为屏幕模式的平面上添加了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)

https://stackoverflow.com/questions/67720068
复制相似问题