Snow effect of Unityshader

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.