Unity3D Shader:消散

Shader "Unlit/Test"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_MainColor("MainColor",COLOR)=(1,1,1,1)
_Hold("Hold",Range(0,1))=0
_AddTex("AddTex",2D)="white"{}
_AddColor("AddColor",COLOR)=(1,1,1,1)
_AddHold("AddHold",Range(0,1))=0
}
SubShader
{
Tags { "RenderType"="Opaque" "LightMode"="ForwardBase" }
LOD 100


Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag

#include "UnityCG.cginc"


struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
float3 nor:NORMAL;
};


struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
float3 norpos:TEXCOORD1;
float3 col:COLOR;
float4 objpos:TEXCOORD2;
};


sampler2D _MainTex;
float4 _MainTex_ST;
float4 _MainColor;
float4 _LightColor0;
float _Hold;
sampler2D _AddTex;
float4 _AddColor;
float _AddHold;


v2f vert (appdata v)
{
v2f o;
v.vertex.xyz+=v.vertex.xyz*saturate(0.2-_Hold)*3;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
o.norpos=mul(v.nor,unity_ObjectToWorld);
fixed3 norpo=normalize(o.norpos);
fixed3 ligpo=normalize(_WorldSpaceLightPos0.xyz);
fixed lam=saturate(dot(norpo,ligpo));
fixed3 co=lam*_LightColor0.rgb*_MainColor.rgb+UNITY_LIGHTMODEL_AMBIENT.xyz;
o.col=co;
o.objpos=v.vertex;
return o;
}

fixed4 frag (v2f i) : SV_Target
{
// sample the texture
fixed3 col = tex2D(_MainTex, i.uv).rgb*i.col;
fixed3 add=tex2D(_AddTex,float2(i.uv.x,i.uv.y-_Time.x)).rgb;
fixed hold=saturate(i.objpos.y+0.55f);
if((add.r<_AddHold)&&(hold>_Hold))
{
discard;
}
fixed lerpAdd=sign(add.r-_AddHold);
fixed3 lerpColor=lerp(fixed3(0,0,0),_AddColor.rgb,saturate(lerpAdd));
fixed lerpMain=sign(hold-_Hold);
fixed3 lerpMainColor=lerp(col,lerpColor,saturate(lerpMain));
return fixed4(lerpMainColor,1);
//if(hold>=_Hold) //这里if写法和上面效果相同
//{
//if(add.r>_AddHold)
//{
//return fixed4(_AddColor.rgb,1);
//}
//else
//{
//discard;
//}


//}
//return fixed4(col,1);
}
ENDCG
}
}

}

Unity3D Shader:消散_第1张图片

你可能感兴趣的:(Shader)