A material that comes from a shader graph in a Reality Composer Pro project, or a MaterialX shader.
Use ShaderGraphMaterial when retrieving a shaders you build in Reality Composer
Pro's shader graph. The following code demonstrates retrieving the first material
from an entity loaded from a Reality Composer Proj project and sets a new value for
one of its named parameters:
```swift
if var modelComponent = entity.modelComponent {
modelComponent.materials = modelComponent.materials.map {
guard var material = $0 as? ShaderGraphMaterial else { return $0 }
if material.parameterNames.contains(myMaterialParameterName) {
do {
try material.setParameter(name: myMaterialParameterName,
value: .float(isPowered ? 1.0 : 0.0))
} catch {
// Handle error.
}
}
return material
}
entity.modelComponent = modelComponent
}
```
In addition to creating instances of `ShaderGraphMaterial` from Reality Composer Pro's shader graph, you can also create them directly from Material X shaders.
You can also load shader graph materials directly from `.reality` files:
```swift
let shader = try! await ShaderGraphMaterial(named: "/Root/Glass", from: "Scene.usda")
````
For more information on using custom parameters in a `ShaderGraphMaterial`, see
<doc://documentation.apple.com/documentation/visionos/implementing-adjustable-material-in-visionos>.
Members (21)
get · iOS 18.0+
readsDepth
TypeScript
get readsDepth(): boolean
Swift declaration
var readsDepth: Bool { get set }
A boolean value that determines whether this material performs the depth test by reading RealityKit's depth buffer.
If true, meshes with this material will depth test each of their fragments when being rendered.
If an object that writes depth is in front of this material, this material will be hidden.
If false, meshes with this material will ignore the depth test, and always render all of their
fragments during their draw call, regardless of the positioning of other objects in the scene.
Note that other objects may still render on top of this material, depending on draw order.
The default value is true.
set · iOS 18.0+
readsDepth
TypeScript
set readsDepth(value: boolean)
Swift declaration
var readsDepth: Bool { get set }
A boolean value that determines whether this material performs the depth test by reading RealityKit's depth buffer.
If true, meshes with this material will depth test each of their fragments when being rendered.
If an object that writes depth is in front of this material, this material will be hidden.
If false, meshes with this material will ignore the depth test, and always render all of their
fragments during their draw call, regardless of the positioning of other objects in the scene.
Note that other objects may still render on top of this material, depending on draw order.
The default value is true.
get · iOS 18.0+
faceCulling
TypeScript
get faceCulling(): MaterialParameterTypes_FaceCulling
Swift declaration
var faceCulling: ShaderGraphMaterial.FaceCulling { get set }
A process in which the system specifies polygons to remove before
rendering a mesh using this material.
To improve performance, RealityKit culls polygons, or faces, that it
determines won’t be visible. Discarding faces that aren’t part of the
final render eliminates the need to do any calculations for those
faces.
RealityKit recognizes when a face aims toward the camera (a front face)
or away from the camera (a back face). This value controls the type of
faces RealityKit culls.
This value defaults to ``MaterialParameterTypes/FaceCulling/back``,
which means RealityKit removes faces that point away from the camera.
Most of the time, this is the correct behavior, because back faces are
usually obscured by other front-facing polygons.
You can change the culling behavior to cull front faces instead or to
turn off face culling altogether, but be aware that turning off face
culling results in less efficient rendering and may negatively impact
your app’s frame rate.
set · iOS 18.0+
faceCulling
TypeScript
set faceCulling(value: MaterialParameterTypes_FaceCulling)
Swift declaration
var faceCulling: ShaderGraphMaterial.FaceCulling { get set }
A process in which the system specifies polygons to remove before
rendering a mesh using this material.
To improve performance, RealityKit culls polygons, or faces, that it
determines won’t be visible. Discarding faces that aren’t part of the
final render eliminates the need to do any calculations for those
faces.
RealityKit recognizes when a face aims toward the camera (a front face)
or away from the camera (a back face). This value controls the type of
faces RealityKit culls.
This value defaults to ``MaterialParameterTypes/FaceCulling/back``,
which means RealityKit removes faces that point away from the camera.
Most of the time, this is the correct behavior, because back faces are
usually obscured by other front-facing polygons.
You can change the culling behavior to cull front faces instead or to
turn off face culling altogether, but be aware that turning off face
culling results in less efficient rendering and may negatively impact
your app’s frame rate.
get · iOS 18.0+
writesDepth
TypeScript
get writesDepth(): boolean
Swift declaration
var writesDepth: Bool { get set }
A boolean value that determines whether this material writes its depth into RealityKit's depth buffer.
If true, meshes with this material will occlude objects behind them by writing their depth
into RealityKit's depth buffer.
If false, meshes with this material will not write their depth into
RealityKit's depth buffer, and may be overwritten by objects drawn behind them, depending on
draw order.
The default value is true.
set · iOS 18.0+
writesDepth
TypeScript
set writesDepth(value: boolean)
Swift declaration
var writesDepth: Bool { get set }
A boolean value that determines whether this material writes its depth into RealityKit's depth buffer.
If true, meshes with this material will occlude objects behind them by writing their depth
into RealityKit's depth buffer.
If false, meshes with this material will not write their depth into
RealityKit's depth buffer, and may be overwritten by objects drawn behind them, depending on
draw order.
The default value is true.
Loads a ShaderGraphMaterial from MaterialX data.
- Parameters:
- materialXLabel: The name of the ShaderGraphMaterial in the MaterialX data.
- data: The data containing the MaterialX file contents.
- Returns: A ShaderGraphMaterial object from the data with the label specified.
get triangleFillMode(): MaterialParameterTypes_TriangleFillMode
Swift declaration
var triangleFillMode: ShaderGraphMaterial.TriangleFillMode { get set }
The object that controls how RealityKit draws triangles.
A value of ``MaterialParameterTypes/TriangleFillMode/fill`` causes RealityKit
to draw triangles normally, while a value of ``MaterialParameterTypes/TriangleFillMode/lines``
turns on wireframe rendering.
set · iOS 18.0+
triangleFillMode
TypeScript
set triangleFillMode(value: MaterialParameterTypes_TriangleFillMode)
Swift declaration
var triangleFillMode: ShaderGraphMaterial.TriangleFillMode { get set }
The object that controls how RealityKit draws triangles.
A value of ``MaterialParameterTypes/TriangleFillMode/fill`` causes RealityKit
to draw triangles normally, while a value of ``MaterialParameterTypes/TriangleFillMode/lines``
turns on wireframe rendering.
init(named name: String, from file: String, in bundle: Bundle? = nil) async throws
Loads a ShaderGraphMaterial from a bundle.
- Parameters:
- name: The name of the ShaderGraphMaterial within the file.
For USD files, this is the full path of the material prim (such as "/Root/MyMaterial").
- file: The name of the file within the bundle.
- bundle: The bundle containing the resource. Specify nil to search the app’s main
bundle.
- Returns: A ShaderGraphMaterial object from the file with the name specified.
Supported file formats are USD (.usd, .usda, .usdc, .usdz) and Reality File (.reality).
init(named name: String, from url: URL) async throws
Loads a ShaderGraphMaterial from a url.
- Parameters:
- name: The name of the ShaderGraphMaterial within the file.
For USD files, this is the full path of the material prim (such as "/Root/MyMaterial").
- url: The path or address of the file containing the ShaderGraphMaterial.
- Returns: A ShaderGraphMaterial object from the file with the name specified.
Supported file formats are USD (.usd, .usda, .usdc, .usdz) and Reality File (.reality).
init(named name: String, from data: Data) async throws
Loads a ShaderGraphMaterial from a named material within a USD file.
- Parameters:
- name: The name of the ShaderGraphMaterial within the USD file.
- data: A data object containing USD file data
- Returns: A ShaderGraphMaterial object from the file with the name specified.
Supported file formats are USD (.usd, .usda, .usdc, .usdz)
Create a ShaderGraphMaterial with an already initialized Program.
Use this method when you want to preload a library of shaders
and create instances of them quickly and synchronously via ShaderGraphMaterials at runtime.
get · iOS 27.0+
program
TypeScript
get program(): ShaderGraphMaterial_Program
Swift declaration
var program: ShaderGraphMaterial.Program { get set }
set · iOS 27.0+
program
TypeScript
set program(value: ShaderGraphMaterial_Program)
Swift declaration
var program: ShaderGraphMaterial.Program { get set }