# Tutorial #3 - Bullet Holes

{% embed url="<https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVDsGRBXgFisq0hO6tTXv%2Fuploads%2FrZi5ON5kvQWOv6TRGlc5%2F4.mp4?alt=media&token=82f7084e-2fd3-41d0-83d6-3997530266da>" %}

In the previous tutorials we have created DMR shaders consisting of only one mask object, but DRM node can calculate a compound mask consisting of multiple objects.

{% stepper %}
{% step %}
Open DRM editor window and choose **HeightField** for shape and set **Count** to 32:

<figure><img src="https://1494537888-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVDsGRBXgFisq0hO6tTXv%2Fuploads%2FUAMkKY6s4CoAVaZlMCRY%2F13.png?alt=media&#x26;token=c425e817-baa1-459f-85bb-494759202e5d" alt="" width="344"><figcaption></figcaption></figure>
{% endstep %}

{% step %}
Click on the **Shader Graph** button and drag and drop generated DRM node into shader editor and connect its output to the **Base Color**:

<figure><img src="https://1494537888-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVDsGRBXgFisq0hO6tTXv%2Fuploads%2Fn2sQZikceT1WjYi55rGA%2F14.png?alt=media&#x26;token=4fa57c23-dc92-4ede-a4d6-c43456f7e273" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
Mask objects count calculated inside a node is written in its name (same as all other DRM settings).
{% endhint %}
{% endstep %}

{% step %}
That's all. Now this DRM node will calculate compound mask consisting of 32 masks. It works exactly the same way as DRM node with 1 mask.
{% endstep %}

{% step %}
Create a new material using this shader and assign it to a mesh.
{% endstep %}

{% step %}
Create **DRM Controller** script with the same **DRM Settings** as used by DRM node and add new material to its **Materials** array. Set **Pool** to **Game Objects** and create several **DRM Game Objects**:

<figure><img src="https://1494537888-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVDsGRBXgFisq0hO6tTXv%2Fuploads%2FauX6uBZLGEZvZKJnrpWB%2F15.png?alt=media&#x26;token=539ca52c-83c3-4ef4-9c3f-ee5a749af560" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
Each mask object has its own visual settings (world-position, radius, intensity, etc) and they are adjusted individually from the **DRM Game Object**. &#x20;

{% hint style="danger" %}
Note, shader performance directly depends on the mask objects count used by the DRM node. Changing the **Count** property inside the **DRM Controller** script or **DRM Game Objects** count in the Pool doesn't mean calculating less or more masks inside a shader.&#x20;

Used mask objects count is baked inside DRM node and it cannot be changed from a script. In this example, the DRM node inside shader always calculates a compound mask that consists of 32 objects.&#x20;

If a DRM node with fewer mask objects is needed, then an appropriate DRM node should be generated using the DRM editor window and it must be used inside the shader.

**DRM Settings** inside the **DRM Controller** script always have to be the same as DRM node settings inside a shader that it updates.
{% endhint %}
{% endstep %}

{% step %}
For creating holes in the mesh, enable **Alpha Clipping** for the shader and use DRM node output for **Alpha** block. Keep **Alpha Clip Threshold** value to 0.5:

<figure><img src="https://1494537888-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVDsGRBXgFisq0hO6tTXv%2Fuploads%2FD9SdHrWDPdIkYiTjdEtQ%2F16.png?alt=media&#x26;token=112ef1f1-8022-4326-883f-5ef5c3f58493" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
Note, output value of the DRM node in this example needs to be inverted. In this case holes will be created inside spherical gizmos.&#x20;
{% endhint %}

<figure><img src="https://1494537888-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVDsGRBXgFisq0hO6tTXv%2Fuploads%2FXCom9uGQqWlWK1HhqPKK%2F17.png?alt=media&#x26;token=69c1dd9f-6f2d-4c03-8418-8818512931fc" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
For creating even better bullet holes effect add Emission (HDR Color) and a noise:

<figure><img src="https://1494537888-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVDsGRBXgFisq0hO6tTXv%2Fuploads%2FGcFSHCvT0tq7dLlzai9Y%2F18.png?alt=media&#x26;token=cddf4be0-3700-4109-8ba7-5f588319a3ec" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1494537888-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVDsGRBXgFisq0hO6tTXv%2Fuploads%2F3WwPSdTT0ymZW8JcqK9Q%2F19.png?alt=media&#x26;token=ce21f531-b168-45c5-b652-7b11a5f1ef4c" alt=""><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}

**DRM Game Objects** are created by hand inside editor or instantiated at run-time, and then manually added to the **Pool**. Visual properties of each mask object can be controlled and animated inside editor or during run-time. For simplifying this process DRM package includes **DRM Live Object** class - this is a run-time generated object with self animatable DRM visual properties and automatic destruction system. We can use it for generating bullets.&#x20;

In the **DRM Controller** switch **Pool** to the **Live Objects** and add **DRM On Mouse Raycast** script to a mesh using the 'bullet holes' material:

<div><figure><img src="https://1494537888-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVDsGRBXgFisq0hO6tTXv%2Fuploads%2FjBKXcDSmvo7t0CYEOY3v%2F20.png?alt=media&#x26;token=85f5a05e-04c0-4909-aa03-d250755de901" alt="" width="290"><figcaption></figcaption></figure> <figure><img src="https://1494537888-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVDsGRBXgFisq0hO6tTXv%2Fuploads%2FCZHta2qYt1qs0RvSlAq3%2F21.png?alt=media&#x26;token=fc618654-40fd-4e7c-b1cb-ea8063c9b246" alt="" width="348"><figcaption></figcaption></figure></div>

{% hint style="info" %}
**DRM On Mouse Raycast** generates **DRM Live Object** on every successful [Physics.Raycast](https://docs.unity3d.com/ScriptReference/Physics.Raycast.html) event and adds it the **DRM Controller** pool.

Import Examples package (from <mark style="color:blue;">**Amazing Assets**</mark> <mark style="color:blue;"></mark><mark style="color:blue;">→</mark> <mark style="color:blue;">**Dynamic Radial Masks**</mark> <mark style="color:blue;"></mark><mark style="color:blue;">→</mark> <mark style="color:blue;"></mark><mark style="color:blue;">**ReadMe**</mark> file) if **DRM On Mouse Raycast** script is missing.
{% endhint %}

In this example generated **DRM Live Objects** have life length of 10 secs after which they are automatically destroyed (removed from the **Pool**). Radius of each one varies between 0.2 - 0.5.&#x20;

Enter game mode and click on the mesh:

{% embed url="<https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVDsGRBXgFisq0hO6tTXv%2Fuploads%2FOOhgu8TGXGAE6uajZOIG%2F3.mp4?alt=media&token=e36ead58-2104-4d2a-9f2f-821c233c934f>" %}
Bullet holes example scene is included in the package
{% endembed %}

DRM node used in this shader calculates mask consisting of 32 objects. During run-time inside **DRM Controller** can be checked their current count in the Pool:

<figure><img src="https://1494537888-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVDsGRBXgFisq0hO6tTXv%2Fuploads%2FAxrXOMBy4hmUsNH0gxRR%2F1.gif?alt=media&#x26;token=45f82fc9-def6-4cc8-b34c-c31c85ee588e" alt=""><figcaption></figcaption></figure>
