_Time的使用
会动的纹理
Shader "Custom/River" {
Properties {
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_XSpeed("X Speed",Range(0,10))=2
_YSpeed("Y Speed",Range(0,10))=2
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Lambert
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
};
float _XSpeed;
float _YSpeed;
void surf (Input IN, inout SurfaceOutput o) {
float2 scrolledUV=IN.uv_MainTex;
float xScrollValue=_XSpeed*_Time.y;
float yScrollValue=_YSpeed*_Time.y;
scrolledUV+=fixed2(xScrollValue,yScrollValue);
fixed4 c=tex2D(_MainTex,scrolledUV);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
_Time内置变量与Time.time类似
float4 _Time:Time(t/20,t,t*2,t*3)用于shader中可动画的地方
根据需要选择某个分量