# Shader Integration

**DRM** can be integrated into **Shader Graph**, [**Amplify Shader Editor**](https://assetstore.unity.com/packages/tools/visual-scripting/amplify-shader-editor-68570?aid=1011lvgVb) and hand-written HSLS files:

{% tabs %}
{% tab title=" Shader Graph" %}
Choose required DRM settings inside DRM editor window and then click on the <img src="https://1494537888-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVDsGRBXgFisq0hO6tTXv%2Fuploads%2FsUDUkiD5QJrFEnXXATge%2F33.png?alt=media&#x26;token=bdee03f9-f398-4d67-b6f5-7b05275878d1" alt="" data-size="line"> **Shader Graph** button:

<figure><img src="https://1494537888-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVDsGRBXgFisq0hO6tTXv%2Fuploads%2Fvml7Fc5LwosFHlfy3H0r%2F1.png?alt=media&#x26;token=da9baba1-7f6c-4eed-9016-51e7de645c76" alt="" width="344"><figcaption></figcaption></figure>

DRM node file will be generated and highlighted inside **Project** window. Drag and drop it inside **Shader Graph**:

<figure><img src="https://1494537888-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVDsGRBXgFisq0hO6tTXv%2Fuploads%2FdibuNMzNrk6cyrR6Sja8%2F2.png?alt=media&#x26;token=7124bee9-e605-49c9-81f7-d20affce58d9" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="https://1494537888-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVDsGRBXgFisq0hO6tTXv%2Fuploads%2FzxDsbaVuZWQxvkTvdYrL%2F3.png?alt=media&#x26;token=bbc3786c-6d38-450b-96db-977cb95aff65" alt=""><figcaption></figcaption></figure>

Node has two inputs:&#x20;

* **World Position** - This is vertex's absolute world position and by default it is already assigned.
* **Noise** - Available only with **Advanced** DRM nodes and allows adding noise to the calculated mask. Noise strength is controlled from the **DRM Game Object** or **DRM Live Object** scripts.

Output value is a calculated mask - *<mark style="color:blue;">float</mark>* type.&#x20;

{% hint style="info" %}
Note, in the case of **Additive** DRM node, generated mask value can be in the range of \[-∞, +∞].

With **Normalize** blend mode output value always is in the range of \[0, 1].
{% endhint %}

Inside **Shader Graph** can be used any number of DRM nodes, each one with its own settings.&#x20;

Each individual DRM node must be updated with its own **DRM Controller** script.

If inside shader several identical DRM nodes are required but each one for different purpose, differentiate them by **ID** property.&#x20;
{% endtab %}

{% tab title="Amplify Shader Editor" %}
Choose required DRM settings inside DRM editor window and then click on the <img src="https://1494537888-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVDsGRBXgFisq0hO6tTXv%2Fuploads%2FqiHKS3mobdB8mWdHIwSB%2F35.png?alt=media&#x26;token=dcbbe719-19fa-4f0f-b067-218a45c35d03" alt="" data-size="line"> **Amplify Shader** button:

<figure><img src="https://1494537888-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVDsGRBXgFisq0hO6tTXv%2Fuploads%2Fvml7Fc5LwosFHlfy3H0r%2F1.png?alt=media&#x26;token=da9baba1-7f6c-4eed-9016-51e7de645c76" alt="" width="344"><figcaption></figcaption></figure>

DRM node file will be generated and highlighted inside **Project** window. Drag and drop it inside **Amplify Shader Editor**:

<figure><img src="https://1494537888-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVDsGRBXgFisq0hO6tTXv%2Fuploads%2Fj3t2xls2FwOFQrCbVpIK%2F36.png?alt=media&#x26;token=721b736b-80fb-499d-9af3-cefa358cd700" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="https://1494537888-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVDsGRBXgFisq0hO6tTXv%2Fuploads%2FURDlNzTXbIdTgURSUFLU%2F37.png?alt=media&#x26;token=256cacfc-37c5-4d89-b293-ef82a7eee6fc" alt=""><figcaption></figcaption></figure>

Node has two inputs:&#x20;

* **World Position** - This is vertex's absolute world position and by default it is already assigned.
* **Noise** - Available only with **Advanced** DRM nodes and allows adding noise to the calculated mask. Noise strength is controlled from the **DRM Game Object** or **DRM Live Object** scripts.

Output value is a calculated mask - *<mark style="color:blue;">float</mark>* type.&#x20;

{% hint style="info" %}
Note, in the case of **Additive** DRM node, generated mask value can be in the range of \[-∞, +∞].

With **Normalize** blend mode output value always is in the range of \[0, 1].
{% endhint %}

Inside ASE can be used any number of DRM nodes, each one with its own settings.&#x20;

Each individual DRM node must be updated with its own **DRM Controller** script.

If inside shader several identical DRM nodes are required but each one for different purpose, differentiate them by **ID** property.&#x20;
{% endtab %}

{% tab title="Hand-written HLSL" %}
Choose required DRM settings inside DRM editor window and then click on the <img src="https://1494537888-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVDsGRBXgFisq0hO6tTXv%2Fuploads%2FpKzR12fLd8cblvFNlc6L%2F34.png?alt=media&#x26;token=6a26c269-3ee0-4471-872d-c747752f83d5" alt="" data-size="line"> **cginc** button:

<figure><img src="https://1494537888-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVDsGRBXgFisq0hO6tTXv%2Fuploads%2Fvml7Fc5LwosFHlfy3H0r%2F1.png?alt=media&#x26;token=da9baba1-7f6c-4eed-9016-51e7de645c76" alt="" width="344"><figcaption></figcaption></figure>

CGINC file will be generated and highlighted inside **Project** window. Path to the file will be copied to the keyboard memory.

```hlsl
//Example of using DRM method inside HLSL file

Shader "Unlit"
{
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 100

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag

            #include "UnityCG.cginc"

            #include "Assets/Amazing Assets/Dynamic Radial Masks/Shaders/CGINC/HeightField/DynamicRadialMasks_HeightField_1_Advanced_Additive_ID1_Local.cginc"

            struct v2f
            {
                float4 vertex : SV_POSITION;
                float3 worldPos : TEXCOORD0;
            };

            v2f vert (float4 vertex : POSITION)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(vertex);
                o.worldPos = mul(unity_ObjectToWorld, vertex).xyz;
                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
                float mask = DynamicRadialMasks_HeightField_1_Advanced_Additive_ID1_Local(i.worldPos, 0);

                return mask;
            }
            ENDCG
        }
    }
}
```

{% hint style="info" %}
Pay attention, DRM ***cginc*** file's name and DRM method's name are identical.
{% endhint %}

DRM methods parameters are:

* Vertex world-space position (*<mark style="color:blue;">float3</mark>* type).
* If using **Advanced** DRM type, then the second parameter is a **Noise** value (*<mark style="color:blue;">float</mark>* type). Noise strength is controlled from the **DRM Game Object** or **DRM Live Object**.

{% hint style="info" %}
Note, in the case of **Additive** DRM node, generated mask value can be in the range of \[-∞, +∞].

With **Normalize** blend mode output value always is in the range of \[0, 1].
{% endhint %}

Inside shader can be used any number of DRM methods, each one with its own settings.&#x20;

Each individual method must be updated with its own **DRM Controller** script.

If inside shader several identical DRM nodes are required but each one for different purpose, differentiate them by **ID** property.&#x20;
{% endtab %}
{% endtabs %}
