iosios11arkit

Darken/Lighten ARKit camera feed behind objects


I'm currently working on an ARKit project where I would like to darken the actual camera feed so the objects in my 3D scene stand out more.

2 Solutions I found so far:

A) Manually applying CIFilter to the camera frames and setting those as background image to the SceneKit scene as answered in this SO post The problem here is that fps tanks significantly.

B) Set a background color like so:

sceneView.scene.background.contents = UIColor(white: 0.0, alpha: 0.2)

Sadly, colors with alpha <1 are still opaque, so no matter what alpha I set I can't see anything of the camera feed.

Can anyone think of a different trick to darken the camera feed?


Solution

  • Your option B doesn't work for two reasons:

    1. the scene view is opaque, so there's nothing behind it for a partially transparent background color to blend with.
    2. sceneView.scene.background is what actually displays the camera image, so if you set it to a color you're not displaying the camera image at all anymore.

    Some other options (mostly untested) you might look into: