TA-Shader-文件 外国TA Joyce 用SG制作逐渐卡通冰冻效果
发布于
2019-9-24
11338
3
TA资源类型
TA资源类型: 算法思路 
shader资源类型: SG节点 脚本文件 shader代码 
适用引擎: unity 
资源介绍: -

您需要 登录 才可以下载或查看,没有账号?注册

x
价格:24 元素币 百度网盘 收益:1032元素币 销量:43
尊敬的游客 ,本内容需要支付后可见.
您可以[充值][发帖] [悬赏] [任务]来赚取积分。
提醒使用【余额支付】需要: ¥2 余额

购买资源为directionallightshader.csIridescent.shadergraphSnow.shadergraphToonLit.shadergraph以及对应的高清连线图,还有toonlit代码
购买该资源包的游客请不要再购买下面高清连线图

文章原标题:Converting some code shaders to ShaderGraph

cover.jpg


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 1.gif


Original Shader (Code) :(详见购买资源里名为toonlit.txt的文本)


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 :(详见购买资源里的directionallightshader.cs)
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
价格:5 元素币 百度网盘 交易量 < 5
尊敬的游客 ,本内容需要支付后可见.
您可以[充值][发帖] [悬赏] [任务]来赚取积分。
提醒使用【余额支付】需要: ¥1 余额

(接下来是作者讲怎么运用了)


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(付费即可预览)
价格:10 元素币 百度网盘 交易量 < 5
尊敬的游客 ,本内容需要支付后可见.
您可以[充值][发帖] [悬赏] [任务]来赚取积分。
提醒使用【余额支付】需要: ¥1 余额



Snow



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 Full Graph(付费即可预览)
价格:5 元素币 百度网盘 收益:45元素币 销量:9
尊敬的游客 ,本内容需要支付后可见.
您可以[充值][发帖] [悬赏] [任务]来赚取积分。
提醒使用【余额支付】需要: ¥1 余额


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!

【元素推荐】印度TA_Joyce分享的如何在u3d制造视差(Parallax)材质
https://www.element3ds.com/tietui.php?233283.316597



















参与人数 2 元素币 +22 活跃度 +20 贡献值 +1
还没有设置签名!您可以在此展示你的链接,或者个人主页!

使用道具 举报 登录

回复 <
qq_Mr.Shi_Gge  发表于 2020-7-30 18:20:05  
2#
nice
回复 收起回复
使用道具
shadowgenius  发表于 2021-3-24 19:33:07  
3#
好东西,先MARK一个~
回复 收起回复
使用道具
123111111111111  发表于 2024-1-19 14:04:36  
4#
要是ase连的就好了
回复 收起回复
使用道具

快来发表你宝贵的意见吧!

元素动效狂 实名

通过了实名认证的内容创造者

  

主题
126
精华
18
超神
1
扩散
1318
微金
400
智慧
46
余额
5
在线时间
268 小时

长枪

快速回复 返回顶部 返回列表