Unity3D Shader:溶解

Shader "Unlit/Test"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_MainColor("MainColor",COLOR)=(1,1,1,1)
_AddTex("AddTex",2D)="white"{}
_DiffColor("DiffColor",COLOR)=(1,1,1,1)
_DiffLessColor("DiffLessColor",COLOR)=(1,1,1,1)
_DiffHold("DiffHold",Range(0.0,1.0))=0.1
_ColorRange("ColorRange",Range(0,1))=0.7
_ColorLessRange("ColorLessRange",Range(0,1))=0.8
_FlyHold("FlyHold",Range(0,1))=0.9
_FlyPower("FlyPower",float)=1
}
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 normal:NORMAL;
};


struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
float3 worldNor:TEXCOORD1;
float3 color:COLOR;
};


sampler2D _MainTex;
float4 _MainTex_ST;
sampler2D _AddTex;
float4 _MainColor;
float _DiffHold;
float4 _DiffColor;
float4 _DiffLessColor;
float _ColorRange;
float _ColorLessRange;
float4 _LightColor0;
float _FlyHold;
float _FlyPower;
v2f vert (appdata v)
{
v2f o;
v.vertex.xyz+=v.normal*saturate(_DiffHold-_FlyHold)*_FlyPower;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
o.worldNor=mul(v.normal,unity_ObjectToWorld);
fixed3 worldNor=normalize(o.worldNor);
fixed3 worldLig=normalize(_WorldSpaceLightPos0.xyz);
fixed lam=saturate(dot(worldNor,worldLig));
fixed3 co=lam *_LightColor0.rgb*_MainColor.rgb + UNITY_LIGHTMODEL_AMBIENT.xyz;
o.color=co;
return o;
}

fixed4 frag (v2f i) : SV_Target
{
// sample the texture
fixed4 DiffVal=tex2D(_AddTex,i.uv);
if(DiffVal.r < _DiffHold)
{
discard;
}

fixed3 col=tex2D(_MainTex,i.uv).rgb*i.color.rgb;
float BaifenBi=_DiffHold/DiffVal.r;
float lerpLess=sign(BaifenBi-_ColorRange-_ColorLessRange);
float3 LessColor=lerp(_DiffLessColor.rgb,_DiffColor.rgb,saturate(lerpLess));
float lerpout=sign(BaifenBi-_ColorRange);
float3 outColor=lerp(col.rgb,LessColor.rgb,saturate(lerpout));
return fixed4(outColor,1);
}
ENDCG
}
}

}

Unity3D Shader:溶解_第1张图片

你可能感兴趣的:(Shader)