barthdamon
barthdamon

Reputation: 49

Loading USDZ for ARKit (not a QLPreview) Material Properties

I'm trying to load a usdz file into ARKkit that has glass transparency on one of its materials. When I put the model into a QLPreviewController the glass renders properly. The problem is I want to render the glass in a SCNScene with ARKit, not QLPreview, the glass material is black when I load it into a SCNScene. It is also black when I preview it in Xcode.

Not sure what QLPreview is doing, or if I'm doing something wrong with my lighting in my scene. I've removed all my custom lights and just have autoenablesDefaultLighting set to true. Then I set each material's lighting model to be PhysicallyBased. But still just black.

Anybody know what I need to do to render the same way QLPreview does? Do I need to unpack the usdz to get the transparency texture and set that manually?

Thanks!

Upvotes: 2

Views: 1890

Answers (1)

Andy Jazz
Andy Jazz

Reputation: 58043

The best way to create a glass in SceneKit is to use Phong shading model (not a PBR). At the moment there are no PBR glass in SceneKit framework, so you need to use a fake one. For making a fake glass you need to create a SCNMaterial with the following properties:

let material = SCNMaterial()

material.lightingModel = .phong
material.diffuse.contents = UIColor(white: 0.2, alpha: 1)
material.diffuse.intensity = 0.9
material.specular.contents = UIColor(white: 1, alpha: 1)
material.specular.intensity = 1.0
material.reflective.contents = UIImage(named: "fileName.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

.fresnelExponent property determines the intensity of reflections in a surface based on its angle relative to the viewer. A higher Fresnel exponent increases the visibility of reflections when the material is viewed from a shallow angle. It's not an IOR (Fresnel's Index of Refraction).

PBR glass or PBR water objects are very expensive at render time due to ray-tracing technology.

enter image description here

If you need a partial transparency of your object – just use transparent slot in Material Inspector to load a B&W mask for transparent/opaque regions.

Upvotes: 2

Related Questions