유니티/쉐이더

05/03 유니티 쉐이더 Texture 2장으로 lerp메서드 연습

박준희 2021. 5. 3. 14:59
728x90

Texture 2장을 받는 쉐이더 작성

 

Shader "Custom/Test"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _SubTex ("SubTex", 2D) = "white" {}
        _Lerp ("lerp", Range(0,1)) = 0.5
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        #pragma surface surf Standard fullforwardshadows


        sampler2D _MainTex;
        sampler2D _SubTex;

        struct Input
        {
            float2 uv_MainTex;
            float2 uv_SubTex;
        };

        float _Lerp;

        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            // Albedo comes from a texture tinted by color
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            fixed4 d = tex2D (_SubTex, IN.uv_SubTex);
            o.Albedo = lerp(c.rgb, d.rgb, _Lerp);
        }
        ENDCG
    }
    FallBack "Diffuse"
}

 

Texture 각각 밝기 조절

 

 

Shader "Custom/Test"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _SubTex ("SubTex", 2D) = "white" {}
        _Lerp ("lerp", Range(0,1)) = 0.5
        _BrightnessMain("BrightnessMian", Range(-1,1)) = 0
        _BrightnessSub("BrightnessSub", Range(-1,1)) = 0
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        #pragma surface surf Standard fullforwardshadows


        sampler2D _MainTex;
        sampler2D _SubTex;

        struct Input
        {
            float2 uv_MainTex;
            float2 uv_SubTex;
        };

        float _Lerp;
        float _BrightnessMain;
        float _BrightnessSub;

        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            // Albedo comes from a texture tinted by color
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            fixed4 d = tex2D (_SubTex, IN.uv_SubTex);
            o.Albedo = lerp(c.rgb + _BrightnessMain/3, d.rgb + _BrightnessSub, 1-c.a);
            
        }
        ENDCG
    }
    FallBack "Diffuse"
}
728x90