본문 바로가기
셰이더 (Shader)/유니티 쉐이더 스타트업 - 정종필

[Unity/Shader] 파트17-1 : 커스텀 제어 가능한 알파 블렌딩

by Minkyu Lee 2023. 8. 30.

모든 문제가 발생하는 전형적인 알파 블렌딩 쉐이더이다.

단, 명시적으로 선언된 부분만 다르다.

 

명시적으로 선언된 부분은 다음과 같다.

1. z 버퍼에 쓸 것인지 여부

2. 블렌드 펙터로 블렌딩을 제어

 

코드

Shader "Custom/part17-1"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Transparent" "Queue"="Transparent" } // *
        zwrite off // zwrite 끄고 켜기 옵션
        blend SrcAlpha OneMinusSrcAlpha // blend 펙터
        LOD 200

        CGPROGRAM
        #pragma surface surf Lambert keepalpha // *
        #pragma target 3.0

        sampler2D _MainTex;

        struct Input
        {
            float2 uv_MainTex;
        };

        UNITY_INSTANCING_BUFFER_START(Props)
            // put more per-instance properties here
        UNITY_INSTANCING_BUFFER_END(Props)

        void surf (Input IN, inout SurfaceOutput o)
        {
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            o.Albedo = c.rgb;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Legacy Shaders/Transparent/VertexLit" // *
}

댓글