I’d like to add a hole inside an empty object with sprites inside.
This hole has a circle shape.
To achieve that, I added a shader to a material and the material to a Sprite Renderer component to the empty object.
Here is my Shader :
Shader "Sprite/Hole Effect"
{
Properties
{
_MainTex ("Base (RGB)", 2D) = "white" {}
_ObjPos ("Object Position", Vector) = (1,1,1,1)
_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
_Radius ("Hole Radius", Range(0.1,10)) = 2
}
SubShader
{
Pass
{
Cull Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
uniform sampler2D _MainTex;
float _Radius;
float4 _ObjPos;
struct vertexInput {
float4 vertex : POSITION;
float4 texcoord : TEXCOORD0;
};
struct vertexOutput {
float4 pos : SV_POSITION;
float4 worldPos : POSITION1;
float4 tex : TEXCOORD0;
};
vertexOutput vert(vertexInput input)
{
vertexOutput output;
output.tex = input.texcoord;
output.pos = UnityObjectToClipPos(input.vertex);
output.worldPos = mul(input.vertex, unity_ObjectToWorld);
return output;
}
float4 frag(vertexOutput input) : COLOR
{
float4 textureColor = tex2D(_MainTex, input.tex.xy);
float dis = distance(input.worldPos.xyz, _ObjPos);
if (dis > _Radius)
{
discard;
}
return textureColor;
}
ENDCG
}
}
FallBack "Diffuse"
}
The problem with this method is that there is no antialiasing for the circle…
So I tried to add a Sprite mask to the empty object instead, but there is no antialiasing nether…
I think the shader is the good solution to achieve that but really don’t know how!
Any help would be perfect!!!