4

I have several objects in my scene, all of which had the "lighting model" of their material set to be physically based.

When I run the app, the view I get looks nothing like the scene editor - it instead looks more like Phong materials.

Is there a root node I need to change in order to have it render physically based from the get-go? I'm new to objective-c, so I'm not sure if I need to set the lighting model of the root node to physically based, and if so, how I would access the root node (and furthermore, can the root node even have a lighting model attribute since it itself is not renderable).

My models were created in ZBrush, retopologized and UV mapped in UIViewController, and were converted to .dae files in Blender. Is it possible that one of those programs set the material shader to be phong? Wouldn't the SceneKit editor overwrite that and set it to physically based?

As far as I can tell, all versions of Xcode, iOS, and SceneKit are recent enough to support PBR.

Thank you for any help :)

Nirmalsinh Rathod
  • 5,079
  • 4
  • 26
  • 56
DanN
  • 41
  • 2
  • Which device are you using? – jlsiewert Jul 28 '17 at 13:18
  • 1
    Make sure you are using the Metal renderer (physically-based shading is not available in the OpenGL render). Metal will be disabled on old devices, in the simulator, or if OpenGL is forced when creating the SCNView (see inspector in Interface Builder or options dictionary in code). – mnuages Jul 28 '17 at 14:43
  • Thanks for this! I thought the simulator was built on Metal as of Xcode 11ish though. – Canucklesandwich Mar 17 '20 at 18:13

1 Answers1

1

It's quite easy to apply a physically based shader to your model in SceneKit (or change its texture or color). If your model consists of several parts, find the part you need in the hierarchical level using the following approach:

enter image description here

enter image description here

SCNScene *scene = [SCNScene sceneNamed: @"art.scnassets/biplane.usdz"];

SCNNode *modelNode = [scene.rootNode childNodeWithName: @"biplane"      
                                           recursively: YES];

SCNNode *body = modelNode.childNodes[0].childNodes[0]
                         .childNodes[0].childNodes[0];

body.geometry.materials[0].lightingModelName = SCNLightingModelPhysicallyBased;
body.geometry.materials[0].diffuse.contents = [UIColor redColor];
body.geometry.materials[0].metalness.contents = @1.0;
body.geometry.materials[0].roughness.contents = @0.0; 

Resulted biplane.usdz model

enter image description here

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220