# DRMController

<div align="left"><figure><img src="https://1494537888-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVDsGRBXgFisq0hO6tTXv%2Fuploads%2F8V5YlmBVghAhW9CXpIjM%2F39.png?alt=media&#x26;token=b63a9319-86a8-48a3-b355-30a98ab01ff3" alt="" width="277"><figcaption></figcaption></figure></div>

**DRM Controller** is used for updating DRM properties inside materials. Without it DRM calculated masks inside shaders will be incorrect or empty.

**DRM Controller** can update only one DRM node (or method) property inside shader and its **DRM Settings** must match the node settings.

If material uses several different DRM nodes, each one needs to be updated separately with its own **DRM Controller**.

Material requiring DRM node updating must be added to the **Materials** array. If several materials use the same DRM node and its properties needs to be the same for those materials, then a single **DRM Controller** can be used for updating all those materials.&#x20;

{% hint style="info" %}
Material to the **Materials** array can be added manually or by drag & dropping them from the **Project** window. Even entire folder can be drag & dropped here and all its materials will be added to the array.
{% endhint %}

To help selecting proper **DRM Settings**, click on the **Load** menu and select required DRM settings from local Materials array or scene materials:

<figure><img src="https://1494537888-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVDsGRBXgFisq0hO6tTXv%2Fuploads%2FEbvjxNefvXjGWIaR0MjL%2F3.gif?alt=media&#x26;token=a3bebbf9-9982-41de-9245-184f09bd383c" alt="" width="462"><figcaption></figcaption></figure>

***

**Keywords** are shader used keywords that are automatically enabled by **DRM Controller** when DRM object is added to an empty **Pool** and disabled when **Pool** becomes empty. Using keywords can greatly help in optimizing DRM usage in shaders to avoid mask calculation when it is not needed.

For example, shader below uses DRM node consisting of 128 objects that is calculated on every frame even if there are no objects in the **DRM Controller**'s Pool and node output result in this case always will be 0.&#x20;

By using keyword, can be controlled when DRM node calculation is enabled and disabled. And **DRM Controller** can handle it. It enables all provided keywords for all materials in the **Materials** array when the very first DRM object is added to the Pool and disables them when Pool becomes empty:

<figure><img src="https://1494537888-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVDsGRBXgFisq0hO6tTXv%2Fuploads%2FEPTLpB6xkSiPSVwgx5RC%2F41.png?alt=media&#x26;token=5bd6c61a-8fae-448e-a707-f1c406a6973a" alt=""><figcaption></figcaption></figure>

***

**Update Mode** - DRM properties inside materials can be updated on every [Update](https://docs.unity3d.com/ScriptReference/MonoBehaviour.Update.html), [FixedUpdate](https://docs.unity3d.com/ScriptReference/MonoBehaviour.FixedUpdate.html) or Manually.&#x20;

**Draw Gizmos** - Draws spherical gizmos of the DRM objects in the Pool inside the Scene window, demonstrating their world-space position and radius.&#x20;

**Pool** - **DRM Controller** reads DRM properties from objects of this Pool and based on them updates DRM nodes inside materials. Pool can contain:

* [**DRM Game Object**](https://amazing-assets.gitbook.io/dynamic-radial-masks/scripts-and-run-time-api/drmgameobject) - This is a scene gameObject with **DRMGameObject** script attached. After instantiated it inside editor or run-time, it needs to be manually added to the Pool.
* [**DRM Live Object**](https://amazing-assets.gitbook.io/dynamic-radial-masks/scripts-and-run-time-api/drmliveobject) - This is run-time generated DRM object with self-animatable properties. After instantiating it needs to be manually added to the Pool.&#x20;
* [**Custom**](https://amazing-assets.gitbook.io/dynamic-radial-masks/scripts-and-run-time-api/drmcontroller/updateshaderdata) - Allows users to provide their own data for updating DRM properties inside materials.

### DRMController Methods

* [UpdateShaderData](https://amazing-assets.gitbook.io/dynamic-radial-masks/scripts-and-run-time-api/drmcontroller/updateshaderdata)
* [AddObjectToPool](https://amazing-assets.gitbook.io/dynamic-radial-masks/scripts-and-run-time-api/drmcontroller/addobjecttopool)
* [RemoveObjectFromPool](https://amazing-assets.gitbook.io/dynamic-radial-masks/scripts-and-run-time-api/drmcontroller/removeobjectfrompool)
* [ClearPool](https://amazing-assets.gitbook.io/dynamic-radial-masks/scripts-and-run-time-api/drmcontroller/clearpool)
* [GetObjectsCountInPool](https://amazing-assets.gitbook.io/dynamic-radial-masks/scripts-and-run-time-api/drmcontroller/getobjectscountinpool)
* [ConvertDRMLiveObjectsToDRMGameObjects](https://amazing-assets.gitbook.io/dynamic-radial-masks/scripts-and-run-time-api/drmcontroller/convertdrmliveobjectstodrmgameobjects)
* [SetKeywordsState](https://amazing-assets.gitbook.io/dynamic-radial-masks/scripts-and-run-time-api/drmcontroller/setkeywordsstate)
* [Delegates](https://amazing-assets.gitbook.io/dynamic-radial-masks/scripts-and-run-time-api/drmcontroller/delegates)
