Converting some code shaders to ShaderGraph



Converting some code shaders to ShaderGraph

금별 3 3,555 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

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

번호 포토 분류 제목 글쓴이 날짜 조회
640 언리얼4 11. 11일 카페 공인스터디 이펙트102 발표내용 일부 영상(네오도쿄챌린지/무기디졸브) 금별 2023.11.12 2708
639 언리얼4 언리얼5 - 머트리얼로 제어하는 책넘김 효과 예제 및 튜토리얼 링크 금별 2023.11.09 3705
638 언리얼4 언리얼5/후디니/섭디 - 불 발사체 제작과정 part2[후디니로 메쉬제작/섭디로 WPO텍스쳐] 금별 2023.11.08 2386
637 언리얼4 [게임 이펙트 소개 02] 쌤~ 게임이펙트 쉽나요? 취업 되나요? 금별 2023.11.08 2438
636 유니티 유니티 - 초간단 화염 회오리 제작과정 금별 2023.11.07 2706
635 2D COLOR for Visual Effects | RGB, Hue, Saturation, and Value 금별 2023.11.07 3037
634 언리얼4 언리얼엔진5 다운로드 / 엔진 설치하기 금별 2023.11.07 2047
633 언리얼4 Unreal 어서와! 이펙트는 처음이지? [게임 이펙트 소개 01] 금별 2023.11.07 2224
632 2D Timing and Spacing(애니메이션 타이밍의 이해) 금별 2023.11.05 2456
631 언리얼4 언리얼5 - Cursed Cannonballs & Gems 금별 2023.11.05 2430
630 언리얼4 언리얼 - 3DsMax 모델링|웨이브에 쓰이는 스태틱 메시 제작방법 금별 2023.11.04 2144
629 언리얼4 언리얼 렌더링 기본이론설명 [린반 초급반_미리보기] 금별 2023.11.04 2133
628 언리얼4 언리얼5/후디니/섭디 - 불 발사체 제작과정 part1[후디니로 메쉬제작/섭디로 WPO텍스쳐] 금별 2023.11.03 2932
627 3D 블랜더3D - 단계가 뚜렷한 카툰 불 머트리얼 노드 금별 2023.11.02 2511
626 언리얼4 언리얼5 - 떨어지는 잎새 표현 제작과정 금별 2023.11.01 2049
625 언리얼4 언리얼5 - 먼지 부유물 제작과정 금별 2023.11.01 2288
624 언리얼4 언리얼+후디니 - 엷은 안개 제작과정 금별 2023.11.01 2255
623 언리얼4 언리얼5 - The Jump Flood Algorithm 금별 2023.10.31 2154
622 언리얼4 언리얼5 - 동굴 입구 아우라 효과 제작과정 금별 2023.10.31 2178
621 3D 블랜더3D - 블랜더를 활용한 2D 폭포수 쉐이더 초간단제작방법 금별 2023.10.28 2682
620 유니티 유니티 - 솓구치는 물회오리 이펙트 프로젝트파일 금별 2023.10.28 3095
619 언리얼4 언리얼5 - Texture Streaming Pool Over Top tip [텍스처 사이즈 최적화] 금별 2023.10.27 1924

 

Banner
 
Facebook Twitter GooglePlus KakaoStory NaverBand