118 lines
2.3 KiB
Plaintext
118 lines
2.3 KiB
Plaintext
|
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
|
|||
|
|
|||
|
Shader "Projector/Custom" {
|
|||
|
Properties{
|
|||
|
_ShadowTex("Cookie", 2D) = "gray" {}
|
|||
|
_RangeRadiu("Radiu",Range(0,0.5)) = 0.2
|
|||
|
_RangeAngle("Angle",Range(0,180)) = 60
|
|||
|
_LineW1("LineW",Range(0,0.5)) = 0.1
|
|||
|
_LineW2("LineW",Range(0,0.1)) = 0.01
|
|||
|
_LineColor("LineColor",Color) = (1,0,0,1)
|
|||
|
_Forword("Forword",Vector) = (0,0,0,0)
|
|||
|
_Type("Type",Int) = 1
|
|||
|
}
|
|||
|
Subshader{
|
|||
|
Tags{ "Queue" = "Transparent" }
|
|||
|
Pass{
|
|||
|
ZWrite Off
|
|||
|
ColorMask RGB
|
|||
|
|
|||
|
Blend SrcAlpha OneMinusSrcAlpha
|
|||
|
|
|||
|
CGPROGRAM
|
|||
|
#pragma vertex vert
|
|||
|
#pragma fragment frag
|
|||
|
#include "UnityCG.cginc"
|
|||
|
|
|||
|
struct v2f {
|
|||
|
float2 uvShadow : TEXCOORD0;
|
|||
|
float4 pos : SV_POSITION;
|
|||
|
};
|
|||
|
|
|||
|
float4x4 unity_Projector;
|
|||
|
float4x4 unity_ProjectorClip;
|
|||
|
|
|||
|
v2f vert(float4 vertex : POSITION)
|
|||
|
{
|
|||
|
v2f o;
|
|||
|
o.pos = UnityObjectToClipPos(vertex);
|
|||
|
o.uvShadow = mul(unity_Projector, vertex);
|
|||
|
return o;
|
|||
|
}
|
|||
|
|
|||
|
sampler2D _ShadowTex;
|
|||
|
float _RangeRadiu;
|
|||
|
float _RangeAngle;
|
|||
|
float _LineW1;
|
|||
|
float _LineW2;
|
|||
|
float4 _LineColor;
|
|||
|
float4 _Forword;
|
|||
|
int _Type; //<2F>Ƿ<EFBFBD><C7B7><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD>вü<D0B2>
|
|||
|
|
|||
|
fixed4 frag(v2f i) : SV_Target
|
|||
|
{
|
|||
|
fixed4 texS = tex2D(_ShadowTex, i.uvShadow);
|
|||
|
fixed4 res = texS;
|
|||
|
if (_Type <= 0)
|
|||
|
return res;
|
|||
|
float2 center = float2(0.5, 0.5);
|
|||
|
float dis = distance(i.uvShadow, center);
|
|||
|
|
|||
|
float2 dir = float2(i.uvShadow.x - 0.5,i.uvShadow.y - 0.5);
|
|||
|
float2 centerDir = float2(_Forword .x-0.5, _Forword .y-0.5);
|
|||
|
float angle = dot(dir, centerDir)/(length(dir)*length(centerDir));
|
|||
|
float angleMax = cos(radians(_RangeAngle));
|
|||
|
|
|||
|
if (dis < _RangeRadiu)
|
|||
|
{
|
|||
|
res = fixed4(0, 0, 0, 0);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
if (dis >= _RangeRadiu && dis < _RangeRadiu + _LineW1)
|
|||
|
{
|
|||
|
if (angle > angleMax)
|
|||
|
{
|
|||
|
res = _LineColor;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
res = fixed4(0, 0, 0, 0);
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
if (dis >= _RangeRadiu + _LineW1 && dis < 0.5- _LineW1)
|
|||
|
{
|
|||
|
if (angle > angleMax && angle < angleMax+ _LineW2)
|
|||
|
{
|
|||
|
res = _LineColor;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
if(angle <= angleMax)
|
|||
|
res = fixed4(0, 0, 0, 0);
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
if (dis >= 0.5- _LineW1 && dis <0.5)
|
|||
|
{
|
|||
|
if (angle > angleMax)
|
|||
|
{
|
|||
|
res = _LineColor;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
res = fixed4(0, 0, 0, 0);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
return res;
|
|||
|
}
|
|||
|
ENDCG
|
|||
|
}
|
|||
|
}
|
|||
|
}
|