> For the complete documentation index, see [llms.txt](https://morningheartgames.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://morningheartgames.gitbook.io/docs/asyncautoexposure/runtime-usage/mask-and-alpha-workflows.md).

# Mask And Alpha Workflows

## Mask-Based Exposure

Use `ProcessTextureWithMask()` when only part of the image should affect exposure.

This is useful when:

* A person is standing in front of a bright window
* The subject should be exposed correctly but the background should be ignored
* A segmentation mask is available
* A chroma-key or custom mask texture defines the foreground

```csharp
RenderTexture result = autoExposure.ProcessTextureWithMask(inputTexture, maskTexture);
```

## Mask Rules

* White pixels are included in brightness analysis
* Black pixels are ignored
* Mask values above the internal threshold are included
* Mask values at or below the threshold are ignored
* The current implementation treats the mask as included/excluded, not as weighted partial coverage

The internal threshold is `10` on the `0` to `255` readback scale. In normalized terms, that is roughly `0.04`.

If no mask pixels pass the threshold, the plugin keeps the previous exposure target.

## Where Masks Come From

Common mask sources include:

* Person segmentation from AR or vision systems
* Chroma-key output
* Manually authored grayscale textures
* UI alpha masks
* RenderTextures generated by a custom shader

The mask does not crop the final image. It only changes which pixels are measured.

## Alpha-Aware UI Processing

`AutoExposureRawImage` and `AutoExposureImage` can account for alpha.

When `Consider Alpha Channel` is enabled:

* Opaque pixels drive the brightness calculation
* Transparent pixels are ignored
* This prevents invisible borders from affecting exposure

### RawImage Alpha

`AutoExposureRawImage` extracts alpha with the bundled shader:

```
Assets/AsyncAutoExposure/Runtime/Resources/Shaders/AlphaExtract.shader
```

Supported source formats:

* `Texture2D`: `ARGB32`, `RGBA32`, `BGRA32`
* `RenderTexture`: `ARGB32`, `BGRA32`

If the texture format does not expose alpha in one of those formats, the component falls back to standard full-frame metering.

### Image Alpha

`AutoExposureImage` extracts sprite alpha through `Texture2D.GetPixels()`. For alpha-aware sprite metering, the sprite texture must be readable in Unity import settings.

If a sprite texture is not readable, either enable Read/Write on that texture or disable `Consider Alpha Channel`.

## Recommended Mask Workflow

For live subject workflows:

1. Generate or provide a subject mask.
2. Pass the source texture and mask to `ProcessTextureWithMask()`.
3. Display the returned `RenderTexture`.
4. Tune `targetBrightness`, `minExposure`, and `maxExposure`.

```csharp
RenderTexture corrected = autoExposure.ProcessTextureWithMask(source, subjectMask);
display.texture = corrected;
```

## Tuning Tips

| Problem                                              | Adjustment                                |
| ---------------------------------------------------- | ----------------------------------------- |
| Subject is still too dark                            | Raise `targetBrightness` or `maxExposure` |
| Subject is blown out                                 | Lower `targetBrightness` or `maxExposure` |
| Background changes cause flicker                     | Use a tighter foreground mask             |
| Transparent UI padding affects exposure              | Enable `Consider Alpha Channel`           |
| Static sprite does not refresh after settings change | Call `ForceUpdate()`                      |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://morningheartgames.gitbook.io/docs/asyncautoexposure/runtime-usage/mask-and-alpha-workflows.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
