效果图
两边闪烁区域呈现半圆形
主要思路:在屏幕坐标系下,左下角为(0,0),右上角为(1,1),区域制作半圆形主要是在(-0.5,0.5)与(1.5,0.5)分别为圆心作园,在shader下uv<0与uv>1都不显示,就呈现出了半圆,之后在做lerp插值的渐变颜色
shader代码:
Shader "Hidden/Blood"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_BloodLength("BloodLength",float)=0.5
}
SubShader
{
// No culling or depth
//Cull Off ZWrite Off ZTest Always
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;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
sampler2D _MainTex;
float _BloodLength;
fixed4 frag (v2f i) : SV_Target
{
float2 tmpuv=i.uv;
float tmpLenth=0;
if(tmpuv.x<0.5){
tmpLenth=length(tmpuv-float2(-0.5,0.5));
}
else{
tmpLenth=length(float2(1.5,0.5)-tmpuv);
}
tmpLenth*=_BloodLength;
fixed4 col = tex2D(_MainTex, i.uv);
col=lerp(col,float4(1,0,0,1),1-clamp(tmpLenth,0,1) );
// just invert the colors
//col = 1 - col;
return col;
}
ENDCG
}
}
}