애니메이터

Unity 엔진의 내장 쉐이더 본문

카테고리 없음

Unity 엔진의 내장 쉐이더

욤마핫 2018. 6. 26. 09:33

Unity Editor에서는 내장된 쉐이더를 볼 수 없다. 모든 Built in Shader는 이미 Compile이 완료된 형태로 존재 하므로 기본 제공 쉐이더들이 어떻게 작성되었나 참고하려면 직접 다운 받아야 한다.

 

Unity download archive 위치 : https://unity3d.com/kr/get-unity/download/archive?_ga=2.34527777.1410280179.1529972917-657720498.1512367994

 

에서 원하는 Unity 버전으로 가서 다운로드 메뉴를 열어서 "내장 셰이더"를 다운로드 한다.

 

다운로드 받은 파일의 압축을 풀면~

 

이런식으로 *.shader 파일들이 나타난다.

각 셰이더 파일은 Monodevelop 등에서 열어 보면 됩니다.

 

참고 - Unlit-AlphaTest.shader


 

// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)

// Unlit alpha-cutout shader.
// - no lighting
// - no lightmap support
// - no per-material color

Shader "Unlit/Transparent Cutout" {
Properties {
    _MainTex ("Base (RGB) Trans (A)"2D) = "white" {}
    _Cutoff ("Alpha cutoff"Range(0,1)) = 0.5
}
SubShader {
    Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
    LOD 100

    Lighting Off

    Pass {  
        CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #pragma target 2.0
            #pragma multi_compile_fog
            
            #include "UnityCG.cginc"

            struct appdata_t {
                float4 vertex : POSITION;
                float2 texcoord : TEXCOORD0;
                UNITY_VERTEX_INPUT_INSTANCE_ID
            };

            struct v2f {
                float4 vertex : SV_POSITION;
                float2 texcoord : TEXCOORD0;
                UNITY_FOG_COORDS(1)
                UNITY_VERTEX_OUTPUT_STEREO
            };

            sampler2D _MainTex;
            float4 _MainTex_ST;
            fixed _Cutoff;

            v2f vert (appdata_t v)
            {
                v2f o;
                UNITY_SETUP_INSTANCE_ID(v);
                UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
                UNITY_TRANSFER_FOG(o,o.vertex);
                return o;
            }
            
            fixed4 frag (v2f i) : SV_Target
            {
                fixed4 col = tex2D(_MainTex, i.texcoord);
                clip(col.a - _Cutoff);
                UNITY_APPLY_FOG(i.fogCoord, col);
                return col;
            }
        ENDCG
    }
}

}