Converting some code shaders to ShaderGraph



Converting some code shaders to ShaderGraph

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

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

번호 포토 분류 제목 글쓴이 날짜 조회
952 3D [아르카도님 번역]【CAPCOM RE 2019】데빌메이크라이5에 VFX해설 금별 2020.02.10 2865
951 2D 포토샵 - 간단한 4장 시퀀스 번개 제작방법 금별 2023.04.08 2858
950 언리얼4 [NDC] 〈드래곤하운드〉 비주얼이펙트 연출 (언리얼4) 댓글+1 금별 2019.07.18 2857
949 유니티 유니티 이펙트 튜토리얼 - 데몬즈 소울 느낌의 자연스러운 디졸브 사라짐 효과 금별 2021.04.01 2827
948 유니티 유니티 VFX 그래프 - Kassadin Slash 제작방법 금별 2022.12.14 2824
947 유니티 유니티 - 기어즈5 Hammer of Dawn 이펙트 만들기 댓글+1 금별 2020.05.16 2818
946 유니티 유니티 - Christmas Lootbox 이펙트 / 제작과정 사진 금별 2021.02.04 2815
945 유니티 유니티 - 피어나는 꽃봉오리 효과 제작과정영상 금별 2022.08.25 2814
944 유니티 유니티 VFX 그래프 - 특정 캐릭이미지를 생성하는 불꽃놀이 제작방법 금별 2022.11.23 2814
943 2D 포토샵 - 간단한 플레어 제작방법 금별 2022.09.14 2811
942 언리얼4 언리얼 - 광역 마법진 간단 제작예제 금별 2022.12.11 2811
941 언리얼4 언리얼4 - 블랜더를 활용한 지형 버텍스 옵셋 이펙트 팁 금별 2019.11.19 2809
940 유니티 유니티 앰플리파이 쉐이더 - 카툰느낌 불 소재 제작방법(중국어) 금별 2022.09.08 2805
939 언리얼4 언리얼4 머터리얼 튜토리얼 - Procedural 노이즈제작 금별 2020.03.26 2799
938 유니티 유니티 - 달 움직임 쉐이더 표현 금별 2021.12.30 2797
937 언리얼4 언리얼5 - 얼음 재질 노드 제작과정 금별 2023.06.25 2794
936 언리얼4 언리얼 - 캐릭이 액체화되는 효과 제작방법 금별 2022.10.06 2790
935 유니티 유니티 VFX 그래프 - Sci-fi 스폰 이펙트 튜토리얼 금별 2022.09.21 2787
934 유니티 유니티 이펙트 - 버택스 옵셋, 음악 리듬 머터리얼 만들기(중국어) 동영상new 금별 2021.11.01 2767
933 언리얼4 언리얼4 튜토리얼 - 심리스 형태의 Animated 노이즈제작 금별 2020.01.31 2756
932 유니티 유니티 - 스크립트를 활용한 레이저 빔 효과 제작과정 금별 2023.11.29 2756
931 언리얼4 언리얼4 - 버블쉐이더 금별 2019.08.20 2755

 

Banner
 
Facebook Twitter GooglePlus KakaoStory NaverBand