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
that applies to the entire material.
The clearcoat value is available in the material’s surface shader
function, but RealityKit doesn’t render a clearcoat unless the
material’s ``CustomMaterial/lightingModel-swift.property`` is
``CustomMaterial/LightingModel-swift.enum/clearcoat`` and its
surface shader function calls `params.surface().set_clearcoat()`.
The following Metal code demonstrates how to retrieve the clearcoat
``CustomMaterial/Clearcoat-swift.struct/scale`` in a surface shader
function and use it to set the final clearcoat value for rendering:
```other
// Retrieve the base color tint from the CustomMaterial.
float clearcoatScale = params.material_constants().clearcoat_scale();
// Assign the scale value as the clearcoat value for this pixel.
params.surface().set_clearcoat(clearcoat);
```
- 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 copied values for
``CustomMaterial/Clearcoat-swift.struct/scale`` and
``CustomMaterial/Clearcoat-swift.struct/texture`` are available in
the material’s surface shader function, regardless of the material’s
lighting model; however RealityKit only renders a clearcoat when
``CustomMaterial/lightingModel-swift.property`` is
``CustomMaterial/LightingModel-swift.enum/clearcoat`` and the
material’s surface shader function calls
`params.surface().set_clearcoat()`.
The following Metal code demonstrates how to retrieve the clearcoat
`scale` and `texture` in a surface shader function and use them to
calculate the final clearcoat value for rendering:
```other
// Retrieve the base color tint from the CustomMaterial.
float clearcoatScale = params.material_constants().clearcoat_scale();
// Retrieve the entity's primary texture coordinates.
float2 uv = params.geometry().uv0();
// Models loaded from a USDZ of .reality file use texture coordinates
// with a flipped y-axis. This compensates for that.
uv.y = 1.0 - uv.y;
// Sample the clearcoat texture to get the value UV-mapped to this pixel.
auto tex = params.textures();
half clearcoat = tex.clearcoat().sample(textureSampler, uv).r;
// Multiply the tint and the sampled value from the texture, and assign it
// to the shader's base color property.
clearcoat *= clearcoatScale;
params.surface().set_clearcoat(clearcoat);
```
- 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 intensity of the clearcoat.
Use the scale value either to hold a uniform clearcoat value that
applies to the entire entity, or use it as a multiplier to scale the
clearcoat intensity sampled from the
``CustomMaterial/Clearcoat-swift.struct/texture`` property.
set · iOS 15.0+
scale
TypeScript
set scale(value: number)
Swift declaration
var scale: Float
The intensity of the clearcoat.
Use the scale value either to hold a uniform clearcoat value that
applies to the entire entity, or use it as a multiplier to scale the
clearcoat intensity sampled from the
``CustomMaterial/Clearcoat-swift.struct/texture`` property.
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 an object by copying the scale and texture
values from the ``PhysicallyBasedMaterial/clearcoat-swift.property``
property of a ``PhysicallyBasedMaterial``.
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 copied values for
``CustomMaterial/Clearcoat-swift.struct/scale`` and
``CustomMaterial/Clearcoat-swift.struct/texture`` are available in
the material’s surface shader function, regardless of the material’s
lighting model; however RealityKit only renders a clearcoat when
``CustomMaterial/lightingModel-swift.property`` is
``CustomMaterial/LightingModel-swift.enum/clearcoat`` and the
material’s surface shader function calls
`params.surface().set_clearcoat()`.
The following Metal code demonstrates how to retrieve the clearcoat
`scale` and `texture` values in a surface shader, and use them to
calculate the final clearcoat value for rendering:
```other
// Retrieve the base color tint from the CustomMaterial.
float clearcoatScale = params.material_constants().clearcoat_scale();
// Retrieve the entity's primary texture coordinates.
float2 uv = params.geometry().uv0();
// Models loaded from a USDZ of .reality file use texture coordinates
// with a flipped y-axis. This compensates for that.
uv.y = 1.0 - uv.y;
// Sample the clearcoat texture to get the value UV-mapped to this pixel.
auto tex = params.textures();
half clearcoat = tex.clearcoat().sample(textureSampler, uv).r;
// Multiply the tint and the sampled value from the texture, and assign it
// to the shader's base color property.
clearcoat *= clearcoatScale;
params.surface().set_clearcoat(clearcoat);
```
- Parameters:
- value: The ``PhysicallyBasedMaterial/clearcoat-swift.property``
property from a ``PhysicallyBasedMaterial``.