0

Here is a simple SceneKit project with two boxes. I’ve added a CIBloom filter to one of them. When I rotate the scene, the ”glow” effect is rendered behind the other box?

I saw someone else had this issue and solved it by setting writesToDepthBuffer to false but in my case it’s important to keep all 3D data (I want to rotate around the scene).

I’ve provided a couple of images and the code.

I would really appreciate any help!

SceneKit + CIFilter SceneKit + CIFilter SceneKit + CIFilter

Here is the code I used:

import UIKit
import QuartzCore
import SceneKit

class GameViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        // create a new scene
        let scene = SCNScene()
        
        // create and add a camera to the scene
        let cameraNode = SCNNode()
        cameraNode.camera = SCNCamera()
        scene.rootNode.addChildNode(cameraNode)
        
        // place the camera
        cameraNode.position = SCNVector3(x: 0, y: 0, z: 15)
        
        let box = SCNNode(geometry: SCNBox(width: 8.0, height: 8.0, length: 2.0, chamferRadius: 0.0))
        box.geometry?.firstMaterial?.diffuse.contents = UIColor.green
        box.position.z = -4
        scene.rootNode.addChildNode(box)
        
        let box2 = SCNNode(geometry: SCNBox(width: 1.0, height: 1.0, length: 1.0, chamferRadius: 0.0))
        box2.geometry?.firstMaterial?.diffuse.contents = UIColor.red
        scene.rootNode.addChildNode(box2)
        
        let bloomFilter = CIFilter(name:"CIBloom")!
        bloomFilter.setValue(10.0, forKey: "inputIntensity")
        bloomFilter.setValue(100.0, forKey: "inputRadius")
        box2.filters = [bloomFilter]
        
        // retrieve the SCNView
        let scnView = self.view as! SCNView
        
        // set the scene to the view
        scnView.scene = scene
        
        // allows the user to manipulate the camera
        scnView.allowsCameraControl = true
        
        scnView.autoenablesDefaultLighting = true
        
        // show statistics such as fps and timing information
        scnView.showsStatistics = true
        
        // configure the view
        scnView.backgroundColor = UIColor.black
    }
    
    override var prefersStatusBarHidden: Bool {
        return true
    }
    
    override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
        if UIDevice.current.userInterfaceIdiom == .phone {
            return .allButUpsideDown
        } else {
            return .all
        }
    }

}

Andy3000
  • 11
  • 1
  • 4
  • You could probably correct this by defining the renderingOrder to higher or lower values applyed on the node you need the effect: Also see: https://developer.apple.com/documentation/scenekit/scnnode/1407978-renderingorder – ZAY Nov 01 '22 at 13:53
  • Thank you so much for taking the time to answer, ZAY. I’ve set the rendering order on box to 100 and box2 to 200 but no difference I’m afraid. They render correctly in 3D but the post processing effect seems to render in an unexpected way. Any other suggestions? – Andy3000 Nov 01 '22 at 14:34
  • there is another approach. set your camera to wantsHDR = true, then you also enable Bloom on the camera. make the Material to physicallyBased, set and enable the emission color texture and set it to a relative high value like 10. you will have to play around with Bloom values. Hope this will hepl you in some way – ZAY Nov 02 '22 at 07:30

0 Answers0