본문 바로가기

Unity/Shader

5. UV가 흘러가도록 시간을 사용해보자 (Time.y)

Shader "Custom/UV_TimeShader"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
		_FlowSpeed("FlowSpeed", float) = 1
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }

        CGPROGRAM
        #pragma surface surf Standard 

        sampler2D _MainTex;
		float _FlowSpeed;
		
        struct Input
        {
            float2 uv_MainTex;
        };

        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            fixed4 c = tex2D (_MainTex, float2(IN.uv_MainTex.x, IN.uv_MainTex.y + _Time.y * _FlowSpeed));
            o.Albedo = (c.r + c.g + c.b) / 3;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

 

y 방향으로 흘러가게

fixed4 c = tex2D (_MainTex, float2(IN.uv_MainTex.x, IN.uv_MainTex.y + _Time.y * _FlowSpeed));

x 방향으로 흘러가게

fixed4 c = tex2D (_MainTex, float2(IN.uv_MainTex.x + _Time.y * _FlowSpeed, IN.uv_MainTex.y));