Mask Parent of Render Texture

Hi all,
So I have a container with a grid layout component and a mask. At run time, it’s populated with instantiated panels that are children of my container. These panels contain, among other bits, a image component hooked up as a RenderTexture.

My problem is, the mask of the container seems to ignore the RenderTextures in it’s children. So, the mask works in that it cuts off other parts of it’s children- a normal image, some text etc- but the RenderTexture has not been masked by it’s parent, and overflows the container.

Not sure if this is intended and I need to adjust my approach, but I thought that a mask once applied, would mask off all it’s children equally? I’ve done some testing, by removing my RenderTextures and replacing these with normal images, and it masks them off properly.

Thanks for any help,
Matt

Figured it out. For anyone who finds this thread and needs a solution:

The Material on my RenderTexture had to be set to “Cutout” rendering made to get it to obey the 2D Rect Mask of it’s parent. But my material was created in code, and to switch to cutout mode you need to:

        myMaterial.SetFloat("_Mode", 1f);
                myMaterial.SetInt("_SrcBlend", 1);
                myMaterial.SetInt("_DstBlend", 0);
                myMaterial.SetInt("_ZWrite", 1);
                myMaterial.EnableKeyword("_ALPHATEST_ON");
                myMaterial.DisableKeyword("_ALPHABLEND_ON");
                myMaterial.DisableKeyword("_ALPHAPREMULTIPLY_ON");
                myMaterial.renderQueue = 2450;

Found by digging around in the Standard Shader source. Maybe someone will find it useful one day :slight_smile:

1 Like

i found another solution. (See Sample Package Attached)
Add “Mask” component instead of rect mask 2d to parent image. Add any shape (circle,square etc) in image source of image component. Make child Raw Image With render texture assign to parent image.

4941128–479582–Minimap.unitypackage (26.4 KB)