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

[Unity/Shader] 파트4-7 : 불필요 코드 삭제

by Minkyu Lee 2023. 8. 6.

불필요한 프로퍼티, 코드를 삭제하여 깔끔하게 만든다.

 

코드

Shader "Custom/chap05"
{
    Properties
    {
        _TestColor ("testcolor", Color) = (1,1,1,1)
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200 // 옵션 값 (삭제 가능)

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

        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0 // 쉐이더 모델 3.0 이상에서만 돌아가게 한다. 더 복잡한 코드 사용할 수 있다. (삭제 가능)


        struct Input
        {
            float4 color : COLOR; // 버텍스 컬러 받기. 구조체가 비어있다는 에러를 피하기 위해 썼다.
        };

        float4 _TestColor;

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

        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            o.Albedo = _TestColor.rgb;
            o.Alpha = 1; // c 변수가 없으니, 상수값으로 변경
        }
        ENDCG
    }
    FallBack "Diffuse"
}

 

핵심은 기본값으로 적힌 코드를 다 지우고

1. 구조체 안을 비우면 에러가 나니, 버텍스 컬러를 받은 것 (사용은 하지 않음)

2. 알파를 상수로 적은 것

두가지이다.

 

(삭제 가능)이라고 주석적힌 부분도 지워도 된다.

 

댓글