rainyeve
  • 首页
  • 编程
  • 涂鸦
  • 其他
  • 关于
2019年11月21日
编程

【Unity Shader】简单模拟热空气扭曲效果

【Unity Shader】简单模拟热空气扭曲效果
2019年11月21日
编程

实现效果

扭曲效果最常见的有用于模拟热空气,模拟玻璃水晶透明物体遮罩等等。最近在做施放特别攻击和落地出场等效果,也用到了模拟热空气扭曲。只是简单地用粒子系统的上升模拟流体,要更完美模拟热空气的流动要再加上flow map计算。

冲刺动作身后栏杆处可以看出微小的扭曲效果
落地时模拟产生热空气

过程摘要

主要是实现一个扭曲屏幕像素位置的shader,再配合粒子动画来模拟热空气上升。Distortion Shader参考了Unity官方发布的Distortion Shader in Unity 2019 with Shader Graph! (Tutorial)。

Unity官方教程里面实现的扭曲还附带了菲涅尔反射的护盾效果

最核心的节点流程实际上只有3步。

  • 用一张NormalMap来取样,每个颜色点代表屏幕像素坐标将要被扭曲的程度, 对取样后的点做坐标系转换,从UV空间转化到屏幕空间,把ScreenPosition和SampleTexture的点做相乘即可
  • 做了空间转换后的点与原ScreenPosition相加,“扭曲”掉原有的坐标
  • 最后的SceneColor节点最巧妙,把屏幕坐标系当做UV,取屏幕的颜色赋值到材质上

Provides access to the current Camera‘s color buffer using input UV, which is expected to be normalized screen coordinates.

Scene Color Node Description

官方案例实现的Distortion只能控制ScreenPosition往同一个方向扭曲,只是每个点扭曲的程度不同,于是我加了一个噪声图,Remap之后取值范围是[-1,1],以此来控制扭曲的程度以及方向,使得扭曲更扭曲。

Distortion Shader
用Cube来预览扭曲效果

细节

Shader Graph Scene Color Node

Unity Shader Graph的Scene Color节点在LWRP里面使用,必须开启LWRP Asset中的Opaque Texture选项,因为Scene Color节点使用的贴图Camera Opaque Texture,LWRP默认情况下是没有把屏幕颜色写入该贴图的,详见Scene Color Node说明。

Note: The behaviour of this Node is undefined globally. The executed HLSL code for this Node is defined per Render Pipeline, and different Render Pipelines may produce different results. Custom Render Pipelines that wish to support this Node will also need to explicitly define the behaviour for it. If undefined this Node will return 0 (black).

Scene Color Node Note

Note: In Lightweight Render Pipeline this Node returns the value of the Camera Opaque Texture. See the Lightweight Render Pipeline for more documentation on this feature. The contents of this texture are only available for Transparent objects. Set the Surface Type dropdown on the Material Options panel of the Master Node to Transparent to receive the correct values from this node.

Scene Color Node Note
LWRP Asset的Opaque Texture开关

Particle System Sorting Fudge

Unity粒子系统的sorting fudge可控制粒子显示层级,不想Distortion粒子遮断了某些其他特效,可以把sorting fudge调大。

end

Post Views: 9,270

shader unity3d 粒子系统

上一篇【涂鸦】祢豆子下一篇 【Animation Rigging】Jiggle Chain实现树枝晃动+Shader动画实现花草晃动

分类目录

  • 其他 (2)
  • 旅行 (1)
  • 涂鸦 (6)
  • 编程 (28)
Email: wuch441692@163.com