게임 그래픽 프로그래밍

셰이더4: 텍스쳐 애니메이션

101won 2024. 9. 3. 23:15

uv
2차원텍스처좌표, Float2 =xy =정규화: 0~1

곱한다 > 어두워진다

매쉬를 해체 - 텍스쳐 만들기 - 메테리얼로 적용

Warp Mode에서 repeat / 올웨이즈리플레쉬

 

> 텍스쳐 좌표 이동

Shader "Custom/nemo"
{
    Properties
    {
       _MainTex("MainTex", 2D) ="white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
  
        CGPROGRAM
        #pragma surface surf Standard 
        #pragma target 3.0

        sampler2D _MainTex;

        struct Input
        {
            float2 uv_MainTex;
        };

        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            float2 uv = IN.uv_MainTex;
            fixed4 c = tex2D (_MainTex, float2(uv.x +0.5 , uv.y + 0.5)); //uv에 0.5 / 텍스쳐 리피트

            o.Albedo = c.rgb;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

 

>좌측으로 흐르기

Shader "Custom/nemo"
{
    Properties
    {
       _MainTex("MainTex", 2D) ="white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }

        CGPROGRAM
        #pragma surface surf Standard 
        #pragma target 3.0

        sampler2D _MainTex;

        struct Input
        {
            float2 uv_MainTex;
        };

        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            float dir = -1;
            float2 uv = IN.uv_MainTex;
       
             fixed4 c = tex2D (_MainTex, float2(uv.x + _Time.y, uv.y)); // 좌측으로 흐르기

            o.Albedo = c.rgb;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

 

> Speed 슬라이더 만들어서 위, 아래와 흐르기 속도 조절

 

Shader "Custom/nemo"
{
    Properties
    {
       _MainTex("MainTex", 2D) ="white" {}
       _Speed("Speed", float) = 1
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }

        CGPROGRAM
        #pragma surface surf Standard 
        #pragma target 3.0

        sampler2D _MainTex;
        float _Speed;

        struct Input
        {
            float2 uv_MainTex;
        };

        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            float dir = -1;
            float2 uv = float2(IN.uv_MainTex.x, IN.uv_MainTex.y +(dir *_Time.y *_Speed));
            // -1는 아래로 // +는 위로
       
             fixed4 c = tex2D(_MainTex, uv);

            o.Albedo = c.rgb;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}