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

# init(_:)

Creates an object from a physically based material’s specular
property.

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

## Parameters

`value`

The [`specular`](/documentation/RealityKit/PhysicallyBasedMaterial/specular-swift.property)
property from a [`PhysicallyBasedMaterial`](/documentation/RealityKit/PhysicallyBasedMaterial).

## Discussion

This initializer creates an object by copying the values from an
existing [`PhysicallyBasedMaterial.Specular`](/documentation/RealityKit/PhysicallyBasedMaterial/Specular-swift.struct) object.

RealityKit automatically draws *specular highlights* for physically
based materials using the values of various properties, primarily
[`roughness`](/documentation/RealityKit/PhysicallyBasedMaterial/roughness-swift.property) and
[`metallic`](/documentation/RealityKit/PhysicallyBasedMaterial/metallic-swift.property). Specular
highlights are bright spots of reflected light that appear on shiny
objects.

![An illustration showing a sphere and a cube with rounded corners.](images/com.apple.RealityKit/CustomMaterial-Specular-swift-struct-init(_:)-1@2x.png)

While many real-world objects can be accurately and realistically
simulated with just the core physically based rendering (PBR)
properties, you can create additional realistic effects by
augmenting the specular highlights.

The specular [`scale`](/documentation/RealityKit/CustomMaterial/Specular-swift.struct/scale) and
[`texture`](/documentation/RealityKit/CustomMaterial/Specular-swift.struct/texture) values are
available to the material’s surface shader, but RealityKit doesn’t
add specular highlights unless the surface shader function calls
`params.surface().set_specular()`.

The following Metal code demonstrates using the specular `scale` and
`texture` values in a surface shader function to calculate
additional specular highlights, emulating the behavior of
[`PhysicallyBasedMaterial`](/documentation/RealityKit/PhysicallyBasedMaterial):

```other
    // Retrieve the opacity scale from the CustomMaterial.
    float specularScale = params.material_constants().specular_scale();

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

    // Entities loaded from a USDZ or .reality file use texture coordinates
    // with a flipped y-axis. This compensates for that.
    uv.y = 1.0 - uv.y;

    // Sample the specular texture.
    auto tex = params.textures();
    half specular = tex.specular().sample(textureSampler, uv).r;

    // Multiply the tint and the sampled value from the texture, and
    // assign the result.
    specular *= specularScale;
    params.surface().set_specular(specular);
```

---

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)