An object that defines the degree to which an entity’s clear, shiny
coating scatters light to create soft highlights.
An entity in RealityKit can display a clearcoat, which is a separate
layer of transparent specular highlights used to simulate a clear
coating, like on a car or the surface of lacquered objects. Use this
object to specify a clearcoat roughness value and indicate how much the
clearcoat scatters light that bounces off of it, which softens and
disperses the highlights.
For information, see
``CustomMaterial/clearcoatRoughness-swift.property``.
Creates a clearcoat object using a single value.
A clearcoat is a separate layer of transparent specular highlights
used to simulate a clear coating, like on a car or the surface of
lacquered objects. Use this initializer to create an object to
specify the amount of clearcoat for a material using a single value
for the entire material, a UV-mapped image to specify different
values for different parts of the entity, or both.
The values from this property are available in the custom material’s
surface shader function regardless of the value of
``CustomMaterial/lightingModel-swift.property`` , but clearcoat
isn’t drawn unless the custom material’s
``CustomMaterial/lightingModel-swift.property`` is
``CustomMaterial/LightingModel-swift.enum/clearcoat`` and the
surface shader calls `params.surface().set_clearcoat()`.
The following Metal code demonstrates how to retrieve the scale and
texture values from this property and use them to enable clearcoat
rendering.
```other
// Retrieve the clearcoat scale and roughness from the CustomMaterial.
float clearcoatScale = params.material_constants().clearcoat_scale();
float clearcoatRoughnessScale = params.material_constants().clearcoat_roughness_scale();
// Assign the clearcoat scale to enable clearcoat rendering (if
// lightingModel is .clearcoat).
params.surface().set_clearcoat(clearcoatScale);
// Assign the clearcoat roughness from the scale property set
// on the custom material.
params.surface().set_clearcoat_roughness(clearcoatRoughnessScale);
```
- Parameters:
- value: The clearcoat value to use for the entity.
Creates a clearcoat object using a single value or a texture.
A clearcoat is a separate layer of transparent specular highlights
used to simulate a clear coating, like on a car or the surface of
lacquered objects. Use this initializer to create an object to
specify the amount of clearcoat for a material using a single value
for the entire material, a UV-mapped image to specify different
values for different parts of the entity, or both.
The values from this property are available in the custom material’s
surface shader function regardless of the value of
``CustomMaterial/lightingModel-swift.property`` , but clearcoat
isn’t drawn unless the custom material’s
``CustomMaterial/lightingModel-swift.property`` is
``CustomMaterial/LightingModel-swift.enum/clearcoat`` and the
surface shader calls `params.surface().set_clearcoat()`.
The following Metal code demonstrates retrieving `scale` and
`texture` in a surface shader, and using them to specify the
clearcoat and clearcoat roughness values:
```swift
// Retrieve the clearcoat scale and roughness from the CustomMaterial.
float clearcoatScale = params.material_constants().clearcoat_scale();
float clearcoatRoughnessScale = params.material_constants().clearcoat_roughness_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 a value from the clearcoat and clearcoat roughness textures.
auto tex = params.textures();
half clearcoat = tex.clearcoat().sample(textureSampler, uv).r;
half clearcoatRoughess = tex.clearcoat_roughness().sample(textureSampler, uv).r;
// Multiply the scale and sampled texture value from the clearcoat
// and assign the result.
clearcoat *= clearcoatScale;
params.surface().set_clearcoat(clearcoat);
// Multiply the scale and sampled texture value from the clearcoat roughness
// and assign the result.
clearcoatRoughess *= clearcoatRoughnessScale;
params.surface().set_clearcoat_roughness(clearcoatRoughess);
```
- Parameters:
- scale: The clearcoat value for the entire material.
- texture: The clearcoat values as the texture of a UV-mapped image.
get · iOS 15.0+
scale
TypeScript
get scale(): number
Swift declaration
var scale: Float
The clearcoat intensity specified as a single value.
set · iOS 15.0+
scale
TypeScript
set scale(value: number)
Swift declaration
var scale: Float
The clearcoat intensity specified as a single value.
get · iOS 15.0+
texture
TypeScript
get texture(): (CustomMaterial_CustomMaterialTexture) | null
Swift declaration
var texture: CustomMaterial.Texture?
The clearcoat intensity specified using a UV-mapped image.
set · iOS 15.0+
texture
TypeScript
set texture(value: (CustomMaterial_CustomMaterialTexture) | null)
Swift declaration
var texture: CustomMaterial.Texture?
The clearcoat intensity specified using a UV-mapped image.
Creates a custom clearcoat object from a physically based material’s
clearcoat property.
This initializer creates a new object by copying the
``PhysicallyBasedMaterial/ClearcoatRoughness-swift.struct/scale``
and
``PhysicallyBasedMaterial/ClearcoatRoughness-swift.struct/texture``
values from an existing
``PhysicallyBasedMaterial/ClearcoatRoughness-swift.struct`` object.
A clearcoat is a separate layer of transparent specular highlights
used to simulate a clear coating, like on a car or the surface of
lacquered objects. Use this initializer to create an object to
specify the amount of clearcoat for a material using a single value
for the entire material, a UV-mapped image to specify different
values for different parts of the entity, or both.
The values from this property are available in the custom material’s
surface shader function regardless of the value of
``CustomMaterial/lightingModel-swift.property`` , but clearcoat
isn’t drawn unless the custom material’s
``CustomMaterial/lightingModel-swift.property`` is
``CustomMaterial/LightingModel-swift.enum/clearcoat`` and the
surface shader calls `params.surface().set_clearcoat()`.
The following Metal code demonstrates how to retrieve `scale` and
`texture` in a surface shader, and use them to specify the clearcoat
and clearcoat roughness values:
```swift
// Retrieve the clearcoat scale and roughness from the CustomMaterial.
float clearcoatScale = params.material_constants().clearcoat_scale();
float clearcoatRoughnessScale = params.material_constants().clearcoat_roughness_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 a value from the clearcoat and clearcoat roughness textures.
auto tex = params.textures();
half clearcoat = tex.clearcoat().sample(textureSampler, uv).r;
half clearcoatRoughess = tex.clearcoat_roughness().sample(textureSampler, uv).r;
// Multiply the scale and sampled texture value from the clearcoat,
// and assign the result.
clearcoat *= clearcoatScale;
params.surface().set_clearcoat(clearcoat);
// Multiply the scale and sampled texture value from the clearcoat roughness,
// and assign the result.
clearcoatRoughess *= clearcoatRoughnessScale;
params.surface().set_clearcoat_roughness(clearcoatRoughess);
```
- Parameters:
- value: The
``PhysicallyBasedMaterial/clearcoatRoughness-swift.property``
property from a ``PhysicallyBasedMaterial``.