# Runtime Color Sampler (Prefab & Class)

The **Runtime Color Sampler** prefab located at `Assets/InfinityPBR - Magic Pig Games/Runtime Color Sampler/Prefabs`

This is most usually brought into your scene as a child of the "Player" object, though you can put it anywhere you'd like to have the color sampled.

This object has the `RuntimeColor` component on it, and two children: [**Sample Sphere**](https://infinitypbr.gitbook.io/infinity-pbr/other/runtime-color-sampler/runtime-color-sampler-prefab-and-class/sampler-sphere) and the [**Sampler Camera**](https://infinitypbr.gitbook.io/infinity-pbr/other/runtime-color-sampler/runtime-color-sampler-prefab-and-class/sampler-camera). The sphere is very small with a default white material. The camera captures the lighting conditions at the position of the sphere.

## Required Fields

<figure><img src="https://2431624982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MY3N_li2jPq7az6mYfq%2Fuploads%2F6JQee1wknQGFk3jnftIf%2FScreenshot%202023-11-08%20at%205.45.02%20PM.png?alt=media&#x26;token=10f9cd72-6ba1-40db-93d7-7023ecb60a2c" alt=""><figcaption></figcaption></figure>

The **Average Color Shader** is not used on a material, but is used during the calculations to find the average color at the position of the Sample Sphere. If it is not populated, you'll find it at `Assets/InfinityPBR - Magic Pig Games/Runtime Color Sampler/Shaders/AverageColor.shader`

The Sample Camera, which should also be populated for you, is a child of the Runtime Color Sampler object.

The Prefabs folder contains the **Light Sampler Render Texture**, which is the `RenderTexture` the Sampler Camera writes to.

## Runtime Color Settings

<figure><img src="https://2431624982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MY3N_li2jPq7az6mYfq%2Fuploads%2F8mFBHsrClUeUKvxwVS9s%2FScreenshot%202023-11-08%20at%205.48.23%20PM.png?alt=media&#x26;token=59e7ad33-7802-4776-b527-9e87d680b0da" alt=""><figcaption></figcaption></figure>

If you alread have [**Runtime Color Settings**](https://infinitypbr.gitbook.io/infinity-pbr/other/runtime-color-sampler/runtime-color-settings) objects, you will see them populated in the Inspector. If you've installed the Demo folder, then you will see the Runtime Color Settings objects for the demo here.

These are Scriptable Objects. Each one has settings to process the average color into a final color which can be passed to objects in your scene through a [**Runtime Listener**](https://infinitypbr.gitbook.io/infinity-pbr/other/runtime-color-sampler/runtime-listener) component, attached to those objects.

You can create a new Runtime Color Settings object here as well -- type in a new unique name and click the "Add" button. The new object will be saved in the same location as the first object in the list, or in a new location if no settings objects exist yet.

### Settings Options

<figure><img src="https://2431624982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MY3N_li2jPq7az6mYfq%2Fuploads%2FD57Tghuw467FWSS2GBRv%2FScreenshot%202023-11-08%20at%205.51.25%20PM.png?alt=media&#x26;token=a6fc7b30-6423-4ec5-8fac-fba781c77ac6" alt=""><figcaption></figcaption></figure>

1️⃣ The "Arrow in a Circle" icon will ping the Scriptable Object in your scene. You can edit these settings on that object itself, but it may be easier to use the Inspector for the Runtime Color Sampler.

2️⃣ The checkmark will enable and disable the entire Settings object. When disabled, it will not process, and any object listening to it will not update.

3️⃣ The "Relative" option determines how the RGB values are clamped when they're outside of the min/max range. When true, one of the three values (R, G, or B) will be set to the minimum or maximum value for this Settings object. The other two values will be brought up or down proportionally.&#x20;

This helps keep saturation and hue, but it can also lead to saturated colors that are darker or lighter than you may wish.

When false, all three values (R, G, and B) will be brought to the minimum or maximum value, resulting in a grey image. In some cases, this outcome is desirable. In others, it may not be. Test out your settings in your project, and choose what works best for you.

&#x20;4️⃣ "Saturation", or "Sat." in the Inspector, is a value from 0-1, with 1 being fully saturated, and 0 being fully desaturated. This can remove all or some of the color from the average color sample.

5️⃣ The Min/Max colors are the clamp range for each Settings object. Note that the minimum or maximum value of each will be used, not the color itself. Therefor it's best to keep them as grey values, with R, G, and B all being equal.

6️⃣ The Override Min/Max values allow you to override the normal Min and Max values at runtime. This will affect all objects listening to the Runtime Color Settings being overridden. Generally this would be used at runtime, but you can enable these and set their values, and they can be active by default in your project, if you so choose.

7️⃣ The output color box is active at runtime and will display the output color of that Settings object. During runtime the input average color sampled from the Sample Sphere is also displayed, along with the R G B `float` values. This is here for convenience and debugging.

## Greyscale Settings

<figure><img src="https://2431624982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MY3N_li2jPq7az6mYfq%2Fuploads%2FxEWkwJpuno9D5pE4y6Yp%2FScreenshot%202023-11-08%20at%206.01.31%20PM.png?alt=media&#x26;token=b2ba2e19-1d87-416c-83bb-7c021a27963c" alt=""><figcaption></figcaption></figure>

When the **Saturation** value is not set to 1, the final value will be desaturated. The human eye handles colors in different ways, so these values are utilized in the desaturation algorithm. You can modify them to get the result you'd like for your project.
