Search code examples
swiftscenekitmetal

SceneKit: SCNRenderingAPI


I am trying to use the PhysicallyBased lighting model for my SCNView... but in order to do that, I must set the view's renderingAPI property to SCNRenderingAPIMetal.

The game technology I chose was SceneKit, not Metal, so that may be the problem. However, I think that is just a template. Shouldn't I be able to import the Metal framework somehow?

edit: I get the error saying that the view.renderingAPI property is immutable...


Solution

  • SceneKit is an abstraction built upon OpenGL/Metal. It wraps commonly used operations, shading models, etc... in a nice framework so programmers don't have to implement an entire rendering pipeline. You should not need to drop down to Metal to do commonly supported operations such as physically based rendering.

    To implement PBR, you need to specify that your object is using PBR and set the various inputs necessary to render the effect:

    let material = firstNode.geometry?.firstMaterial
    material?.lightingModelName = SCNLightingModelPhysicallyBased
    material?.diffuse.contents = UIImage(named: "albedo.png")
    material?.roughness.contents = UIImage(named: "roughness.png")
    material?.metalness.contents = UIImage(named: "metalness.png")
    material?.normal.contents = UIImage(named: "normal.png")
    

    You should only need to drop down to Metal if you are trying to implement an effect that is not supported by SceneKit. Hope that helps!