Shader-水流效果

效果图:(贴图类似于泥石流)

代码:

 1 Shader "CookbookShaders/Chapter02/ScrollingUVs"
 2 {
 3     Properties
 4     {
 5         _MainTint("Diffuse Tint", Color) = (1,1,1,1)
 6         _MainTex("Base (RGB)", 2D) = "white" {}
 7         _ScrollXSpeed("X Scroll Speed", Range(0, 10)) = 2
 8         _ScrollYSpeed("Y Scroll Speed", Range(0, 10)) = 2
 9     }
10 
11         SubShader
12     {
13         Tags{ "RenderType" = "Opaque" }
14         LOD 200
15 
16         CGPROGRAM
17 #pragma surface surf Lambert
18 
19     fixed4 _MainTint;
20     fixed _ScrollXSpeed;
21     fixed _ScrollYSpeed;
22     sampler2D _MainTex;
23 
24     struct Input
25     {
26         float2 uv_MainTex;
27     };
28 
29     void surf(Input IN, inout SurfaceOutput o)
30     {
31         //Create a seperate variable to store our uvs 
32         //before we pass them to the tex2D() function
33         fixed2 scrolledUV = IN.uv_MainTex;
34 
35         //Create variables that store the individual x and y 
36         //components for the uv's scaled by time
37         fixed xScrollValue = _ScrollXSpeed * _Time;
38         fixed yScrollValue = _ScrollYSpeed * _Time;
39 
40         //Apply the final uv offset
41         scrolledUV += fixed2(xScrollValue, yScrollValue);
42 
43         //Apply textures and tint
44         half4 c = tex2D(_MainTex, scrolledUV);
45         o.Albedo = c.rgb * _MainTint;
46         o.Alpha = c.a;
47     }
48     ENDCG
49     }
50         FallBack "Diffuse"
51 }

注意:

内置方法 _Time

是个4维向量,跟Unity3D中的deltaTime(这是个一维的,数值)不同。

    • float4 _Time : Time (t/20, t, t*2, t*3), use to animate things inside the shaders
点赞鼓励下,(づ ̄3 ̄)づ╭❤~

作者:君莫笑
       出处:https://www.cnblogs.com/Firepad-magic/
       Unity最受欢迎插件推荐:点击查看
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

原文地址:https://www.cnblogs.com/Firepad-magic/p/5509976.html