<!--
{
  "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/Metallic-swift.struct/init(scale:texture:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "RealityKit"
    ],
    "preciseIdentifier" : "s:17RealityFoundation14CustomMaterialV8MetallicV5scale7textureAESf_AC0cD7TextureVSgtcfc"
  },
  "title" : "init(scale:texture:)"
}
-->

# init(scale:texture:)

Creates an object from a color or texture.

```
init(scale: Float = 1.0, texture: CustomMaterial.Texture? = nil)
```

## Parameters

`scale`

The reflectiveness value.

`texture`

An optional image texture.

## Discussion

In physically based rendering, the `metallic` property represents
the reflectiveness of an entity. This initializer creates a new
object that passes a single scale value, a texture, or both to the
material’s shader functions.

The following code demonstrates creating a roughness object using
this initializer:

```swift
if let metallicResource = try? TextureResource.load(named:
"metallic_roughness") {
    let metallic = MaterialParameters.Texture(metallicResource)
    customMaterial.roughness = .init(scale: 0.5, texture: metallic)
}
```

With custom materials, the `texture` and `scale` properties you set
on this property are available in your surface shader function, but
RealityKit doesn’t automatically use them to render your entity.
To render an entity with reflectiveness, set
[`lightingModel`](/documentation/RealityKit/CustomMaterial/lightingModel-swift.property) to
[`CustomMaterial.LightingModel.lit`](/documentation/RealityKit/CustomMaterial/LightingModel-swift.enum/lit) or
[`CustomMaterial.LightingModel.clearcoat`](/documentation/RealityKit/CustomMaterial/LightingModel-swift.enum/clearcoat),
and call `params.surface().set_metallic()`
from its surface shader.

To achieve the same metallic behavior as
[`PhysicallyBasedMaterial`](/documentation/RealityKit/PhysicallyBasedMaterial), the surface shader function multiplies
the metallic scale by the sampled value from the roughness texture,
as the following Metal code demonstrates:

```other
    // Retrieve the metallic scale from the CustomMaterial.
    float metallicScale = params.material_constants().metallic_scale();

    // Retrieve the entity's UV texture coordinates.
    float2 uv = params.geometry().uv0();

    // Models loaded from USDZ or Reality Composer use UVs that are flipped
    // on the y-axis. This compensates for that.
    uv.y = 1.0 - uv.y;

    // Sample the texture based on the resulting UVs.
    auto tex = params.textures();
    half metallic = tex.metallic().sample(textureSampler, uv).r;

    // Multiply the scale and the sampled value from the texture, and assign
    // the result to the shader's metallic property.
    metallic *= metallicScale;
    params.surface().set_metallic(metallic);
```

For more information on creating custom materials and writing shader
functions, see
[Modifying RealityKit rendering using custom materials](/documentation/RealityKit/modifying-realitykit-rendering-using-custom-materials).

---

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)