鸟语天空
滚动的背景
post by:追风剑情 2016-11-8 20:56

纹理的Wrap Mode一定要设置成Repeat

111111.png

Shader代码

Shader "Custom/Chapter11-ScrollingBackground" {
	Properties {
		_MainTex ("Base (RGB)", 2D) = "white" {}
		_ScrollX ("Scroll Speed", float) = 1.0
	}
	SubShader {
		Tags { "RenderType"="Opaque" }
		LOD 200
		Pass {
			Tags { "LightMode"="ForwardBase" }
			
			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			#include "UnityCG.cginc"
			
			sampler2D _MainTex;
			float4 _MainTex_ST;
			float _ScrollX;
			
			struct a2v {
				float4 vertex : POSITION;
				float4 texcoord : TEXCOORD0;
			};
			
			struct v2f {
				float4 pos : SV_POSITION;
				half2 uv : TEXCOORD0;
			};
			
			v2f vert(a2v v) {
				v2f o;
				o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
				o.uv = v.texcoord.xy*_MainTex_ST.xy+_MainTex_ST.zw;
				//frac(x):返回x的小数部分
				o.uv += frac(float2(_ScrollX, 0.0) * _Time.y);
				return o;
			}
			
			fixed4 frag(v2f i) : Color {
				fixed4 c = tex2D(_MainTex, i.uv);
				return c;
			}
			ENDCG
		}
	} 
	FallBack "VertexLit"
}

评论:
发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容