0504 쉐이더 특정 부분만 반짝거리게 하기

2021. 5. 4. 14:45unity/쉐이더

영역을 b와 r로 나누어 준다.
b와 r에 각자 다른 텍스쳐를 넣어놓고,
r영역에만 반짝거림을 더해서 물에 젖은 듯한 효과를 준다.

 

방법 #1.

Shader "Custom/rock"
{
    Properties
    {

        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _MainTex2("Albedo (RGB)", 2D) = "white" {}
        _BumpMap("Normal Map",2D) = "bump"{}
        _Glossiness ("Smoothness", Range(0,1)) = 0.5
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }


        CGPROGRAM

        #pragma surface surf Standard 


        sampler2D _MainTex;
        sampler2D _MainTex2;
        sampler2D _BumpMap;

        struct Input
        {
            float2 uv_MainTex;
            float2 uv_MainTex2;
            float2 uv_BumpMap;
            float4 color:COLOR;
        };

        half _Glossiness;
        half _Metallic;


        void surf (Input IN, inout SurfaceOutputStandard o)
        {

            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            fixed4 d = tex2D(_MainTex2, IN.uv_MainTex2);
            fixed3 n = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
            
            o.Albedo = c.rgb;
            //o.Albedo = IN.color.rgb;

            o.Albedo = lerp(o.Albedo, c, IN.color.r);
            o.Albedo = lerp(o.Albedo, d, IN.color.b);
            o.Smoothness = _Glossiness * IN.color.r;
            o.Normal = n;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

 

방법 #2. 더 정교하게 수치를 조장할 수 있도록

Shader "Custom/rock"
{
    Properties
    {

        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _MainTex2("Albedo (RGB)", 2D) = "white" {}
        _BumpMap("Normal Map",2D) = "bump"{}
        _Smoothness("Smoothness", Range(0,1)) = 0
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }


        CGPROGRAM

        #pragma surface surf Standard 


        sampler2D _MainTex;
        sampler2D _MainTex2;
        sampler2D _BumpMap;

        struct Input
        {
            float2 uv_MainTex;
            float2 uv_MainTex2;
            float2 uv_BumpMap;
            float4 color:COLOR;
        };

        half _Glossiness;
        half _Metallic;
        float _Smoothness;


        void surf (Input IN, inout SurfaceOutputStandard o)
        {

            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            fixed4 d = tex2D(_MainTex2, IN.uv_MainTex2);
            fixed3 n = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
            
            o.Albedo = c.rgb;
            //o.Albedo = IN.color.rgb;

            o.Albedo = lerp(o.Albedo, c, IN.color.r);
            o.Albedo = lerp(o.Albedo, d, IN.color.b);
            o.Smoothness = (IN.color.r * 0.5) * _Smoothness;
            
            o.Normal = n;
        }
        ENDCG
    }
    FallBack "Diffuse"
}