# How do i make a cube mask using the custom node in the material editor?

**URL:** <https://forums.unrealengine.com/t/how-do-i-make-a-cube-mask-using-the-custom-node-in-the-material-editor/1247685>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, editor, Rendering, question, Blueprint\
**Created:** [August 2, 2023, 1:09am UTC](https://forums.unrealengine.com/t/how-do-i-make-a-cube-mask-using-the-custom-node-in-the-material-editor/1247685 "2023-08-02T01:09:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SophiaWolfie](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/sophiawolfie/32/1008648_2.png) [@SophiaWolfie](https://forums.unrealengine.com/u/SophiaWolfie)\
**Post date:** [August 2, 2023, 1:09am UTC](https://forums.unrealengine.com/t/how-do-i-make-a-cube-mask-using-the-custom-node-in-the-material-editor/1247685/1 "2023-08-02T01:09:08Z")

</div>

![imagem](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/6/2/9624f9f49fea343fe322599ed0399e0c7ccae8e6.png)  
In this example it creates a sphere mask that i then use to hide the mesh in the material.  
But what if i want to do a cube mask in the custom node?  
How do i do that?

---

<div class="post-metadata">

**Author:** ![SophiaWolfie](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/sophiawolfie/32/1008648_2.png) [@SophiaWolfie](https://forums.unrealengine.com/u/SophiaWolfie)\
**Post date:** [August 2, 2023, 1:49am UTC](https://forums.unrealengine.com/t/how-do-i-make-a-cube-mask-using-the-custom-node-in-the-material-editor/1247685/2 "2023-08-02T01:49:51Z")

</div>

Found the solution:

```auto
float4 CubesMask = float4(0.0, 0.0, 0.0, 0.0); // Mask for four cubes

// Define the positions and half extents of the four cubes
float3 CubeCenters[4] = {
    float3(80, -80, 80),
    float3(-80, 80, 120),
    float3(100, 80, 120),
    float3(-80, -80, 200)
};

float3 CubeHalfExtents = float3(50, 50, 150);

// Iterate through each cube and calculate the distance from its center
for (int i = 0; i < 4; i++)
{
    float3 Distance = abs(ObjectWorldPosition - CubeCenters[i]);

    // Check if the pixel is inside the cube
    if (all(Distance <= CubeHalfExtents))
    {
        CubesMask += float4(1.0, 1.0, 1.0, 1.0); // Add 1.0 to the corresponding component
    }}

return CubesMask;

```

This will create 4 cube masks on your mesh.

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [September 1, 2023, 1:50am UTC](https://forums.unrealengine.com/t/how-do-i-make-a-cube-mask-using-the-custom-node-in-the-material-editor/1247685/3 "2023-09-01T01:50:27Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
