SceneKit:如何从 Google Poly 为同一个 OBJ 文件重新创建照明? [英] SceneKit: how to recreate lighting from Google Poly for same OBJ file?

查看:28
本文介绍了SceneKit:如何从 Google Poly 为同一个 OBJ 文件重新创建照明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标是为此 OBJ 文件重新创建光照:

屏幕截图 2:

代码:

//创建环境光让环境光节点 = SCNNode()环境光节点.light = SCNLight()ambientLightNode.light!.type = .ambientambientLightNode.light!.color = UIColor(white: 0.50, alpha: 1.0)//给场景添加环境光scene.rootNode.addChildNode(ambientLightNode)//创建定向光让 directionalLight = SCNNode()方向光.光 = SCNLight()directionLight.light!.type = .directionaldirectionalLight.light!.color = UIColor(white: 0.40, alpha: 1.0)directionalLight.eulerAngles = SCNVector3(x: Float.pi, y: 0, z: 0)//添加定向光Scene.rootNode.addChildNode(定向光)

解决方案

默认情况下,通过模型 I/O 加载的 OBJ 文件使用基于物理的照明.此模型具有卡通外观,并使用大量环境照明和少量镜面高光.

您应该首先将所有材料转换为 lambert 光照模型.

然后添加一个ambient 点亮你的场景.这个场景中有很多环境照明,物体的每个部分都被照亮.color 75% 的白色就可以了.

最后附上一个directional 照亮相机以突出显示面向用户的多边形.color 50% 的白色声音没错.

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:

SCREENSHOT 2:

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)

解决方案

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.

这篇关于SceneKit:如何从 Google Poly 为同一个 OBJ 文件重新创建照明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆