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

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

Code for loading the OBJ file into SceneKit (you can download the file from the link above):

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 

The parameters have been met so far:

1) The default ambient lighting is much tougher than Google Poly lighting. Removing ambient light made everything too flat.

2) Using four directional lights: one in front, one in the back, one below and one above the model. All lights at an angle to indicate the model. This was best, but still left some shadows and harsher areas that were not seen in Google Polymer.

3) Two more indicators were added to option No. 2, this time adding lights left and right. This was worse than option number 2, because additional lights combined with four existing lights whitened the model.

UPDATE AFTER THE FOLLOWING OFFERS:

Now the code implements ambient light and directional light.

Adding directional light to the camera node, compared to the root of the scene node, for some reason has not changed.

Light code below.

There are two problems:

1) In screenshot 1, the right side of the chest is too bright and does not show edges. The far left face of the chest is too dark. The person with the best lighting is in the center. How can you get coverage this way for all faces (or better match Google Poly lighting)?

2) In screenshot 2, directional light has no effect. How can you ensure that the back of the model is as light as the front, with the proposed 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) 
+3
source share
2 answers

OBJ files loaded using model I / O use physical lighting by default. This model has a cartoony look and uses a lot of ambient lighting with several specular highlights.

You should start by converting all your materials into a lambert lighting model.

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

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

+4
source

In addition to MNuages, answer, try to enable occlusion of the surrounding space on the screen (on the camera). For the current camera, this allows you to:

 scnView.pointOfView.camera.screenSpaceAmbientOcclusionIntensity = 1.7; scnView.pointOfView.camera.screenSpaceAmbientOcclusionNormalThreshold = 0.1; scnView.pointOfView.camera.screenSpaceAmbientOcclusionDepthThreshold = 0.08; scnView.pointOfView.camera.screenSpaceAmbientOcclusionBias = 0.33; scnView.pointOfView.camera.screenSpaceAmbientOcclusionRadius = 3.0; 

You will probably have to adjust the values ​​a bit to get the desired results, this is what works for me in a particular scene.

+1
source

Source: https://habr.com/ru/post/1275500/


All Articles