Shader "XGame/TestTime" { Properties { _MainTex ("Texture", 2D) = "white" {} _ScrollY ("Scroll Speed", Range(0, 1)) = 1 _MoveTime("Move Time", float) = 0 } SubShader { Tags { "RenderType"="Opaque" } LOD 100 Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag // make fog work // #pragma multi_compile_fog #include "UnityCG.cginc" struct appdata { float4 vertex : POSITION; float2 uv : TEXCOORD0; }; struct v2f { float2 uv : TEXCOORD0; float4 vertex : POSITION; }; sampler2D _MainTex; float4 _MainTex_ST; float _ScrollY; float _MoveTime; float2 ModuloUV(float2 uv) { // 取模运算,返回小数部分 // uv.y -= floor(uv.y); return uv - floor(uv); // return frac(uv); } v2f vert (appdata v) { v2f o; // v.vertex.y = sin(v.vertex.x+_Time.y); o.vertex = UnityObjectToClipPos(v.vertex); o.uv = v.uv + float2(0, _ScrollY * _MoveTime); return o; } fixed4 frag (v2f i) : SV_Target { fixed4 col = tex2D(_MainTex, ModuloUV(i.uv)); return col; } ENDCG } } }