Unity Shader实现径向模糊效果
作者:会编程的小毛驴 时间:2021-09-06 01:02:47
在游戏里面有很多模糊效果,像赛车类游戏。当你加速时,会发现2边的场景变模糊。如下图:
今天也来做一下径向模糊效果,首先创建一个Material,给它添加一个纹理后将Material拖到新建的Plane上。如图所示,可以看出模糊效果是从中心点由内往外扩散。接下来脑子里有了步骤
步骤一:定义径向模糊的中心点,通常取图像的正中心点。
步骤二:计算采样像素与中心点的距离,根据距离确定偏移程度,即离中心点越远,偏移量越大。
步骤三:将采样点的颜色值做平均求和。
Shader "liulongling/motion" {
Properties {
_MainTex("纹理",2D)="while"{}
_Level("强度",Range(0,100))=10
}
SubShader {
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "unitycg.cginc"
sampler2D _MainTex;
float _Level;
struct v2f{
fixed4 vertex:POSITION;
fixed2 uv:TEXCOORD;
};
v2f vert(appdata_base v){
v2f o;
o.vertex=mul(UNITY_MATRIX_MVP,v.vertex);
o.uv=v.texcoord;
return o;
}
fixed4 frag(v2f i):COLOR{
fixed4 c;
fixed2 center=fixed2(.5,.5);
fixed2 uv=i.uv-center;
fixed3 c1=fixed3(0,0,0);
for(fixed j=0;j<_Level;j++){
c1+=tex2D(_MainTex,uv*(1-0.01*j)+center).rgb;
}
c.rgb=c1/_Level;
c.a=1;
return c;
}
ENDCG
}
}
}
效果如下:
来源:https://blog.csdn.net/liulongling/article/details/50787445
标签:Unity,Shader,径向模糊
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java 信号量Semaphore的实现
2023-06-19 11:00:34
Java和C++通过new创建的对象有何区别?
2022-02-07 10:06:10
![](https://img.aspxhome.com/file/2023/9/67019_0s.png)
一文彻底搞懂Java和JDK的版本命名问题
2023-11-24 01:39:25
![](https://img.aspxhome.com/file/2023/6/59576_0s.jpg)
关于Spring BeanPostProcessor的执行顺序
2022-03-17 23:53:41
![](https://img.aspxhome.com/file/2023/2/67122_0s.jpg)
Java异常处理机制try catch流程详解
2022-09-23 08:51:09
![](https://img.aspxhome.com/file/2023/4/62404_0s.png)
浅谈Java自定义类加载器及JVM自带的类加载器之间的交互关系
2021-09-12 23:37:24
![](https://img.aspxhome.com/file/2023/0/66510_0s.jpg)
SpringMvc微信支付回调示例代码
2023-01-24 08:00:03
Android studio中生成引用.aar和.jar的方法详解
2023-09-29 07:48:33
![](https://img.aspxhome.com/file/2023/3/82393_0s.png)
一个Servlet是如何处理多个请求的?
2023-01-18 11:19:32
![](https://img.aspxhome.com/file/2023/5/70495_0s.png)
Java设计模式之模板方法模式详解
2021-08-04 04:32:51
![](https://img.aspxhome.com/file/2023/2/70292_0s.png)
深入理解Java设计模式之命令模式
2023-11-24 11:06:31
![](https://img.aspxhome.com/file/2023/4/59684_0s.jpg)
Java之如何关闭流
2023-11-04 21:29:11
Java经典排序算法之插入排序
2022-08-29 11:08:39
![](https://img.aspxhome.com/file/2023/7/72367_0s.jpg)
详解SpringBoot 快速整合Mybatis(去XML化+注解进阶)
2022-02-19 03:54:29
![](https://img.aspxhome.com/file/2023/9/65359_0s.png)
IOS与网页JS交互详解及实例
2023-07-08 11:58:20
Java 求解如何把二叉搜索树转换为累加树
2021-11-19 14:09:54
![](https://img.aspxhome.com/file/2023/8/61018_0s.png)
JAVA如何按字节截取字符串
2023-11-25 13:31:41
关于JWT之token令牌认证登录
2022-03-16 07:32:58
![](https://img.aspxhome.com/file/2023/8/69918_0s.png)
IDEA + Maven环境下的SSM框架整合及搭建过程
2023-08-26 02:06:55
![](https://img.aspxhome.com/file/2023/3/58423_0s.jpg)
Java中checkbox实现跨页多选的方法
2023-10-14 11:01:20