Mobile development snow shader effect development tutorial, snow shader effect tutorial

Source: Internet
Author: User

Mobile development snow shader effect development tutorial, snow shader effect tutorial

Mobile development snow shader effect development tutorial.

Shader "Custom/XueDiShader" {Properties {// rock Paster _ MainTex ("basic material", 2D) = "white" {} // normal texture _ Bump ("line chart", 2D) = "bump" {} // indicates the number of snow that is covered on the rock, the value range is from 0 ~ 1 _ Snow ("Snow level", Range (1.0) = 0 // Snow Color default white _ SnowColor ("Snow Color", Color) = (1.0, 1.0, 1.0) // snow direction _ SnowDirection ("Snow direction", Vector) = (0, 0) // snow thickness _ SnowDepth ("snow depth", Range (0, 0.2) = 0.1 // humidity. If the value is greater, the color proportion of the snow in the mixed color is lower. This indicates that the more wet the snow, the less the color of the snow, all are converted into water _ Wetness ("water", Range (0, 0.5 )) = 0.3} SubShader {Tags {"RenderType" = "Opaque"} lays 200 CGPROGRAM # pragma surface surf Lambert vertex: vert // get the specific attribute value sampler2D _ Mai NTex; sampler2D _ Bump; float _ Snow; float4 _ SnowColor; float4 _ SnowDirection; float _ SnowDepth; float _ Wetness; // Input struct Input {// obtain the uv coordinate float2 uv_MainTex of The Rock texture; // obtain the uv coordinate float2 uv_Bump of the Normal texture; // if the Normal value is set in SurfaceOutput, worldNormal can be used to obtain the float3 worldNormal; INTERNAL_DATA} of the current point in the world; // void vert (inout appdata_full v) of the vertex coloring program entry) {// convert _ SnowDirection to the float4 sn = mul (UNITY_MATRIX_IT _ MV, _ SnowDirection); if (dot (v. normal, sn. xyz)> = lerp (1,-1, (_ Snow * 2)/3) {v. vertex. xyz + = (sn. xyz + v. normal) * _ SnowDepth * _ Snow;} void surf (Input IN, inout SurfaceOutput o) {half4 c = tex2D (_ MainTex, IN. uv_MainTex); o. normal = UnpackNormal (tex2D (_ Bump, IN. uv_Bump); // WorldNormalVector uses the input vertex and its normal value, to calculate its direction in the World coordinate. // then, use the Input Point in the World coordinate direction and the Snow direction to perform the dot product operation and subtract the _ Snow interpolation half difference = dot (World NormalVector (IN, o. normal), _ SnowDirection. xyz)-lerp (1,-1, _ Snow); // If x is smaller than 0, the saturate (x) function returns 0; if x is greater than 1, 1 is returned; otherwise, returns x difference = saturate (difference/_ Wetness); // the reflectivity of the light source. O. Albedo = difference * _ SnowColor. rgb + (1-difference) * c; o. Alpha = c. a;} ENDCG} FallBack "Diffuse "}

Related Article

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.