<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "tvOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "RealityKit",
  "identifier" : "/documentation/RealityKit/CustomMaterial/custom-swift.property",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "RealityKit"
    ],
    "preciseIdentifier" : "s:17RealityFoundation14CustomMaterialV6customAC0C0Vvp"
  },
  "title" : "custom"
}
-->

# custom

User-defined properties for the material’s shader functions.

```
var custom: CustomMaterial.Custom { get set }
```

## Discussion

Use a [`CustomMaterial.Custom`](/documentation/RealityKit/CustomMaterial/Custom-swift.struct) object to send custom data
to your shader functions. A custom object can hold a texture or a vector
value, or both. Both the texture and vector value are available in your
shader functions.

> Note: Unlike other ``doc://com.apple.RealityKit/documentation/RealityKit/CustomMaterial`` properties, you don’t need to
> create a ``doc://com.apple.RealityKit/documentation/RealityKit/CustomMaterial/Custom-swift.struct`` object for your
> material. All ``doc://com.apple.RealityKit/documentation/RealityKit/CustomMaterial`` objects have one by default; you just
> need to set the ``doc://com.apple.RealityKit/documentation/RealityKit/CustomMaterial/Custom-swift.struct/value`` property,
> ``doc://com.apple.RealityKit/documentation/RealityKit/CustomMaterial/Custom-swift.struct/texture`` property, or both.

The following code demonstrates how to use the custom property to pass a
vector to your shader functions:

```swift
// Specify a custom vector to pass to the shader functions.
customMaterial.custom.value = [0.25, 0.25, 0.25, 1.0]
```

You can also use it to pass up to four scalar values instead of a
vector:

```swift
let customValue1: Float = 0.25
let customValue2: Float = 0.75
customMaterial.custom.value[0] = customValue1
customMaterial.custom.value[1] = customValue2
```

The custom property can also include a texture. The following code
demonstrates how to add a texture to the custom property:

```swift
if let theResource = try? TextureResource.load(named: "MyCustomTexture") {
    let myTexture = CustomMaterial.Texture(theResource)
    customMaterial.custom.texture = .init(myTexture)
}
```

The following Metal code shows how to retrieve the custom vector in a
shader function:

```cpp
float4 myCustomVector = params.uniforms().custom_parameter();
```

The following Metal code shows how to retrieve individual values from
the custom vector in your shader functions:

```cpp
float firstCustomValue = params.uniforms().custom_parameter()[0];
float secondCustomValue = params.uniforms().custom_parameter()[1];
```

Here’s how to retrieve the custom texture in your shader functions:

```cpp
float voronoiColor = params.textures()
    .custom().sample(textureSampler, UV).r;
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)