【Unity】从零使用Amplify Shader - 屏幕抓取与扭曲

前言:

很多实际项目中,我们都需要对当前整个屏幕进行一些特殊处理,那再ASE中其实可以非常快速的实现,下面就跟着教程试试吧。

创建材质:

● 右键 - Create - Amplify Shader - Legacy - Unlit
● 在创建出的Shader上右键 - Create - Material - 起个名字
● 打开ASE编辑器。

初步实现:
  • 在ASE中,想要抓取屏幕内容,只需要了解两个最重要的节点:
    • Screen Position - 屏幕坐标
    • Grab Screen Color - 当前屏幕颜色

在这里插入图片描述

  • 在这里我们首先连接了一个 Component Mask,这也是我们第一次用到这个节点,它的意义也很简单,知道Mask的概念就能懂一半:筛选我们需要的内容,这里因为我们只需要屏幕的二维坐标也就是XY,所以勾选XY即可。
  • 接下来就直接将屏幕坐标连接到Grab Screen Color节点的UV上,最后输出颜色到片元着色Frag Color。
  • 到此为止我们已经可以获得屏幕信息了,可以利用一个2D Sprite来测试一下。
扭曲
  • 这一步操作算是重点了,折射(扭曲)。虽然是重点,但其实也超简单!
  • 先直接上基本完成图,首先把几个控制变量忽略不看。那么就剩下Panner,Texture和Lerp三个节点了。
    • Lerp是核心,作用是对屏幕UV进行了一个插值。 这里给出公式:lerp(a, b, f) //(1-f)a + bf , 简单理解就是B向着A混合。
    • Panner是让UV滚动起来,这里Speed在Y方向-1也就是在Y方向进行滚动。
    • Texture就没什么可说的,用它的R的值来做插值混合,这里用黑底渐变图是为了让图形周围更圆滑,不像矩形那么锋利,可以从接下来的图中看到。

在这里插入图片描述

  • 记得给Lerp的Alpha的控制变量赋值才能看到变化。
  • 那么我们在屏幕中随便给一张背景图片,然后再添加一个2D Sprite矩形测试后的结果如下:
  • 在这里插入图片描述
  • 最后,调整一下截图的尺寸,然后像上面提到的替换一些圆滑的贴图到Texture节点。可以看到动起来以后的画面了:

请添加图片描述

总结:

到上面为止,基本折射扭曲的概念和示例已经差不多结束了,但是值得注意的是,这种全屏操作是非常消耗性能的,因为每帧都会去截取屏幕图形,使用的时候需要慎重考虑。那实际应用中都用在什么地方呢?举个例子:一个类似黑洞的子弹,这种持续时间短且会回收的资源,用一下这样的shader还是性能可接收的。但是用在子弹上多数情况就需要使用粒子,提示这个材质要用在粒子上,需要一个额外节点Vertex Color顶点色,具体大家自己去尝试一下吧

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
NEW! Support for Lightweight SRP NEW! Multi-Pass on Templates NEW! Compatibility with Unity 2018 NEW! Xbox One/PS4/Switch Support NEW! Texture Array Creator tool NEW! Terrain support NEW! Shader Templates • Lightweight PBR SRP • Lightweight Unlit SRP • Post-Process effects • Alpha-Blended particles • Sprite • Unlit • UI New Samples • SRP Lightweight 2D Fractal • Projectors • XRay • Single Channel Masking by Sarah Akers and David Marshall • Stylized Skybox by BOXOPHOBIC • Melting by Gil Damoiseaux New Shader Functions • Detail Albedo • Fetch Lightmap Value • Lerp White To New Template • Lightweight Unlit SRP New Nodes • Transform Position • Transform Direction Latest Improvements • Amplify Shader Editor now supports Lightweight SRP v1.1.10 via templates. • Support for Specular workflow into Lightweight PBR SRP template. • Templates can now be Multi-Pass. • Amplify Shader Editor is now compatible with Unity 2018. • Official support for Xbox One/PS4/Switch. • Texture Array Creator tool now also creates 3D Textures. • Can create terrain shaders, completely from within ASE without external editing required. • Improved templates loading behavior after hot code reload. • Pragmas, Defines and Includes are now set over a single reorderable list. • Blend, Cull, Stencil, Color Mask and Depth options can now reference properties. • Properties now can have custom attributes. • Improved editor rendering pipeline leading to huge performance boost. • Reduced editor memory allocations resulting on a low Garbage Collector impact. • Editor more snappy and responsive when auto panning and zooming. • Multiple fixes over various nodes, editor and samples. Learn more: Amplify Wiki Discuss here: Unity Forum Thread Shader Samples: Full List The Editor will continue to be improved in future updates, there are a lot more features currently in development. Notable Features • Full source-code • Support for Xbox One/PS4/Switch • Custom Node API • Shader Templates • Shader Functions • Multi

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值