Unity/Shader

[5.4] PolyBrush & Vertex Color을 이용해서 특정 영역 색칠 후 텍스쳐 삽입

ljw4104 2021. 5. 4. 12:22

결과물 : Texture를 적용한 결과 / Vertex Color만 출력한 결과
PolyBrush 설정

  1. 모든 면을 검정으로 칠함 => 변수를 0으로 초기화 하는 것과 비슷한 맥락이다.
    1. Color Mask를 지정하지 않고 칠해도 된다.
  2. 특정 Texture가 들어갈 위치에 색을 칠한다.
  3. 코드로 연결 ( CG : lerp 함수 이용 )

Stone.shader

Shader "Custom/Stone"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _SubTex ("Albedo (RGB)", 2D) = "white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }

        CGPROGRAM
        #pragma surface surf Standard fullforwardshadows

        sampler2D _MainTex;
        sampler2D _SubTex;

        struct Input
        {
            float2 uv_MainTex;
            float2 uv_SubTex;
            float4 color:COLOR;
        };

        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            fixed4 d = tex2D (_SubTex, IN.uv_SubTex);

            //빨간색이 조금이라도 포함된 부분에 텍스쳐가 들어감.
            o.Albedo = lerp(c.rgb, d.rgb, IN.color.r);
            o.Alpha = c.a;

            //Vertex Color 색을 확인하기 위한 테스트 코드
            // o.Albedo = IN.color.rgb;
        }
        ENDCG
    }
    FallBack "Diffuse"
}