gpt4 book ai didi

SceneKit ARKit 发光效果

转载 作者:行者123 更新时间:2023-12-02 21:43:25 26 4
gpt4 key购买 nike

嗨,我正在尝试在节点周围产生发光效果。我使用了 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() 

enter image description here

最后一点,我注意到 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 的内容,它就不起作用,尽管使用另一个图像就可以了。

希望它能为您指明正确的方向...

关于SceneKit ARKit 发光效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51390603/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com