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

# init(_:)

Creates a roughness object from a physically based material’s
roughness property.

```
init(_ value: PhysicallyBasedMaterial.Roughness)
```

## Parameters

`value`

The physically based material’s roughness property.

## Discussion

This initializer creates a roughness object by copying the scale and
texture values from an existing
[`PhysicallyBasedMaterial.Roughness`](/documentation/RealityKit/PhysicallyBasedMaterial/Roughness-swift.struct) object.

With custom materials, the `texture` and `scale` properties of the
[`CustomMaterial.Roughness`](/documentation/RealityKit/CustomMaterial/Roughness-swift.struct) object are available in
your surface shader function, but RealityKit doesn’t automatically
use them when rendering your entity.
To render an entity with roughness, 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_roughness()`
from its surface shader.

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

```swift
    // Retrieve the roughness scale from the CustomMaterial.
    float roughnessScale = params.material_constants().roughness_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 roughness = tex.roughness().sample(textureSampler, uv).r;

    // Multiply the scale and the sampled value from the texture, and assign
    // the result to the shader's base color property.
    roughness *= roughnessScale;

    // Set the roughness value to be used by the custom material shader.
    params.surface().set_roughness(roughness);
```

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)