<!--
{
  "availability" : [
    "iOS: 9.0.0 -",
    "iPadOS: 9.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.11.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "ModelIO",
  "identifier" : "/documentation/ModelIO/MDLMesh/generateAmbientOcclusionTexture(withQuality:attenuationFactor:objectsToConsider:vertexAttributeNamed:materialPropertyNamed:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Model I/O",
      "ModelIO"
    ],
    "preciseIdentifier" : "c:objc(cs)MDLMesh(im)generateAmbientOcclusionTextureWithQuality:attenuationFactor:objectsToConsider:vertexAttributeNamed:materialPropertyNamed:"
  },
  "title" : "generateAmbientOcclusionTexture(withQuality:attenuationFactor:objectsToConsider:vertexAttributeNamed:materialPropertyNamed:)"
}
-->

# generateAmbientOcclusionTexture(withQuality:attenuationFactor:objectsToConsider:vertexAttributeNamed:materialPropertyNamed:)

Calculates ambient occlusion (AO) information for the mesh and saves it in the mesh as a material property texture.

```
func generateAmbientOcclusionTexture(withQuality bakeQuality: Float, attenuationFactor: Float, objectsToConsider: [MDLObject], vertexAttributeNamed vertexAttributeName: String, materialPropertyNamed materialPropertyName: String) -> Bool
```

## Parameters

`bakeQuality`

A value between `0.0` and `1.0` that determines the fidelity and performance of AO calculation. Higher values produce more accurate output at the cost of more processing time and memory usage.

`attenuationFactor`

A value between `0.0` and `1.0` that scales the strength of the AO effect. Higher values result in higher contrast when the AO texture is used for shading.

`objectsToConsider`

An array of other objects in the scene that should affect static ambient lighting for the mesh.

`vertexAttributeName`

The name of the vertex attribute for storing generated texture coordinate data.

`materialPropertyName`

The name of the material for storing the generated texture image.

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> if AO calculation succeeded; otherwise <doc://com.apple.documentation/documentation/Swift/false>.

## Discussion

Ambient occlusion (AO) is a measure, for each point on a surface, of how much ambient light can reach that point. For example, a narrow, concave section of a mesh does not receive much ambient light compared with a wide, flat section—thus, in a realistic rendering of the mesh, the concave sections should appear darker than the flat sections. This method analyzes the mesh (and, optionally, static elements of its local environment, specified in the `objectsToConsider` parameter) to precompute (or “bake”) AO information for each point on the mesh’s surface. You can then use the resulting information in shading to produce a more realistic render.

This method saves AO data as a texture image and associates that image with the mesh through the material property specified in the `materialPropertyName` parameter. To map the texture onto the mesh’s surface, this method also generates texture coordinates and writes them in the vertex attribute specified in the `vertexAttributeName` parameter. If the mesh already contains that attribute, this method overwrites the contents of the corresponding vertex buffer. If the mesh does not contain that attribute, this method creates a new attribute and updates the mesh’s [`vertexDescriptor`](/documentation/ModelIO/MDLMesh/vertexDescriptor) object accordingly.

The `bakeQuality` parameter controls the fidelity and performance of the AO calculation process and its output using an arbitrary scale. To control quality based on raytracing parameters, use the [`generateAmbientOcclusionTexture(withSize:raysPerSample:attenuationFactor:objectsToConsider:vertexAttributeNamed:materialPropertyNamed:)`](/documentation/ModelIO/MDLMesh/generateAmbientOcclusionTexture(withSize:raysPerSample:attenuationFactor:objectsToConsider:vertexAttributeNamed:materialPropertyNamed:)) method.

---

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)