<!--
{
  "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(floatLiteral:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "RealityKit"
    ],
    "preciseIdentifier" : "s:17RealityFoundation14CustomMaterialV9RoughnessV12floatLiteralAESf_tcfc"
  },
  "title" : "init(floatLiteral:)"
}
-->

# init(floatLiteral:)

Creates an object to specify the amount of roughness, using a single
value that applies to the entire material.

```
init(floatLiteral value: Float)
```

## Parameters

`value`

The roughness value.

## Discussion

The `roughness` property represents how much the surface of the
entity scatters light that it reflects. A material with a high
roughness has a matte appearance, and one with a low roughness has a
shiny appearance.

![An illustration showing three spheres with different amounts of](images/com.apple.RealityKit/CustomMaterial-Roughness-swift-struct-init(floatLiteral:)-1@2x.png)

The following Swift code shows how to specify roughness using a
single value for the entire entity:

```swift
material.roughness = PhysicallyBasedMaterial.Roughness(floatLiteral: 0.0)
```

With custom materials, the roughness value is available in your
surface shader; however, RealityKit doesn’t use it automatically to
render the entity.
To render an entity with roughness, the material’s
[`lightingModel`](/documentation/RealityKit/CustomMaterial/lightingModel-swift.property)
needs to be
[`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 function.

The following Metal code shows how to retrieve the roughness value
set using this initializer in your surface shader:

```other
    // Retrieve the roughness scale from the CustomMaterial.
    float roughnessScale = params.material_constants().roughness_scale();

    // Set the roughness value using the roughness scale.
    params.surface().set_roughness(roughnessScale);
```

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)