> 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/introduction/getting-started.md).

# Getting Started

## 1. Confirm The Package Is Present

The runtime files should be under:

```
Assets/AsyncAutoExposure/Runtime/
```

The default shader must remain inside a `Resources` folder so it can be loaded automatically:

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

If you move the shader, assign it manually in the `AsyncAutoExposure` Inspector field.

## 2. Pick A Workflow

| Source type                                                                     | Recommended workflow                                    |
| ------------------------------------------------------------------------------- | ------------------------------------------------------- |
| Any `Texture`, `WebCamTexture`, `RenderTexture`, or `VideoPlayer.targetTexture` | Use `AsyncAutoExposure` from code                       |
| Unity UI `RawImage`                                                             | Add `AutoExposureRawImage`                              |
| Unity UI `Image` with a sprite                                                  | Add `AutoExposureImage` and assign an output `RawImage` |
| Foreground-only or subject-only metering                                        | Use `ProcessTextureWithMask()`                          |

## Script Workflow

Use `AsyncAutoExposure` when you want to process a texture through code.

```csharp
using AsyncAutoExposure;
using UnityEngine;
using UnityEngine.UI;

public class WebcamDisplay : MonoBehaviour
{
    [SerializeField] RawImage display;

    WebCamTexture webcam;
    AsyncAutoExposure autoExposure;

    void Start()
    {
        webcam = new WebCamTexture();
        webcam.Play();

        autoExposure = gameObject.AddComponent<AsyncAutoExposure>();
        autoExposure.targetBrightness = 0.4f;
        autoExposure.adjustmentSpeed = 4f;
    }

    void Update()
    {
        if (webcam == null || !webcam.didUpdateThisFrame)
            return;

        RenderTexture corrected = autoExposure.ProcessTexture(webcam);
        if (corrected != null)
            display.texture = corrected;
    }
}
```

Call `ProcessTexture()` every frame for live content. The returned `RenderTexture` is owned by the component and is reused until the input size changes.

## UI Component Workflow

For UI elements, use the included components.

### RawImage

Add `AutoExposureRawImage` to a GameObject with a `RawImage`.

```csharp
rawImage.gameObject.AddComponent<AutoExposureRawImage>();
```

Set `Continuous Update` to `true` when the texture changes every frame, such as webcam or video content. Leave it disabled for static textures so the component processes once and then stays idle.

### Image

Add `AutoExposureImage` to a GameObject with a Unity UI `Image`.

```csharp
var component = image.gameObject.AddComponent<AutoExposureImage>();
component.outputRawImage = correctedOutput;
```

`AutoExposureImage` displays the processed result through a `RawImage`. Assign `Output Raw Image` in the Inspector, or place a `RawImage` on the same GameObject for the component to find.

## Mask Workflow

Use a mask when only part of the image should drive exposure.

```csharp
RenderTexture corrected = autoExposure.ProcessTextureWithMask(sourceTexture, maskTexture);
display.texture = corrected;
```

White mask pixels are included in brightness measurement. Black mask pixels are ignored.

## Recommended First Settings

Use these values as a practical starting point:

* `targetBrightness`: `0.4`
* `adjustmentSpeed`: `4`
* `minExposure`: `0.5`
* `maxExposure`: `3.0`
* `downsampleFactor`: `4` on desktop, `8` on mobile
* `readbackFrameSkip`: `2`

For darker subject-focused scenes, try `targetBrightness = 0.5` and `maxExposure = 5`. For already-bright sources, try `targetBrightness = 0.3`.

## 3. Try The Samples

Open the scenes in:

```
Assets/AsyncAutoExposure/Samples/Scenes/
```

Start with `01_BasicWebcam.unity`, then use `02_Advanced.unity` to tune parameters while watching live brightness and exposure values.


---

# 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/introduction/getting-started.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.
