There's no photorealistic glass with true index of refraction (IoR) in SceneKit but you can easily create a fake one using phong
shader. Phong shader also has three important properties of a glass – specularity, reflectivity, and fresnelExponent.
For metallic material use physicallyBased
shading model.
Here's a code:
import SceneKit
class ViewController: NSViewController {
override func viewDidLoad() {
super.viewDidLoad()
let sceneView = self.view as! SCNView
sceneView.scene = SCNScene(named: "glasses.scn")!
sceneView.allowsCameraControl = true
sceneView.pointOfView?.position.z = 20
let glassesFrame = sceneView.scene?.rootNode.childNode(withName: "glassesFrame",
recursively: true)
glassesFrame?.geometry?.firstMaterial?.lightingModel = .physicallyBased
glassesFrame?.geometry?.firstMaterial?.metalness.intensity = 1
glassesFrame?.geometry?.firstMaterial?.diffuse.contents = NSColor.systemBrown
let lens1 = sceneView.scene?.rootNode.childNode(withName: "rightLens",
recursively: true)
let lens2 = sceneView.scene?.rootNode.childNode(withName: "leftLens",
recursively: true)
let material = SCNMaterial()
material.lightingModel = .phong
material.diffuse.contents = NSColor(white: 0.2,
alpha: 1)
material.diffuse.intensity = 0.9
material.specular.contents = NSColor(white: 1,
alpha: 1)
material.specular.intensity = 1.0
material.reflective.contents = NSImage.Name("art.scnassets/texture.png")
material.reflective.intensity = 2.0
material.transparencyMode = .dualLayer
material.fresnelExponent = 2.2
material.isDoubleSided = true
material.blendMode = .alpha
material.shininess = 100
material.transparency.native = 0.7
material.cullMode = .back
lens1?.geometry?.firstMaterial = material
lens2?.geometry?.firstMaterial = material
}
}