1.设置
sprite 动效的贴图与背景图设置成一致的
2.代码
Shader "Custom/SpriteWave2"{
Properties{
_Color ("Tint", Color) = (0, 0, 0, 1)
_MainTex ("Texture", 2D) = "white" {}
}
SubShader{
Tags{
"RenderType"="Transparent"
"Queue"="Transparent"
}
Blend SrcAlpha OneMinusSrcAlpha
ZWrite off
Cull off
Pass{
CGPROGRAM
#include "UnityCG.cginc"
#pragma vertex vert
#pragma fragment frag
#define PI 3.1415926
sampler2D _MainTex;
fixed4 _Color;
struct appdata{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f{
float4 position : SV_POSITION;
float2 uv : TEXCOORD0;
};
float func(float x){
float xx = x * 0.5 * PI + _Time * 5.0;
//xx = (1 - floor(xx)) * PI / 4 + PI / 4;
//裁剪波谷
float sx = abs(sin(xx));
return sx / 20 + 0.9;
}
float plotFunc(float2 uv){
float f = func(uv.x);
return 1 - step(f,uv.y);
}
v2f vert(appdata v){
v2f o;
o.position = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
fixed4 frag(v2f i) : SV_TARGET{
i.uv -= float2(-0.5,-0.5);
float a = plotFunc(i.uv);
fixed4 col = fixed4(0,0,a,0);
if(a <= 0){
col.a = 0;
}else{
col.a = 1;
}
return col;
}
ENDCG
}
}
}
3.效果: