Unity/수업 내용

[Unity 2020.3] Alpha Shader 투명 오브젝트 뒷면까지 출력되는 문제

JSH1 2021. 11. 25. 17:40

 

Shader "Custom/AlphaBlend"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _BumpMap ("Normal Map", 2D) = "bump" {}
    }
    SubShader
    {
        Tags { "RenderType"="Transparent" "Queue"="Transparent" }

        CGPROGRAM

        #pragma surface surf Lambert alpha:blend

        sampler2D _MainTex, _BumpMap;

        struct Input
        {
            float2 uv_MainTex;
        };

        void surf (Input IN, inout SurfaceOutput o)
        {
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            o.Albedo = c.rgb;
            o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_MainTex));
            o.Alpha = 0.5;
        }

        ENDCG
    }
    FallBack "Diffuse"
}

 

Shader "Custom/AlphaBlend"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _BumpMap ("Normal Map", 2D) = "bump" {}
    }
    SubShader
    {
        Tags { "RenderType"="Transparent" "Queue"="Transparent" }

        ColorMask 0 

        CGPROGRAM

        #pragma surface surf _Unlit

        struct Input
        {
            float2 color:COLOR;
        };

        void surf (Input IN,inout SurfaceOutput o)
        {
        }

        float4 Lighting_Unlit(SurfaceOutput o, float3 lightDir, float atten)
        {
          return 0;
		}

        ENDCG
        
        ZWrite off // ZWrite의 기본값은 on 상태이다

        CGPROGRAM

        #pragma surface surf Lambert alpha:blend

        sampler2D _MainTex, _BumpMap;

        struct Input
        {
            float2 uv_MainTex;
        };

        void surf (Input IN, inout SurfaceOutput o)
        {
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            o.Albedo = c.rgb;
            o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_MainTex));
            o.Alpha = 0.5;
        }

        ENDCG
    }
    FallBack "Diffuse"
}