TA-Shader-文件 印度TA_Joyce分享的如何在u3d制造视差(Parallax)材质
发布于
2019-9-22
27027
27
TA资源类型
TA资源类型: 算法思路 
shader资源类型: 其它 
适用引擎: unity 
资源介绍: -

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

x
本帖最后由 幺九 于 2021-2-18 20:19 编辑

价格:36 元素币 收益:5148元素币 销量:143

尊敬的游客 ,本内容需要支付后可见.
您可以[充值][发帖] [悬赏] [任务]来赚取积分。

因论坛限制gif大小,该购买链接为本文章所有高清配图
价格:1 元素币 收益:98元素币 销量:98

尊敬的游客 ,本内容需要支付后可见.
您可以[充值][发帖] [悬赏] [任务]来赚取积分。

11_看图王.jpg
835675d88989491099.png


I've played around a little with parallax effects in the Procgen Eyeball shader .
But there are more visuals you can use this effect for.
So in this post i'll show off a few experiments/examples.

Eyeball shader
Shader Code请查看购买资源里的名为Eyeball shader的文本)

What is Parallax?It's the effect of fake depth by moving UVs using the view direction

This plane is flat, but has a lot of fake depth in it.First, how to set it up:  
Parallax offset
Unity already has a built-in function that handles the calculation for a parallax offset  



(From the unity github)
Here the h is a texture sample of a depthmap, height is the depth/strength of the parallax effect, and of course viewdir is the view direction
Let's use it in a basic shader:
Create a new surface shader and declare a few extra properties

    _DepthMap("DepthMap", 2D) = "black" {}
    _Normal("Normal", 2D) = "bump" {}
    _Parallax("Parallax Depth", Range(0,10)) = 0.0
And don't forget to declare under the Input struct too!

To use the depth map, project it to uv's just like a regular texture:

     float dTex = tex2D(_DepthMap, IN.uv_MainTex).r;

Only a single channel is needed for the float, so grab the .r

As you've seen in the code above, the View Direction is also needed, so declare a "float3 viewDir;" in the struct Input to access the built-in variable. In the Input struct, also add a uv for the normal map :"float2 uv_Normal;"

    float2 parallax = ParallaxOffset( dTex , _Parallax, IN.viewDir);
This is the offset to add to the uv map

    o.Normal = UnpackNormal(tex2D(_Normal, IN.uv_Normal + parallax));
And thats it for the most basic parallax effect on the normal map.

Note: If you don't setup o.Normal, Unity will use the world normals instead of the tangent normals you need for this effect, so even if you don't want to use a normal, add the line anyway, just keep the texture slot empty



It should look something like this
Settings:


Shader Code:(详见购买资源里basicparallax.shader文本)
So knowing this setup, what else can be done?
Instead of adding the parallax offset to the normal map, add it to the diffuse maintex

Now we get this strange deep liquid kinda look
Shader Code:(详见购买资源里basicparallaxdiffuse.shader文本)

Trying something different: What happens if you keep adding the parallax offset over eachother? You get this trippy layered floor effect, reminds me a bit of those infinity mirrors

    for (float i = 0; i < _Layers; i++)
    {
    IN.uv_MainTex += ParallaxOffset(tex2D(_DepthMap, IN.uv_MainTex), _Parallax, IN.viewDir);
    }
Just add onto the uv using a for-loop with a variable so you can set the amount of layers you want.

Shader Code: (详见购买资源里basicparallaxdiffuselayers.shader文本)
Settings:

Gemstones(宝石材质)


Here's an example combines the parallax effect with parts of the old Specular Shader(详见购买资源里toonlitspecular.shader文本) I made a while ago.
It has rim lighting, color gradient, and specular.


toonlitspecular(就是文中说的old Specular Shader)

Shader Code: (详见购买资源里的名为gemstone.shader文本)
Settings:



Ice(冰材质)


Similar to the gemstone, but this also has a GrabPass Distortion in it
Just make sure the Render Queue is set to Geometry + 1(2001), to avoid glitchy grabpass results
Shader Code: (详见购买资源里的名为parallaxicegrabpass.shader文本)

Settings:



You don't have to keep it static, throw a _Time.x in there with the texture UV's and you get this


Shader Code:(详见购买资源里的名为parallaxmoving.shader文本)

Textures to play with:(教程里用到的贴图,购买包里有)








Extra resources:
Harry did a nice post about parallax too in two parts: First(Also includes link on setting up Parallax in Shader Graph), Second
He shows off a layering effect that fades into the depth, I tried it out here V


















参与人数 5 元素币 +38 活跃度 +46
还没有设置签名!您可以在此展示你的链接,或者个人主页!

使用道具 举报 登录

回复 <
wrey  发表于 2019-9-23 10:17:06  
2#
TQL
回复 收起回复
使用道具
Check不是Check  发表于 2019-9-23 10:58:41  
3#
资源哪里好,肯定元素找
回复 收起回复
使用道具
Check不是Check  发表于 2019-9-23 11:20:44  
4#
将 parallax Depth的范围设置成(-1,10)之间还能模拟冰层的感觉
回复 收起回复
使用道具
我没有过去  发表于 2019-9-28 15:13:45  
5#
资源哪里好,肯定元素找
回复 收起回复
使用道具
cybbxp  发表于 2019-9-29 08:57:30  
6#
这个碉堡了嗷嗷
回复 收起回复
使用道具
qq_皮皮铎。_aAo  发表于 2019-10-11 19:52:21  
7#
厉害~~~~
回复 收起回复
使用道具
vc2015  发表于 2019-11-1 09:24:38  
8#
回复 收起回复
使用道具
虚文  发表于 2019-11-1 10:21:06  
9#
下载来试试
回复 收起回复
使用道具
b172386067  发表于 2019-11-5 10:54:41  
10#
感谢楼主分享资源
回复 收起回复
使用道具
b172386067  发表于 2019-11-5 10:55:08  
11#
真的是好资源
回复 收起回复
使用道具
囧囧有神  发表于 2019-11-6 09:20:31  
12#
感谢分享~~~~~~~~~~~~~~~~~~~~
回复 收起回复
使用道具
小小白1994  发表于 2019-11-20 17:53:14  
13#
感谢楼主分享
回复 收起回复
使用道具
fyh420464  发表于 2019-12-5 17:38:16  
14#

这个碉堡了嗷嗷,真的流弊啊,先取了
回复 收起回复
使用道具
CG一目连  发表于 2019-12-7 11:32:49  
15#
资源哪里好,肯定元素找
回复 收起回复
使用道具
小小白1994  发表于 2020-1-8 17:58:50  
16#
感谢楼主分享
回复 收起回复
使用道具
elementalfx  发表于 2020-2-25 10:19:13  
17#
感谢楼主分享
回复 收起回复
使用道具
hw9198  发表于 2020-4-28 16:32:39  
18#
666666666
回复 收起回复
使用道具
qq_噼里啪啦_ana  发表于 2020-6-8 13:16:52  
19#
元素帖子强,满满正能量
回复 收起回复
使用道具
无忧亦无怖  发表于 2020-7-11 18:46:58  
20#
资源哪里好,肯定元素找
回复 收起回复
使用道具
12下一页

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

元素动效狂 实名

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

  

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

长枪

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