本系列主要参考《Unity Shaders and Effects Cookbook》一书(感谢原书作者),同时会加上一点个人理解或拓展。
这里是本书所有的插图。这里是本书所需的代码和资源(当然你也可以从官网下载)。
========================================== 分割线 ==========================================
新年第一篇!在此就献给了这个系列。马上就可以放假回家了,虽然还有一些事情需要处理,但是能和家人团聚实在是件很难得的事了。希望所有朋友也能记得多回家看看,借最近很热门的电影《私人定制》(我没看过甲方乙方什么的,觉得这个还不错啦)中的插曲《时间都去哪儿了》,不要等到时间都不见了才想起家人,希望朋友们和朋友的家人们在新年里都能幸福!
门前老树长新芽
院里枯木又开花
半生存了多少话
藏进了满头白发
记忆中的小脚丫
肉嘟嘟的小嘴巴
一生把爱交给他
只为那一声爸妈
时间都去哪儿了
还没好好感受年轻就老了
生儿养女一辈子
满脑子都是孩子哭了笑了
时间都去哪儿了
还没好好看看你眼睛就花了
柴米油盐半辈子
转眼就只剩下满脸的皱纹了
Properties { _MainTex ("Base (RGB)", 2D) = "white" {} // Add two properties _ScrollXSpeed ("X Scroll Speed", Range(0, 10)) = 2 _ScrollYSpeed ("Y Scroll Speed", Range(0, 10)) = 2 }
CGPROGRAM #pragma surface surf Lambert sampler2D _MainTex; fixed _ScrollXSpeed; fixed _ScrollYSpeed;
void surf (Input IN, inout SurfaceOutput o) { fixed2 scrolledUV = IN.uv_MainTex; fixed xScrollValue = _ScrollXSpeed * _Time.y; fixed yScrollValue = _ScrollYSpeed * _Time.y; scrolledUV += fixed2(xScrollValue, yScrollValue); half4 c = tex2D (_MainTex, scrolledUV); o.Albedo = c.rgb; o.Alpha = c.a; }
Shader "Custom/ScrollingUVs" { Properties { _MainTex ("Base (RGB)", 2D) = "white" {} // Add two properties _ScrollXSpeed ("X Scroll Speed", Range(0, 10)) = 2 _ScrollYSpeed ("Y Scroll Speed", Range(0, 10)) = 2 } SubShader { Tags { "RenderType"="Opaque" } LOD 200 CGPROGRAM #pragma surface surf Lambert sampler2D _MainTex; fixed _ScrollXSpeed; fixed _ScrollYSpeed; struct Input { float2 uv_MainTex; }; void surf (Input IN, inout SurfaceOutput o) { fixed2 scrolledUV = IN.uv_MainTex; fixed xScrollValue = _ScrollXSpeed * _Time.y; fixed yScrollValue = _ScrollYSpeed * _Time.y; scrolledUV += fixed2(xScrollValue, yScrollValue); half4 c = tex2D (_MainTex, scrolledUV); o.Albedo = c.rgb; o.Alpha = c.a; } ENDCG } FallBack "Diffuse" }
struct Input { float2 uv_MainTex; };
Shader "Mobile/Transparent/Vertex Color" { Properties { _Color ("Main Color", Color) = (1,1,1,1) _SpecColor ("Spec Color", Color) = (1,1,1,0) _Emission ("Emmisive Color", Color) = (0,0,0,0) _Shininess ("Shininess", Range (0.1, 1)) = 0.7 _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {} } Category { Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"} ZWrite Off Alphatest Greater 0 Blend SrcAlpha OneMinusSrcAlpha SubShader { Material { Diffuse [_Color] Ambient [_Color] Shininess [_Shininess] Specular [_SpecColor] Emission [_Emission] } Pass { ColorMaterial AmbientAndDiffuse Fog { Mode Off } Lighting Off SeparateSpecular On SetTexture [_MainTex] { Combine texture * primary, texture * primary } SetTexture [_MainTex] { constantColor [_Color] Combine previous * constant DOUBLE, previous * constant } } } } }
using UnityEngine; using System.Collections; public class WaterFlow : MonoBehaviour { public float m_SpeedU = 0.1f; public float m_SpeedV = -0.1f; // Update is called once per frame void Update () { float newOffsetU = Time.time * m_SpeedU; float newOffsetV = Time.time * m_SpeedV; if (this.renderer) { renderer.material.mainTextureOffset = new Vector2(newOffsetU, newOffsetV); } } }