The docs for RealityKit include the structs: OcclusionMaterial
, SimpleMaterial
, and UnlitMaterial
for adding materials to a Mode
Updated: June 23, 2020.
There are 4 types of materials in RealityKit 2.0 at the moment:
So you can use the following code with a SimpleMaterial()
class:
@IBOutlet var arView: ARView!
let sceneObjects = try! Experience.loadAllMyObjects()
var simpleMaterial = SimpleMaterial()
simpleMaterial.baseColor = try! MaterialColorParameter.texture(
TextureResource.load(named: "img.jpg"))
simpleMaterial.metallic = MaterialScalarParameter(floatLiteral: 0.9)
simpleMaterial.roughness = MaterialScalarParameter(floatLiteral: 0.1)
simpleMaterial.tintColor = UIColor.yellow
/*
simpleMaterial.baseColor = MaterialColorParameter.color(UIColor(red: 0.7,
green: 0.5,
blue: 0.2,
alpha: 1.0))
*/
And at the moment there are only 4 methods in RealityKit to create simple 3D primitives:
generateBox()
generateSphere()
generatePlane()
generateText()
So let's use one of them:
let mesh: MeshResource = .generateBox(size: 2.5)
let component = ModelComponent(mesh: mesh,
materials: [simpleMaterial])
sceneObjects.components.set(component)
arView.scene.anchors.append(sceneObjects)
We know that in SceneKit there are 5 different shading models, so we can use RealityKit's SimpleMaterial
and UnlitMaterial
to generate all these five shaders that we've been accustomed to.
Let's see how it looks like:
SCNMaterial.LightingModel.blinn – SimpleMaterial(color: . gray,
roughness: .float(0.5),
isMetallic: false)
SCNMaterial.LightingModel.lambert – SimpleMaterial(color: . gray,
roughness: .float(1.0),
isMetallic: false)
SCNMaterial.LightingModel.phong – SimpleMaterial(color: . gray,
roughness: .float(0.0),
isMetallic: false)
SCNMaterial.LightingModel.physicallyBased – SimpleMaterial(color: . gray,
roughness: .float(0.0),
isMetallic: true)
SCNMaterial.LightingModel.constant – UnlitMaterial(color: .gray)