The snow effect is relatively simple, only need to calculate the vertex normal direction and the world upward direction between the point multiplication, the resulting value compared with the preset threshold, less than the threshold value of 0, with this value interpolation is OK
Code:
1Shader"Myshader/snowshader" {2 properties{3_maintex ("Maintex", 2D) =" White"{}//Textures4_snownum ("Snow Num", Range (-1,1))=0//Point Multiplier threshold5_snowintensity ("Snow Intensity", Range (0, -))=1//Snow intensity6_snowcolor ("Snow Color", Color) = (1.0,1.0,1.0,1.0)//Snow Color7 }8 9 subshader{Ten pass{ Onetags{"Lightmode"="Forwardbase"} A Cgprogram - #pragmaVertex vert - #pragmaFragment Frag the#include"Unitycg.cginc" - - sampler2d _maintex; - float4 _maintex_st; + fixed_snownum; - fixed_snowintensity; + fixed4 _snowcolor; A at structa2v{ - float4 vertex:position; - FLOAT3 Normal:normal; - float2 texcoord:texcoord0; - }; - in structv2f{ - float4 pos:sv_position; to FLOAT3 worldnormal:texcoord0; + float2 uv:texcoord1; - }; the * v2f Vert (a2v v) { $ v2f o;Panax Notoginsengo.pos=Mul (Unity_matrix_mvp,v.vertex); -O.worldnormal=Unityobjecttoworldnormal (v.normal); theo.uv=v.texcoord*_maintex_st.xy+_maintex_st.zw; + returno; A } the + fixed4 Frag (v2f i): sv_target{ -Fixed3 tex=tex2d (_MAINTEX,I.UV). RGB; $Fixed3 worldnormaldir=normalize (i.worldnormal); $Fixed3 Worldupdir=fixed3 (0,1,0); - //use Smoothstep to make the snow edge transition smoother - fixedColnum=smoothstep (_snownum,1, Dot (worldnormaldir,worldupdir)) *_snowintensity; the //fixed colnum=step (dot (worldnormaldir,worldupdir), _snownum); -Fixed3 finalcol=Lerp (tex,_snowcolor,colnum);Wuyi returnFixed4 (Finalcol,1); the } - ENDCG Wu } - } AboutFallBack"Diffuse" $}
View Code
:
Adjusting these values can also make other effects, such as placing objects that have been filled with dust for a long time.
Snow effect of Unityshader