ios3dscenekitmodelio

SceneKit: how to recreate lighting from Google Poly for same OBJ file?


The goal is to recreate the lighting for this OBJ file: https://poly.google.com/view/cKryD9VnDEZ

Code to load OBJ file into SceneKit (can download file from above link):

let modelPath = "model.obj"
let url = NSURL(string: modelPath)

let scene = SCNScene(named: modelPath)!
sceneView.autoenablesDefaultLighting = true
sceneView.allowsCameraControl = true
sceneView.scene = scene
sceneView.backgroundColor = UIColor.white

Options tried so far:

1) The default ambient lighting is much harsher than the Google Poly lighting. Removing the ambient lighting rendered everything too flat.

2) Using four directional lights: one in front, one behind, one below, and one above the model. All lights are angled to point at the model. This was the best, but still left some shadows and harsher areas not seen on Google Polymer.

3) Added two more lights to option #2, this time adding lights to the left and right. This one was worse than option #2 since the extra lights combined with the four existing lights and whitewashed the model.

UPDATE AFTER FOLLOWING SUGGESTIONS:

The code now implements an ambient light and a directional light.

Adding the directional light to the camera node, versus the scene root node, made no difference for some reason.

The light code is below.

There are two problems:

1) In Screenshot 1, the right side of the chest is too bright and shows no edges. The far left face of the chest is too dark. The face with the best lighting is in the center. How can you get the lighting to be like this for all faces (or better match the Google Poly lighting)?

2) In Screenshot 2, the directional light appears to have no effect. How can you ensure the back of the model is as light as the front with the suggested architecture of one ambient light and one directional light?

SCREENSHOT 1: enter image description here

SCREENSHOT 2: enter image description here

CODE:

    // Create ambient light
    let ambientLightNode = SCNNode()
    ambientLightNode.light = SCNLight()
    ambientLightNode.light!.type = .ambient
    ambientLightNode.light!.color = UIColor(white: 0.50, alpha: 1.0)

    // Add ambient light to scene
    scene.rootNode.addChildNode(ambientLightNode)

    // Create directional light
    let directionalLight = SCNNode()
    directionalLight.light = SCNLight()
    directionalLight.light!.type = .directional
    directionalLight.light!.color = UIColor(white: 0.40, alpha: 1.0)
    directionalLight.eulerAngles = SCNVector3(x: Float.pi, y: 0, z: 0)

    // Add directional light
    scene.rootNode.addChildNode(directionalLight)

Solution

  • OBJ files loaded through Model I/O use physically based lighting by default. This model has a cartoonish look and uses a lot of ambient lighting with a few specular highlights.

    You should start by converting all your materials to the lambert lighting model.

    Then add an ambient light to you scene. There's a lot of ambient lighting in this scene, every part of the object is lit. A color of 75% white will do.

    Finally attach a directional light to the camera to highlight the polygons facing the user. A color of 50% white sounds about right.