---
title: CustomMaterial.SurfaceShader
framework: realitykit
role: symbol
role_heading: Structure
path: realitykit/custommaterial/surfaceshader
---

# CustomMaterial.SurfaceShader

The custom material’s surface shader function.

## Declaration

```swift
struct SurfaceShader
```

## Overview

Overview Custom materials work together with a surface shader function to render entities. The CustomMaterial properties related to rendering, such as baseColor and normal, are available in the surface shader function, but RealityKit doesn’t use them directly. Instead, the material’s surface shader function allows you to calculate or specify all the material parameters that RealityKit uses to render your entity, such as baseColor, normal, and roughness. RealityKit’s fragment shader calls your surface shader function once for each pixel it renders. Here’s a simple example of a surface shader that sets the entity’s base color: #include <metal_stdlib> #include <RealityKit/RealityKit.h>

// Specify the current default namespace as metal so that it's not // necessary to prefix Metal Standard Library symbols. using namespace metal;

[[visible]] void mySurfaceShader(realitykit::surface_parameters params) {     // Set the base color     params.surface().set_base_color(half3(1.0, 0.5, 0.5)); } For more information on creating custom materials and writing shader functions, see Modifying RealityKit rendering using custom materials.

## Topics

### Creating surface shader objects

- [init(named:in:)](realitykit/custommaterial/surfaceshader/init(named:in:).md)

### Accessing surface shader properties

- [name](realitykit/custommaterial/surfaceshader/name.md)
- [library](realitykit/custommaterial/surfaceshader/library.md)

### Initializers

- [init(named:in:constantValues:)](realitykit/custommaterial/surfaceshader/init(named:in:constantvalues:).md)

## Relationships

### Conforms To

- [Equatable](swift/equatable.md)
- [Escapable](swift/escapable.md)
- [Hashable](swift/hashable.md)
- [MaterialFunction](realitykit/materialfunction.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Shaders

- [Implementing adjustable material](visionos/implementing-adjustable-material-in-visionos.md)
- [Displaying a stereoscopic image](visionos/displaying-a-stereoscopic-image-in-visionos.md)
- [ShaderGraphMaterial](realitykit/shadergraphmaterial.md)
- [ShaderGraphMaterial.FaceCulling](realitykit/shadergraphmaterial/faceculling-swift.typealias.md)
- [ShaderGraphMaterial.TriangleFillMode](realitykit/shadergraphmaterial/trianglefillmode-swift.typealias.md)
- [Modifying RealityKit rendering using custom materials](realitykit/modifying-realitykit-rendering-using-custom-materials.md)
- [CustomMaterial](realitykit/custommaterial.md)
- [CustomMaterial.GeometryModifier](realitykit/custommaterial/geometrymodifier.md)
- [MaterialFunction](realitykit/materialfunction.md)
- [CustomMaterial.Program](realitykit/custommaterial/program-swift.class.md)
- [CustomMaterial.Program.Descriptor](realitykit/custommaterial/program-swift.class/descriptor-swift.struct.md)
- [CustomShaderStage](realitykit/customshaderstage.md)
