Unity/그래픽스프로그래밍

0510_ 알파 테스트와 컷 아웃

minquu 2021. 5. 10. 11:20
반응형

먼저 그리는 순서를   z - buffer 라고한다.

 

오버드로우, 뒤 쪽에 있는 걸 먼저그리는 것

z 버퍼는 카메라에 무얼 먼저 그릴지를 선택하는 것

알파블랜딩
오브젝트들을 그리는 순서가 정해져 있지 않다.
오브젝트들이 그려질떄마다  z 버퍼를 참고해서
앞뒤 판정을 한다.
그리고 그려질 픽셀과 안그려질 픽셀을 결정한다.

Z버퍼링
이미지 심도 좌표 관리방식이며,
어떤 물체가 그려질 떄 만들어진 픽셀의 깊이 정보는 버퍼에 저장된다.

1.불투명이 먼저 그린다.
2.반투명을 나중에 그린다.
3.반투명인 물체들은 멀리있는 것부터 가까운것까지 차례대로

풀 이미지한장받는거 만들어서
풀 넣고
 Tags { "RenderType"="Transparent" "Queue" =  "Transparent"}
 alpha:fade

해서 풀만 보에기하기 

태그 밑에 
Cull off 해주면 양면을 보임


FallBack "Diffuse"
}

지정해주않으면 기본으로 하는 쉐이더 

FallBack "Legacy Shaders/Transparent/VertexLit"
// 그림자를 없애는 코드

으로 바꿔주기  


Transparent  계열은 그림자 안나온다.

Tags { "RenderType"="Transparent" "Queue" =  "AlphaTest"}

알파테스트는 z 버퍼에서 필요하지 않은 부분은 렌더링 하지 않겠다는
것을 의미함

 

 

CutOff 를 사용한다.

 

 

 

 

Shader "Custom/Glass"
{
    Properties
    {
        _MainColor("Color", Color) = (1,1,1,1)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _CutOff("Alpha cutoff", Range(0,1)) = 0.5
    }
    SubShader
    {
        Tags { "RenderType"="Transparent" "Queue" =  "AlphaTest"}
        LOD 200

        Cull off

        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types
        #pragma surface surf Standard alphatest:_CutOff

        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0

        sampler2D _MainTex;

        struct Input
        {
            float2 uv_MainTex;
        };

        

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

 

 

폴백에서 트랜스퍼렌트/ 컷아웃를 해줘야지 그림자가 생긴다.

 

 

        _CutOff("Alpha cutoff", Range(0,1)) = 0.5

 

컷오프는 알파를 짜르는 정도 

 

 

 

 

#pragma 안에 Cutoff가 있어야지 먹힘 

 

 

------

 

최종적으로

 

 

Shader "Custom/Glass"
{
    Properties
    {
        _Color("Color", Color) = (1,1,1,1)
        _MainTex("Albedo (RGB)", 2D) = "white" {}
        _Cutoff("Alpha cutoff", Range(0,1)) = 0.5
    }
        SubShader
        {
            Tags { "RenderType" = "TransparentCutout" "Queue" = "AlphaTest"}
            LOD 200

            Cull off

            CGPROGRAM

            #pragma surface surf Standard alphatest:_Cutoff
            #pragma target 3.0

            sampler2D _MainTex;

            struct Input
            {
                float2 uv_MainTex;
            };



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

 

 

Cutoff 임  O가 대문자 아님! 주의!!

 

이걸 하는 이유는 알파로 빠진 부분은 그림자로 생성이 되지 않게 하기 위함임

 

* 컬러를 반드시 받아야한다.

 

 

 

 

 

반응형