One Logo Pool Ball
RealityFoundation · IOS API REFERENCE

ShaderGraphMaterial

struct · iOS 18.0+ · SDK 27.1

struct ShaderGraphMaterial

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.

method · iOS 18.0+

getParameter

TypeScript
getParameterName(name: string): (MaterialParameters_Value) | null
Swift declaration
func getParameter(name: String) -> MaterialParameters.Value?
method · iOS 18.0+

getParameter

TypeScript
getParameterHandle(handle: MaterialParameters_Handle): (MaterialParameters_Value) | null
Swift declaration
func getParameter(handle: MaterialParameters.Handle) -> MaterialParameters.Value?
method · iOS 18.0+

setParameter

TypeScript
setParameterNameValue(name: string, newValue: MaterialParameters_Value): void
Swift declaration
mutating func setParameter(name: String, value newValue: MaterialParameters.Value) throws
method · iOS 18.0+

setParameter

TypeScript
setParameterHandleValue(handle: MaterialParameters_Handle, newValue: MaterialParameters_Value): void
Swift declaration
mutating func setParameter(handle: MaterialParameters.Handle, value newValue: MaterialParameters.Value) throws
init · iOS 18.0+

init

TypeScript
static initMaterialXLabelData(materialXLabel: string, data: ArrayBuffer): Promise<ShaderGraphMaterial>
Swift declaration
init(materialXLabel: String, data: Data) async throws

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 · iOS 18.0+

parameterNames

TypeScript
get parameterNames(): Array<string>
Swift declaration
var parameterNames: [String] { get }
static · iOS 18.0+

parameterHandle

TypeScript
static parameterHandle(name: string): MaterialParameters_Handle
Swift declaration
static func parameterHandle(name: String) -> MaterialParameters.Handle
get · iOS 18.0+

triangleFillMode

TypeScript
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 · iOS 18.0+

init

TypeScript
static initNamedFromIn(name: string, file: string, bundle?: (_Foundation_Bundle) | null): Promise<ShaderGraphMaterial>
Swift declaration
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 · iOS 18.0+

init

TypeScript
static initNamedFrom(name: string, url: string): Promise<ShaderGraphMaterial>
Swift declaration
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 · iOS 18.0+

init

TypeScript
static initNamedFrom14551(name: string, data: ArrayBuffer): Promise<ShaderGraphMaterial>
Swift declaration
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)

init · iOS 27.0+

init

TypeScript
static initProgram(program: ShaderGraphMaterial_Program): ShaderGraphMaterial
Swift declaration
init(program: ShaderGraphMaterial.Program)

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 }

Skipped declarations

No declarations were skipped in this snapshot.

All RealityFoundation types →