Hello devs!
I’m trying to create a shader that will be used as a minimap for an action game I’m developing.
All I want to do is to overlay the minimap’s camera RenderTexture on top of another normal texture (grid) and after that mask it with another texture, so that the minimap is round.
So far I have come to the shader below:
Shader "Custom/MinimapShader"
{
Properties
{
_MainTex("Main Texture", 2D) = "white" {}
_Mask("Mask Texture", 2D) = "white" {}
_IgnoreColor("Mask Ignore Color", Color) = (0, 0, 0, 1)
_Art("Art Texture", 2D) = "white" {}
}
SubShader
{
Tags{
"Queue" = "Transparent"
"RenderType" = "Transparent"
"PreviewType" = "Plane"
}
Blend SrcAlpha OneMinusSrcAlpha
ZWrite Off
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
uniform sampler2D _MainTex;
uniform sampler2D _Mask;
uniform sampler2D _Art;
uniform float4 _IgnoreColor;
struct appdata {
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f {
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
};
v2f vert(appdata input)
{
v2f output;
output.vertex = mul(UNITY_MATRIX_MVP, input.vertex);
output.uv = input.uv;
return output;
}
float4 frag(v2f input) : COLOR
{
if (any(tex2D(_Mask, input.uv.xy) != _IgnoreColor)) {
float4 mainTexColor = tex2D(_MainTex, input.uv.xy);
if (any(mainTexColor == _IgnoreColor))
return tex2D(_Art, input.uv.xy);
else
return mainTexColor;
}
else
return float4(0, 0, 0, 0);
}
ENDCG
}
}
}
I’m more or less achieving what I want but there are some parts that could use some improvements.
The result is like the image below:

The first problem appears when I try to include a round background image behind the RawImage I have attached a material that uses the shader.
I get the following result with a transparent and an opaque image accordingly.

It seems that the background sprite overlays the RawImage when it’s transparent and covers it when it’s opaque.
Also, there is an issue with the triangles having holes inside them, that completely beats me why ![]()
This is the first time I’m playing with shaders and I could use some guidance to overcome these problems but also to improve the specific shader altogether.
Thanks a lot for your time!
Edit: I forgot to mention that the RenderTexture is a texture that’s mostly black and contains only triangles of different colors, produced by a camera of course. Also, the mask texture is a black texture with a white circle in it. I can provide screenshots if needed.