0503 쉐이더 UV

2021. 5. 3. 16:50unity/쉐이더

가로는 U, 세로는 V 

둘을 시각적으로 나타내기

void surf (Input IN, inout SurfaceOutputStandard o)
        {
            fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
            o.Albedo = IN.uv_MainTex.x;
            
        }
        ENDCG

void surf (Input IN, inout SurfaceOutputStandard o)
        {
            fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
            o.Albedo = IN.uv_MainTex.y;
            
        }
        ENDCG

 

0.5만큼 y축이 올라갔다.

Shader "Custom/Test"
{
    Properties
    {

        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _V("v value",Range(-1,1)) = 0
        _U("u value",Range(-1,1)) = 0
       
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        
        #pragma surface surf Standard fullforwardshadows


        sampler2D _MainTex;

        struct Input
        {
            float2 uv_MainTex;
        };

        float _V;
        float _U;
        
        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            fixed4 c = tex2D(_MainTex, float2(IN.uv_MainTex.x+_U, IN.uv_MainTex.y+_V));
            o.Albedo = c.rgb;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

 

둘이 한꺼번에 움직이도록 설정

 

x축으로만 흘러가도록 할 때

void surf (Input IN, inout SurfaceOutputStandard o)
        {
            fixed4 c = tex2D(_MainTex, float2(IN.uv_MainTex.x + _Time.y, IN.uv_MainTex.y));
            o.Albedo = c.rgb;
            
        }
        ENDCG

 

y축으로만 흘러가도록 할때

void surf (Input IN, inout SurfaceOutputStandard o)
        {
            fixed4 c = tex2D(_MainTex, float2(IN.uv_MainTex.x, IN.uv_MainTex.y + _Time.y));
            o.Albedo = c.rgb;
            
        }
        ENDCG

 

xy축 동시에 흘러가도록 할 때

 void surf (Input IN, inout SurfaceOutputStandard o)
        {
            fixed4 c = tex2D(_MainTex, float2(IN.uv_MainTex.x, IN.uv_MainTex.y)+_Time.y);
            o.Albedo = c.rgb;
            
        }
        ENDCG

 

흘러가는 속도를 조절하는 슬라이더 만들기

Properties
    {
        
        _MainTex("Albedo (RGB)", 2D) = "white" {}
        _Speed("Speed",Range(0,1)) = 0
  
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        
        #pragma surface surf Standard fullforwardshadows


        sampler2D _MainTex;

        struct Input
        {
            float2 uv_MainTex;
        };

        float _Speed;

        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            fixed4 c = tex2D(_MainTex, float2(IN.uv_MainTex.x, IN.uv_MainTex.y)+_Time.y*_Speed);
            o.Albedo = c.rgb;
            
        }
        ENDCG
    }
    FallBack "Diffuse"
}