(유니티쉐이더) 02 유니버설 렌더링 파이프라인 쉐이더 그래프
이 포스트는 2020년 1월에 작성되었습니다. 현재의 유니티와는 다를 수 있습니다.

현재 제일 최신 정식 릴리즈인 2019.3.0f3 버전 입니다. 그렇습니다. 유니티가 결국엔 LWRP / HDRP 나누던거 다 그냥 URP 하나로 합쳤습니다.
URP로 들어오면서 언리얼 엔진처럼 노드로 쉐이더를 작성 할 수 있도록 Shader Graph 기능이 추가되었습니다. 우리는 쉐이더 그래프 기본 조작에 대해 알아볼 것입니다.

URP 프로젝트를 열면 기본적으로 에셋 몇개와 후처리, 리플렉션 / 라이트 프로브가 들어있는 기본 씬을 하나 던져줍니다. Hierarchy에서 카메라와 디렉셔널 라이트(Directional light)를 제외하고 깔끔하게 지워 줍시다.

에셋 창에서 우클릭하여 Create - Shader 의 목록을 보면 다음과 같이 저희가 찾던 그래프가 있습니다.
Unlit Graph
: Un-light. 단어 그대로 빛이 없는, 빛에 대한 연산을 하지 않는 쉐이더에 대한 노드 에디터 입니다.
PBR Graph
: 물리 기반 쉐이더를 작성하는 노드 에디터입니다.
VFX Shader Graph
: 이펙트에 사용되는 쉐이더를 제작할 때 사용하는 노드 에디터 입니다.
Sub Graph
: 언리얼의 메테리얼 인스턴스처럼 쉐이더에서 동작하고 재사용 할 수 있는 함수를 편집하는 노드 에디터 입니다.
PBR Graph를 선택하여 생성합니다.

PBR 그래프 아이콘을 더블 클릭을 하면 아래와 같은 창이 열립니다.

블랙보드 PBR 마스터 노드 프리뷰
블랙보드는 그래픽 아티스트가 메테리얼의 인스펙터(Inspector) 창에서 변수를 조작할 수 있도록 프로퍼티(Property)로 선언하는 부분입니다.
PBR 마스터 노드에서 모든 핵심 코드들을 작성하고 편집할 수 있습니다.
각 항목 괄호의 숫자는 변수가 가진 정보량을 나타냅니다. 예를 들어 버텍스 포지션 값은 X,Y,Z로 Vector3이기 때문에 (3)으로 적혀 있습니다.
이렇게 작성된 쉐이더 노드를 프리뷰 창에서 미리 볼 수 있습니다.

블랙보드에서 Vector1 변수를 추가해 봅시다.

Exposed 체크박스
: 체크박스에 체크가 되어 있다면 인스펙터 창에서 변수를 조작할 수 있습니다.
Reference
: 쉐이더 그래프 내부에서 프로그래머가 접근할 때 사용할 이름을 변경 할 수 있습니다.


Default
: 프로퍼티에서 제한 없는 값을 입력해줄 수 있습니다.

Slider
: 프로퍼티를 제한된 슬라이드의 형태로 만들어줍니다.

우클릭 할 경우 프로퍼티의 이름 자체를 변경 할 수 있습니다.

Precision
: 변수의 크기를 결정합니다.

Vector4 / Color
기본적으로 둘은 똑같습니다. 컬러의 RGBA와 벡터4의 XYZW가 대응하기 때문입니다.
Color 노드가 HDR 인터페이스를 사용한다는 것 외에는 차이가 없습니다.

위 처럼 벡터3의 X값에 1을 넣어도 컬러 노드의 빨강과 동일한 결과물이 나옵니다.


Texture2D / Cubemap
텍스쳐를 받는 노드입니다. 큐브맵 노드는 유니티의 큐브맵 스카이박스등에 사용됩니다.

Matrix
행렬 데이터를 받는 노드입니다. Exposed가 잠겨있고 쉐이더 그래프 에디터 내부에서만 작동합니다.
어느정도 변수 조작법에 대해 알았으니 기본적인 컬러 연산을 해봅시다. RGB는 가산혼합이기 때문에 더할수록 밝아집니다.

Vector의 합과 곱은 제대로 결과물이 나오는데 Color의 합과 곱은 결과물이 이상합니다..?


쉐이더 그래프에서 Color 노드는 sRGB 컬러 공간으로 인식을 하기 때문에 컬러 공간 변환 노드를 거쳐서 Linear를 RGB로 바꿔줘야 합니다...
Comments