# Grid Custom Surface Projector

The **Grid Custom Surface Projector** component located in <mark style="color:purple;">**SoulGames > Easy Grid Builder Pro 2 > Scripts > Grid Custom Surface Camera Scripts**</mark> dynamically adjusts the grid projection onto surfaces in real-time. This component is used to align grid visuals to underlying terrain or other complex geometry, ensuring the grid adapts smoothly to uneven surfaces.

This component is designed to work with the **Custom Surface Grid Projector** prefab, located in:\ <mark style="color:purple;">**SoulGames > Easy Grid Builder Pro 2 > Prefabs**</mark><mark style="color:purple;">.</mark>

<figure><img src="https://2651556506-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FeumhICLT4oHoEIEssOjB%2Fuploads%2FxmBAzEl5C39nvbFMJzgu%2Fimage.png?alt=media&#x26;token=deea9c2a-5c0e-41ff-bf2c-45c974153db9" alt=""><figcaption></figcaption></figure>

<table data-full-width="false"><thead><tr><th width="216">Property</th><th width="429.3333333333333">Function</th><th>Required</th></tr></thead><tbody><tr><td>Update in Editor</td><td>Allows updates to projection while in the Unity Editor.</td><td>No</td></tr><tr><td>Main Camera</td><td>The camera used to calculate projection parameters. Defaults to <code>Camera.main</code> if not assigned</td><td><mark style="color:red;"><strong>Yes</strong></mark></td></tr><tr><td><strong>Surface Layer Mask</strong></td><td>Defines the layers used for detecting Custom Surfaces during raycasting (Ex: Terrain)</td><td><mark style="color:red;"><strong>Yes</strong></mark></td></tr><tr><td>Minimum Projection Scale</td><td>The smallest scale for grid projection when close to the camera</td><td><mark style="color:red;"><strong>Yes</strong></mark></td></tr><tr><td>Maximum Projection Scale</td><td>The largest scale for grid projection when far from the camera</td><td><mark style="color:red;"><strong>Yes</strong></mark></td></tr><tr><td>Maximum Distance</td><td>The maximum distance to the Surface from the Camera for scaling calculations</td><td><mark style="color:red;"><strong>Yes</strong></mark></td></tr><tr><td>Projection Depth</td><td>The depth of the decal projection</td><td><mark style="color:red;"><strong>Yes</strong></mark></td></tr><tr><td>Decal Projector</td><td>The Unity Decal Projector component is used for grid visuals</td><td><mark style="color:red;"><strong>Yes</strong></mark></td></tr><tr><td>Decal Camera</td><td>A secondary camera used for orthographic capturing of the grid</td><td><mark style="color:red;"><strong>Yes</strong></mark></td></tr></tbody></table>

***

## <mark style="color:green;">Example Use case</mark>

To use this feature, let’s say you want to project your grid system onto a **Terrain**.

1. Start by setting up your **Terrain** and **Grid System**. Position your grid system below the custom surface (Terrain). At this point, when viewed from above, the grid system should not be visible because it is positioned beneath the terrain.
2. Locate the **Custom Surface Grid Projector** prefab in:\ <mark style="color:purple;">**SoulGames > Easy Grid Builder Pro 2 > Prefabs**</mark><mark style="color:purple;">.</mark>\
   Drag and drop it into your scene. The projector will automatically find the **Main Camera** and configure the necessary parameters.
3. In the **Custom Surface Grid Projector** component, add the layers of your custom surfaces to the **Surface Layer Mask** property.
4. Ensure the **Update In Editor** property is enabled. This will instantly project the grid visuals onto the custom surface, allowing you to see the grid overlay on your terrain.

<figure><img src="https://2651556506-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FeumhICLT4oHoEIEssOjB%2Fuploads%2FMg1JB1RzxvvLsbZ5MnHE%2Fimage.png?alt=media&#x26;token=cc2bbf7e-ddf8-4667-9b3b-5236b725e89e" alt=""><figcaption></figcaption></figure>

If the grid projection doesn’t cover the entire camera view area, you can adjust the **Max Distance** and **Max Projection Scale** properties. Be sure to test these adjustments in the **Game view**, not the **Scene view**, as the projection is designed to align with the camera’s view area.

In most cases, the default values work best, but fine-tuning these properties may be necessary for specific setups.

When you enter **Play Mode** and move the camera, you’ll notice that the projection dynamically adjusts to cover only the camera’s view area. This ensures optimized performance and maintains higher resolution for the grid visuals.

<figure><img src="https://2651556506-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FeumhICLT4oHoEIEssOjB%2Fuploads%2F9E8N3zyZciEgZptmh8M2%2Fimage.png?alt=media&#x26;token=3ce90ed6-23dc-4700-b076-5e72c9b53194" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
When you scale up the projection area using the **Max Distance** and **Max Projection Scale** properties, the projection area expands at the expense of projection resolution quality. It’s important to find a proper balance between area coverage and visual quality.

To enhance the grid’s appearance when using custom surface projection, it’s recommended to enable the **Use Alpha Mask** property in the **Visual - Object Grid** section of your **Easy Grid Builder Pro XZ** component. This limits the visible grid area, ensuring a cleaner and more focused projection.
{% endhint %}

<figure><img src="https://2651556506-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FeumhICLT4oHoEIEssOjB%2Fuploads%2F1kq5FzThOs1uoYYCVsom%2Fimage.png?alt=media&#x26;token=aa61f324-6eec-4807-856c-9dfd5b5d2438" alt=""><figcaption></figcaption></figure>

Behind the scenes, a custom camera captures the grid surface and stores it in a **Render Texture**. This texture is then projected onto the custom surface using a **Decal Projector**.

You can find the **Custom Surface Render Texture** in:\ <mark style="color:purple;">**SoulGames > Easy Grid Builder Pro 2 > Misc Assets > Materials > Custom Surface Render Texture**</mark><mark style="color:purple;">.</mark>

By default, the **Size** property of this texture is set to **2048 x 2048**. You can adjust this value to fit your target platform, balancing resolution quality and performance.

***

## <mark style="color:green;">Limitations of Custom Surface Projection</mark>

One limitation of using custom surface projection is that the projected grid will not have any emissive qualities. If you’re using **Grid Show Color HDR**, the HDR emissive colors will not appear in the projected view. This is a trade-off for the performance and versatility of the projection system.
