我有一个透明的圆,并且我想让着色器仅显示其中的一小部分,例如从30度到90度,我的想法是让他的原点从片段传递到顶点到通过制作该女巫像素而不是顶点来使其更“干净”。
这就是我所拥有的,任何人都可以帮助我弄清楚该怎么做?
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
}
}
}
答案 0 :(得分:0)
最简单的方法是选择一条指向范围中心的轴,然后将其轴从UV坐标指向UV中心,然后得到这两个点之间的点积:
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
这将为您提供一个跨度介于22.5度和+22.5度之间的扇区。但是,它不会为您提供非常用户友好的参数。