티스토리 뷰
Shader Variants란 #ifdef #else #endif등의 조건부 컴파일 지시자에 의해 미리 쉐이더를 컴파일 해둔 파생 쉐이더.
쉐이더 도입부에서 #pragma multi_compile KEYWORD1 KEYWORD2 등의 명령어로 어떤 키워드가 사용될지 미리 선언해야함.
#pragma surface surf Lambert noshadow nofog
쉐이더에서 자동으로 생성되는 Variants (docs.unity3d.com/2019.4/Documentation/Manual/SL-SurfaceShaders.html)
Unity - Manual: Writing Surface Shaders
Surface Shaders and rendering paths Writing Surface Shaders Writing shadersA small script that contains the mathematical calculations and algorithms for calculating the Color of each pixel rendered, based on the lighting input and the Material configuratio
docs.unity3d.com
shader_feature KEYWORD
해당 키워드를 사용하는지 안하는지를 검사해서 사용하지 않는 키워드는 빌드에 포함시키지 않음.
다만, 런타임에 변경하게되면 아래의 멀티컴파일을 사용해야함.
multi_compile KEYWORD
해당 키워드를 사용하지 않더라도 전부 빌드에 포함시킴
다만, 전체 키워드는 256개로 숫자제한이 있음. 그리고 엔진에서 기본적으로 사용하고도 있어서 부족할 수 있다.
docs.unity3d.com/kr/current/Manual/SL-MultipleProgramVariants.html
여러 셰이더 프로그램 배리언트 만들기 - Unity 매뉴얼
셰이더 코드 조각 대부분을 고정시키되 약간 다른 셰이더 “배리언트”가 생성될 수 있게 하면 편리합니다. 일반적으로 “메가 셰이더” 또는 “우버 셰이더”라고 하며, 각 경우마다 다른 프
docs.unity3d.com
MaterialPropertyDrawer
커스텀에디터없이 머티리얼의 프로퍼티에 조건이나 선택을 걸어주는 것을 MaterialPropertyDrawer라고함.
docs.unity3d.com/kr/current/ScriptReference/MaterialPropertyDrawer.html
UnityEditor.MaterialPropertyDrawer - Unity 스크립팅 API
Base class to derive custom material property drawers from.
docs.unity3d.com
- Toggle : on/off 상태, on상태의 쉐이터 키워드를 제공함
- Enum : enum형태로 값이 지정된 팝업메뉴제공
- KeywordEnum : 해당속성에 대한 팝업메뉴를 표시하고, 해당 쉐이더키워드를 제공함
- PowerSlider : 비선형으로 동작하는 슬라이더
- IntRange : int타입의 슬라이더
- Space : inspector에 공백추가
- Hearder : inspector에 설명문구 추가
참고로 Toggle에 의해 세팅되는 키워드는 "프로퍼티명(대문자) + 밑줄 + ON"의 규칙으로 세팅
멀티컴파일이 적용되려면 #progma multi_compile(shader_feature) 명령이 추가되어야함.
Toggle키워드는 On에 해당되는 키워드 하나만 세팅되지만 KeywordEnum은 최소 두개의 키워드가 머티리얼에 세팅됨. 예를 들어 Toggle은 off 상태일때 TOGGLE_ON 키워드가 삭제되지만 KeywordEnum은 KEYWORDENUM_OFF가 세팅되기에 단순 on/off에서는 toggle을 사용하는것이 좋다.
'Unity > Shader' 카테고리의 다른 글
Summary of Built-in vs URP differences (0) | 2021.01.25 |
---|---|
ShadowCaster & DepthOnly Passes (0) | 2021.01.25 |
PBR Lighting (0) | 2021.01.25 |
Lighting Introduction (0) | 2021.01.22 |
Keywords & Shader Variants (0) | 2021.01.22 |
- Total
- Today
- Yesterday