SceneKit ARKit 发光效果
SceneKit ARKit glowing effect
您好,我正在尝试在节点周围产生发光效果。
我使用了 SCNNode 过滤器 属性 并设置为 CIFilter 数组。
它仅在节点后面没有我不理解的节点时才起作用并呈现。我尝试设置渲染顺序和 readDepth 选项但没有成功。我真的被困在这一点上,非常感谢您的意见!
请查看示例和代码示例的屏幕截图。
func addBloom() -> [CIFilter]? {
let bloomFilter = CIFilter(name:"CIBloom")!
bloomFilter.setValue(10.0, forKey: "inputIntensity")
bloomFilter.setValue(30.0, forKey: "inputRadius")
return [bloomFilter]
}
使用以下方式调用:
myNode.filters = addBloom()
最后一点,我注意到要使 CIFilter 与 Metal 一起工作,需要将抗锯齿设置为 .none
arSceneView.antialiasingMode = .none
非常感谢!
阿德里安
您是否尝试过将未应用过滤器的节点的 writesToDepthBuffer
设置为 false?
供您参考 writesToDepthBuffer
指的是:
SceneKit’s rendering process uses a depth buffer to determine the
ordering of rendered surfaces relative to the viewer. The default
value of this property is YES, specifying that SceneKit saves depth
information for each rendered pixel for use by later rendering passes.
Typically, you disable writing to the depth buffer when rendering
semitransparent objects, because later stages of the rendering process
may require depth information about the opaque objects behind them.
这个例子似乎工作正常:
/// Generates An SCNPlane & A Red & Green SCNSphere
func generateNodes(){
let planeNode = SCNNode(geometry: SCNPlane(width: 1, height: 0.5))
planeNode.geometry?.firstMaterial?.diffuse.contents = UIColor.black
planeNode.position = SCNVector3(0, 0, -1)
let redSphereNode = SCNNode(geometry: SCNSphere(radius: 0.1))
redSphereNode.geometry?.firstMaterial?.diffuse.contents = UIColor.red
redSphereNode.position = SCNVector3(-0.3, 0, -1)
redSphereNode.filters = addBloom()
let greenSphereNode = SCNNode(geometry: SCNSphere(radius: 0.1))
greenSphereNode.geometry?.firstMaterial?.diffuse.contents = UIColor.green
greenSphereNode.position = SCNVector3(0.3, 0, -1)
greenSphereNode.filters = addBloom()
self.augmentedRealityView.scene.rootNode.addChildNode(planeNode)
self.augmentedRealityView.scene.rootNode.addChildNode(redSphereNode)
self.augmentedRealityView.scene.rootNode.addChildNode(greenSphereNode)
planeNode.geometry?.firstMaterial?.writesToDepthBuffer = false
}
/// Creates An Array Of CIBloom Filters
///
/// - Returns: [CIFilter]?
func addBloom() -> [CIFilter]? {
let bloomFilter = CIFilter(name:"CIBloom")!
bloomFilter.setValue(10.0, forKey: "inputIntensity")
bloomFilter.setValue(30.0, forKey: "inputRadius")
return [bloomFilter]
}
但是要注意一件事,我确实注意到,如果我使用具有透明背景的图像作为 SCNPlane 的内容,它不起作用,但使用另一个图像就可以了。
希望它能为您指明正确的方向...
您好,我正在尝试在节点周围产生发光效果。 我使用了 SCNNode 过滤器 属性 并设置为 CIFilter 数组。
它仅在节点后面没有我不理解的节点时才起作用并呈现。我尝试设置渲染顺序和 readDepth 选项但没有成功。我真的被困在这一点上,非常感谢您的意见!
请查看示例和代码示例的屏幕截图。
func addBloom() -> [CIFilter]? {
let bloomFilter = CIFilter(name:"CIBloom")!
bloomFilter.setValue(10.0, forKey: "inputIntensity")
bloomFilter.setValue(30.0, forKey: "inputRadius")
return [bloomFilter]
}
使用以下方式调用:
myNode.filters = addBloom()
最后一点,我注意到要使 CIFilter 与 Metal 一起工作,需要将抗锯齿设置为 .none
arSceneView.antialiasingMode = .none
非常感谢!
阿德里安
您是否尝试过将未应用过滤器的节点的 writesToDepthBuffer
设置为 false?
供您参考 writesToDepthBuffer
指的是:
SceneKit’s rendering process uses a depth buffer to determine the ordering of rendered surfaces relative to the viewer. The default value of this property is YES, specifying that SceneKit saves depth information for each rendered pixel for use by later rendering passes. Typically, you disable writing to the depth buffer when rendering semitransparent objects, because later stages of the rendering process may require depth information about the opaque objects behind them.
这个例子似乎工作正常:
/// Generates An SCNPlane & A Red & Green SCNSphere
func generateNodes(){
let planeNode = SCNNode(geometry: SCNPlane(width: 1, height: 0.5))
planeNode.geometry?.firstMaterial?.diffuse.contents = UIColor.black
planeNode.position = SCNVector3(0, 0, -1)
let redSphereNode = SCNNode(geometry: SCNSphere(radius: 0.1))
redSphereNode.geometry?.firstMaterial?.diffuse.contents = UIColor.red
redSphereNode.position = SCNVector3(-0.3, 0, -1)
redSphereNode.filters = addBloom()
let greenSphereNode = SCNNode(geometry: SCNSphere(radius: 0.1))
greenSphereNode.geometry?.firstMaterial?.diffuse.contents = UIColor.green
greenSphereNode.position = SCNVector3(0.3, 0, -1)
greenSphereNode.filters = addBloom()
self.augmentedRealityView.scene.rootNode.addChildNode(planeNode)
self.augmentedRealityView.scene.rootNode.addChildNode(redSphereNode)
self.augmentedRealityView.scene.rootNode.addChildNode(greenSphereNode)
planeNode.geometry?.firstMaterial?.writesToDepthBuffer = false
}
/// Creates An Array Of CIBloom Filters
///
/// - Returns: [CIFilter]?
func addBloom() -> [CIFilter]? {
let bloomFilter = CIFilter(name:"CIBloom")!
bloomFilter.setValue(10.0, forKey: "inputIntensity")
bloomFilter.setValue(30.0, forKey: "inputRadius")
return [bloomFilter]
}
但是要注意一件事,我确实注意到,如果我使用具有透明背景的图像作为 SCNPlane 的内容,它不起作用,但使用另一个图像就可以了。
希望它能为您指明正确的方向...