Shader "TA/Snow"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_AddTex ("AddTex",2D) = "white" {}
_BumpMap("BumpMap",2D)= "white" {}
_SnowStep(" Snow",Range(0,1))=0.5
_LightDir("LightDir",vector) = (0,0,1,1)
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#pragma multi_compile_fog
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
half3 vnormal : NORMAL;
};
struct v2f
{
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
fixed3 normal : NORMAL;
};
sampler2D _MainTex,_AddTex,_BumpMap;
fixed _SnowStep;
half4 _MainTex_ST,_LightDir;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
o.normal = v.vnormal;
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 s = tex2D(_AddTex, i.uv);
half3 customColor = step(1-_SnowStep*s.a,i.normal.y);
fixed4 col = tex2D(_MainTex, i.uv);
fixed3 bum = UnpackNormal(tex2D(_BumpMap, i.uv) * _LightDir.w);
half sDir = max(0,dot(_LightDir,bum));
// apply fog
UNITY_APPLY_FOG(i.fogCoord, col);
return half4((col.rgb*sDir + customColor*s*0.7),1);
}
ENDCG
}
}
}
网友评论