Converting some code shaders to ShaderGraph



Converting some code shaders to ShaderGraph

금별 3 1,336 2020.02.27 16:15

 

A follow-up to the Shader Graph intro, please read that one first if you haven't already! 

In this post I'm converting a few of the shaders I've made in the past into ShaderGraph, (the UnityPackage with all these files will go up soon :) )

Toon Lit

Original Shader (Code) : PasteBin Link 

Since custom lighting is currently not supported by ShaderGraph (if this changes, I'll put up another post for it) the Toon Lit effect has to be faked.

Create a new PBR Shadergraph

Now, the most important part of the toon lit look is the lighting.

This underlined pieces of code are all we need to convert, so how do we do this? 

Lets take it one by one. The first line needs the light direction. There is currently no node for this, so this value needs to be added via script (A very simple script, don't worry!)

We send values to shaders using Shader.SetGlobal___ ,

Since the lighting part is fake, the light direction, and the light intensity need to be included:

Shader.SetGlobalVector("_LightDirectionVec", -transform.forward);
Shader.SetGlobalFloat("_LightIntensity", dirLight.intensity);

Here's the full script : PasteBin Link 

Drop this on your Directional Light, and drag the light into the slot

Now we can get to the graph

Create a Vector3 property with the reference "_LightDirectionVec", and a Vector1 with the reference "_LightIntensity"

Make sure they are not exposed, and give them a value so the preview looks right

Here's the first line of the code, normalize the light direction. Converting code into nodes is a lot of thinking backwards, you plug the value into the function in nodes, instead of typing the fuction with the value inside in code.

So for this add the Property: Light Direction, and plug it into a Normalize node.

For this line, we need a Dot Product node, and plug in a (world)Normal Vector, and the result of the Normalize Light Direction

Next line is a bit more complicated, the SmoothStep node takes 3 inputs. The IN of Smoothstep will be the Dot Product, the 2 Edge inputs are the Offset(Vector1), and a slightly bigger value for smoothness, which is the Offset + Blur(Vector1) value. Convert these Vector1 into properties to control them in the material settings.

Before adding the _ToonTint(Color) value, the _LightIntensity needs to multiplied, it's not in the code, but is needed to fake the lighting.

Just needs a texture now,
Because the lighting is faked, this part goes a bit simpler, just add a Texture Node(convert to property), and a Sampler Texture 2D, then multiply with the lighting ramp result.

PBR Master needs to be set to Specular Workflow, with Specular set to black, and Occlusion set to something like 3. 

There it is, fake toon lighting :)

Full graph image is here, and graph file is attached

Iridescent

A simple, weird one this time, based on the Iridescent Tip 

Looking at the relevant lines, the first two can be done with handy built-in nodes.

(There is also simple noise, and gradient noise to play with, instead of Voronoi)
Fresnel Effect node is great, you can turn the Power into a property if you want for more control

Line 3. is just a texture + sample 2D, as seen before.

Instead of plugging the UV into the Sample Texture, plug in the Fresnel Effect + Noise, then multiply a Color property

Finally, add the Texture, and the iridescent effect with a slider for Brightness

Image of Full Graph 

Snow

Based on the Snow Shader Tip 

This one is a bit more complicated because of vertex manipulation

Here are the relevant lines, both vertex and surface use a Dotproduct of the normal and snowDirection, so lets start with that.

The result of this node is used in all other parts of the shader.

Multiply the Normal with the SnowHeight value, then multiply with the step result to only affect the top area. add this to Position (Object) to add a layer on top of the object, plug this result into Position of the Master Node.

For the non-snowy part, just create a texture + sample 2D like before, and invert the step result using One Minus

The Fresnel Effect node takes up most of the code here. Color the result, then multiply with the step result. Add the snow and non-snow parts together and you're done!

Image of the full graph 

 

Hope this helped you understand a bit more on how to convert code into graphs, a lot of is just searching the values and functions and finding the right node that way :)

 

Thanks for reading, and have fun!

Iridescent.shadergraph

Snow.shadergraph

ToonLit.shadergraph

Comments

키자비 2020.02.27 23:16
좋은 자료 감사합니다~^
커피맥주 2020.09.14 01:21
링크된 그림이 깨져서 이제 안보이네요 ㅠㅠ
금별 2020.09.14 18:06
https://www.patreon.com/posts/24781996

여기 원문입니다. 링크다깨졌군요 ㅠㅠ

번호 포토 분류 제목 글쓴이 날짜 조회
792 유니티 유니티 - 흐르듯 사라지는 2D 카드 이펙트/트레일 제작과정 금별 04.10 225
791 언리얼4 린반라이브 - 초급 최신 리뉴얼 정보 및 QNA / 사소한 라이브 금별 04.09 164
790 언리얼4 언리얼5 - 값싸고 유동적인 폭포제작과정(한글자막) 금별 04.07 198
789 언리얼4 린반 언리얼 이펙트 라이브(3.27일자) - Texcoord 여러가지 설명 외 금별 04.03 149
788 언리얼4 언리얼5 - 나이아가라의 실용적인 최적화와 확장성【CEDEC2023】 금별 04.03 218
787 언리얼4 언리얼/유니티 - 파티클 이미터 기본사이즈 설명(영어자막) 금별 04.01 161
786 언리얼4 언리얼/유니티 - 파티클 빌보드 시스템 소개(영어자막) 금별 04.01 142
785 2D 픽셀 컴포저 - 노드 기반 픽셀 이미지,플립북 제작 금별 04.01 141
784 언리얼4 언리얼 - 엠버젠활용한 볼륨의 랜덤 회전 생성 적용 간단팁 금별 04.01 145
783 2D 애프터이펙트 - Water Escape 제작방법(한글자막) 금별 03.28 198
782 언리얼4 언리얼5.4 - 나이아가라의 메모가 파라미터마다 재편집가능 금별 03.28 158
781 공구,번역정보 언리얼 - 커스텀 뷰 모드를 위한 포스트 프로세스 머티리얼 금별 03.28 166
780 언리얼4 언리얼 - 눈 셰이더에 디더링 간단 적용노드 및 예제이미지 금별 03.28 156
779 언리얼4 언리얼 - 셰이더 토이를 활용한 커스텀 머트리얼 표현식 사용법(한글자막) 금별 03.28 135
778 2D 포토샵/언리얼5 - 게임 VFX용 페인트 트레일 텍스처를 드로잉으로 처리하는 방법 금별 03.25 210
777 언리얼4 언리얼 - 그레이스케일 그라디언트/텍스처를 시각화하는 간단한 방법 사진링크new 금별 03.21 274
776 언리얼4 언리얼 - 먹물 느낌의 검기 효과 제작과정(한글자막) 금별 03.21 261
775 2D 섭스턴스디자인/언리얼적용 - 분화구형 크랙 텍스쳐 제작과정(한글자막) 금별 03.21 253
774 유니티 유니티/포토샵 - 불속성/물속성 소드 슬래시 간단 제작과정(한글자막) 금별 03.19 283
773 3D 블랜더를 활용한 매직 오브 제작과정(머트리얼메이커) 금별 03.19 182
772 2D 포토샵 - 리얼한 연기 간단 제작과정 금별 03.19 216
771 유니티 유니티 - 2D 형태 충격파 궁극기 제작과정 금별 03.17 309

 

Banner
 
Facebook Twitter GooglePlus KakaoStory NaverBand