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

# init(floatLiteral:)

Creates an opacity object from a single value.

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

## Parameters

`value`

The opacity value.

## Discussion

This initializer creates an object that defines the opacity of an
entity using a single value for the entire entity. This value is
available to the material’s surface shader function, but RealityKit
draws the entity fully opaque unless the surface shader function
calls `params.surface().set_opacity()`.

The following Metal code demonstrates how to set the entity’s
opacity in the material’s surface shader function based on `value:`

```swift
    // Retrieve the opacity scale from the CustomMaterial.
    float opacityScale = params.material_constants().opacity_scale();

    // Use the opacity scale to set the current pixel's opacity.
    params.surface().set_opacity(opacityScale);
```

---

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)