Shader "Custom/_Snow" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Bump ("Bump", 2D) = "bump" {}
_Snow ("Snow Level", Range(0,5)) = 0
_SnowColor("Snow Color", Color) = (1,1,1,1)
_SnowDir("Snow Direction",Vector) = (0,1,0)
_SnowThick ("Snow thickness", Range(-1,1)) = 0
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Lambert vertex:vert
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex;
sampler2D _Bump;
sampler2D _RampTex;
struct Input {
float2 uv_MainTex;
float2 uv_Bump;
float3 viewDir;
float3 worldNormal; INTERNAL_DATA
};
fixed4 _Color;
half _Snow;
fixed4 _SnowColor;
fixed3 _SnowDir;
float _SnowThick;
// tangent(切线)的效果是整体变化
// normal(法线)或texcoord(第一个uv坐标)都是逐步变化
// 顶点函数里对需要积雪的地方给一个厚度
void vert (inout appdata_full v) {
if(dot(v.normal, _SnowDir.xyz) > lerp(1,-1,_SnowThick)){
v.vertex.xyz += v.normal * _SnowThick * (dot(v.normal, _SnowDir.xyz)*0.5 + 0.5) * 0.05;
}
}
void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Normal = UnpackNormal(tex2D(_Bump, IN.uv_Bump));
if (dot(WorldNormalVector(IN, o.Normal), _SnowDir.xyz) > lerp(1,-1,_Snow)) {
o.Albedo = _SnowColor.rgb * _Color;
} else {
o.Albedo = c.rgb;
}
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
Unity Shader学习之积雪练习
最新推荐文章于 2024-06-28 16:43:02 发布