I have transparent circle, and i want to make able to show only a small parth of it by shader, for example from 30 degrees to 90 degrees, my idea is to get he’s origin point from fragment the pass it to vertex to make it more “clean” by doing this witch pixel instead vertex.
This is what i have, anyone can help me to figure out how to do this?
Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
Shader "Unlit/PipeShader"
{
Properties
{
_Color ("Main Color (A=Opacity)", Color) = (1,1,1,1)
_MainTex ("Base (A=Opacity)", 2D) = "" {}
_Transparency("Transparency", Range(0.0,0.5)) = 0.25
}
SubShader
{
Tags
{
"Queue"="Transparent"
"RenderType"="Transparent"
"IgnoreProjector" = "true"
}
Zwrite Off
Blend SrcAlpha OneMinusSrcAlpha
Cull Off
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
float4 worldSpacePos : TEXCOORD0;
};
sampler2D _MainTex;
float4 _MainTex_ST;
float4 _Color;
float _Transparency;
float4 setAxisAngle (float3 axis, float rad) {
rad = rad * 0.5;
float s = sin(rad);
return float4(s * axis[0], s * axis[1], s * axis[2], cos(rad));
}
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
float4 objectOrigin = mul(unity_ObjectToWorld, float4(0.0,0.0,0.0,1.0));
i.worldSpacePos = mul(unity_ObjectToWorld,i.vertex);
// sample the texture
fixed4 col = tex2D(_MainTex, i.uv) * _Color;
col.a = _Transparency;
return col;
}
ENDCG
}
}
}
The easiest way to do this would be to choose an axis which points towards the center of your range, then get the axis from your UV coords to the UV center, and get the dot product between those:
float2 a = float2(cos(_Angle), sin(_Angle)); // Note that _Angle is in radians!
float2 b = normalize(i.uv - (float2)0.5)
half d = dot(a, b);
// dot(a, b) gets the cosine of the angle between a and b
half maxAngle = 0.5 // 45 degrees range
half mask = d > maxAngle ? 1 : 0;
col.a *= mask;
return col
This would give you a sector spanning between angle-22.5 and angle+22.5 degrees. It won't give you very user-friendly parameters, though.