5

Ok, I am trying desperately to achieve this sort of warm lighting on my objects when added to my ARScene in Swift/Xcode - warm lighting and little glowing lights around:

enter image description here

To be clear, I do NOT want the objects I add to my scene to look like they belong in the surrounding room. I want them to stand out/ look warm and glow.All the tutorials on ARKit teach you how to mimic the lighting of the actual room.

Xcode has several lighting options, pulling from the surroundings gathered by the camera because with:

if let lightEstimate = session.currentFrame?.lightEstimate

I can print out the warmth, intensity, etc. And I also have these properties currently set to match the light of room:

sceneView.automaticallyUpdatesLighting = true
extension ARSCNView {

    func setup() { //SCENE SETUP
        antialiasingMode = .multisampling4X
        autoenablesDefaultLighting = true
        preferredFramesPerSecond = 60
        contentScaleFactor = 1.3

        if let camera = pointOfView?.camera {
            camera.wantsHDR = true
            camera.wantsExposureAdaptation = true
            camera.exposureOffset = -1
            camera.minimumExposure = -1
            camera.maximumExposure = 3
        }
    }
}

I have tried upping the emission on my object's textures and everything but nothing achieves the effect. Adding a light just turns the objects black/no color.

What is wrong here?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
blue
  • 7,175
  • 16
  • 81
  • 179

2 Answers2

5

To create this type of glowing red neon light result in ARKit. You can do the following.

enter image description here

You need to create a reactor.scnp (scenekit particle System File) and make the following changes to create the glowing red halo. This should be place in your Resources directory of the playground along with the file spark.png

These are the settings to change from the default reactor type. Leave all the other settings alone.

  1. Change the Image animate color to red/orange/red/black

  2. speed factor = 0.1

  3. enable lighting checked

  4. Emitter Shape = Sphere

  5. Image Size = 0.5

  6. Image Intensity = 0.1

  7. Simulation Speed Factor = 0.1

Note: The code below is playground app I use for testing purposes. You just tap anywhere to add the Neon light into the scene. You can place as many neon lights as you like.

import ARKit
import SceneKit
import PlaygroundSupport
import SceneKit.ModelIO

class ViewController: NSObject {

    var sceneView: ARSCNView
    init(sceneView: ARSCNView) {
        self.sceneView = sceneView

        super.init()

        self.setupWorldTracking()
        self.sceneView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(ViewController.handleTap(_:))))
    }

    private func setupWorldTracking() {
        if ARWorldTrackingConfiguration.isSupported {
            let configuration = ARWorldTrackingConfiguration()
            configuration.planeDetection = .horizontal
            configuration.isLightEstimationEnabled = true
            self.sceneView.session.run(configuration, options: [])
        }
    }

    @objc func handleTap(_ gesture: UITapGestureRecognizer) {
        let results = self.sceneView.hitTest(gesture.location(in: gesture.view), types: ARHitTestResult.ResultType.featurePoint)
        guard let result: ARHitTestResult = results.first else {
            return
        }
        let cylinder = SCNCylinder(radius: 0.05, height: 1)
        cylinder.firstMaterial?.emission.contents = UIColor.red
        cylinder.firstMaterial?.emission.intensity = 1


        let spotLight = SCNNode()
        spotLight.light = SCNLight()
        spotLight.scale = SCNVector3(1,1,1)
        spotLight.light?.intensity = 1000
        spotLight.castsShadow = true
        spotLight.position = SCNVector3Zero
        spotLight.light?.type = SCNLight.LightType.directional
        spotLight.light?.color = UIColor.white

        let particleSystem = SCNParticleSystem(named: "reactor", inDirectory: nil)
        let systemNode = SCNNode()
        systemNode.addParticleSystem(particleSystem!)


        let node = SCNNode(geometry: cylinder)

        let position = SCNVector3Make(result.worldTransform.columns.3.x, result.worldTransform.columns.3.y, result.worldTransform.columns.3.z)

        systemNode.position = position
        node.position = position

        self.sceneView.scene.rootNode.addChildNode(spotLight)
        self.sceneView.scene.rootNode.addChildNode(node)
        self.sceneView.scene.rootNode.addChildNode(systemNode)
    }
}

let sceneView = ARSCNView()

let viewController = ViewController(sceneView: sceneView)
sceneView.autoenablesDefaultLighting = false
PlaygroundPage.current.needsIndefiniteExecution = true
PlaygroundPage.current.liveView = viewController.sceneView
Clay
  • 1,721
  • 2
  • 10
  • 18
0

If your looking for a neon/glowing effect in your scene... these previous answers to a similar question asked about glowing/neon lighting should give you some guidance.

As you will see from the answers provided sceneKit does not have built-in support for volumetric lighting, all the approaches are more hacks to achieve a similar effect to a glowing light.

iOS SceneKit Neon Glow

To add a "red" directional light effect to your scene... which is an alternative to using sceneView.autoenablesDefaultLighting = true

let myLight = SCNNode()
myLight.light = SCNLight()
myLight.scale = SCNVector3(1,1,1)
myLight.intensity = 1000
myLight.position = SCNVector3Zero
myLight.light?.type = SCNLight.LightType.directional
myLight.light?.color = UIColor.red

// add the light to the scene

sceneView.scene.rootNode.addChildNode(myLight)

note: This effect makes all the objects in the scene more reddish.

Clay
  • 1,721
  • 2
  • 10
  • 18