Search code examples
swiftscenekitvirtual-realitypost-processing

SceneKit – Adding vignette to SCNView has no effect


I'm trying to set up a vignette effect within a SCNView. I did this following this tutorial using more or less the same code as I'm unexperienced with the range of the values. But when I apply that to my SCNViews camera object, nothing happens.

The docs about vignette read that it is necessary to set wantsHDR = true so I did that without any noticeable difference.

// scene setup (light, models, etc.)
...
sceneView.backgroundColor = .gray
sceneView.allowsCameraControl = true
let camera = sceneView.scene?.rootNode.camera
camera?.wantsHDR = true
camera?.vignettingPower = 0.6

camera?.bloomIntensity = 1.4
camera?.bloomBlurRadius = 1.0
    
camera?.fStop = 20.0
camera?.fStop = 5.0
camera?.focusDistance = 1.0

I've only changed the parameters which were marked as deprecated but that wasn't the issue.

I've instanciated the SCNView with the Storyboard and I'm accessing it by having an Outlet in my ViewController and I can use lot of functions with success.

Further I experienced problems setting up MSAA4x with sceneView.antialiasingMode = .multisampling4X. No difference in the outcome. And some more methods/parameters with skybox/environment lighting not doing anything (see this post).

No errors shown in the console.


Solution

  • If you added a new camera to the scene, it would render a vignette.

    let cameraNode = SCNNode()
    cameraNode.camera = SCNCamera()
    cameraNode.position.z = 10
    cameraNode.camera?.wantsHDR = true
    cameraNode.camera?.vignettingPower = 1
    cameraNode.camera?.vignettingIntensity = 1
    sceneView.scene?.rootNode.addChildNode(cameraNode)
    

    enter image description here

    Your approach doesn't work because you're accessing the default camera.

    cameraNode.camera = sceneView.scene?.rootNode.camera