One Logo Pool Ball
RealityFoundation · IOS API REFERENCE

CustomMaterial.AmbientOcclusion

struct · iOS 15.0+ · SDK 27.1

struct AmbientOcclusion

An object that defines an entity’s exposure to ambient light.

Members (4)

get · iOS 15.0+

texture

TypeScript
get texture(): (CustomMaterial_CustomMaterialTexture) | null
Swift declaration
var texture: CustomMaterial.Texture?

The entity’s exposure to ambient light 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 entity’s exposure to ambient light specified using a UV-mapped image.

init · iOS 15.0+

init

TypeScript
static initTexture(texture?: (CustomMaterial_CustomMaterialTexture) | null): CustomMaterial_AmbientOcclusion
Swift declaration
init(texture: CustomMaterial.Texture? = nil)

Creates an object from an image texture. Ambient occlusion represents the entity’s exposure to ambient light. This function creates a new ambient occlusion object from a UV-mapped image texture. Specify ambient occlusion by using a UV-mapped image called an _ambient occlusion map_. A value of black (`0.0`) represents parts of the model that receive less ambient light because that part of the model is a crevice, dent, or recessed area, or because another part of the same entity is preventing ambient light from reaching it. Ambient occlusion values of white (`1.0`) represent flat portions of the model that receive full ambient light. You generate ambient occlusion maps by using a 3D software package. The ambient occlusion texture is available in the material’s surface shader, but RealityKit doesn’t render ambient occlusion unless the surface shader calls `params.surface().set_ambient_occlusion()`. The following Metal code shows how to use the ambient occlusion texture in a surface shader function: ```swift // Retrieve the entity's texture coordinates. float2 uv = params.geometry().uv0(); // Entities loaded from USDZ or .reality files have texture coordinates // with a flipped y-axis. This adjusts for that. uv.y = 1.0 - uv.y; // Sample the ambient occlusion texture and use it to set the // ambient occlusion value to use during rendering. auto tex = params.textures(); half metallic = tex.ambient_occlusion().sample(textureSampler, uv).r; params.surface().set_ambient_occlusion(metallic); ``` - Parameters: - texture: A UV-mapped image texture that defines the entity’s exposure to ambient light.

init · iOS 15.0+

init

TypeScript
static init(value: PhysicallyBasedMaterial_AmbientOcclusion): CustomMaterial_AmbientOcclusion
Swift declaration
init(_ value: PhysicallyBasedMaterial.AmbientOcclusion)

Creates an object from a physically based material’s ambient occlusion property. Ambient occlusion represents the entity’s exposure to ambient light. This initializer creates a new object by copying the values from an existing ``PhysicallyBasedMaterial`` instance’s ``PhysicallyBasedMaterial/ambientOcclusion-swift.property`` property. Specify ambient occlusion by using a UV-mapped image called an _ambient occlusion map_. A value of black (`0.0`) represents parts of the model that receive less ambient light because of a crevice, dent, recessed area, or another part of the same entity blocking ambient light from reaching it. Ambient occlusion values of white (`1.0`) represent flat portions of the model that receive full ambient light. You generate ambient occlusion maps by using a 3D software package. The ambient occlusion texture is available in the material’s surface shader, but RealityKit doesn’t render ambient occlusion unless the surface shader calls `params.surface().set_ambient_occlusion()`. The following Metal code shows how to use the ambient occlusion texture in a surface shader function: ```swift // Retrieve the entity's texture coordinates. float2 uv = params.geometry().uv0(); // Entities loaded from USDZ or .reality files have texture coordinates // with a flipped y-axis. This adjusts for that. uv.y = 1.0 - uv.y; // Sample the ambient occlusion texture and use it to set the // ambient occlusion value to use during rendering. auto tex = params.textures(); half metallic = tex.ambient_occlusion().sample(textureSampler, uv).r; params.surface().set_ambient_occlusion(metallic); ``` - Parameters: - value: The ambient occlusion property from a ``PhysicallyBasedMaterial``.

Skipped declarations

No declarations were skipped in this snapshot.

All RealityFoundation types →