均值模糊,也使用卷积来实现,之不过卷积中每个值均相等,且相加等于1。

代码如下,

子类:

 using UnityEngine;

 public class MeanBlurRenderer : PostEffectRenderer
{
protected override string ShaderName
{
get { return "Custom/Mean Blur"; }
}
}

MeanBlurRenderer

shader

 Shader "Custom/Mean Blur"
{
Properties
{
_MainTex("Main Texture", 2D) = "white" {}
} SubShader
{
Pass
{
Cull Off
ZWrite Off
ZTest Always CGPROGRAM
#pragma vertex vert
#pragma fragment frag sampler2D _MainTex;
float4 _MainTex_TexelSize; struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
}; struct v2f
{
float4 pos : SV_POSITION;
float2 uv[] : TEXCOORD0;
}; v2f vert(appdata v)
{
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv[] = v.uv + _MainTex_TexelSize.xy * float2(-, );
o.uv[] = v.uv + _MainTex_TexelSize.xy * float2(, );
o.uv[] = v.uv + _MainTex_TexelSize.xy * float2(, );
o.uv[] = v.uv + _MainTex_TexelSize.xy * float2(-, );
o.uv[] = v.uv + _MainTex_TexelSize.xy * float2(, );
o.uv[] = v.uv + _MainTex_TexelSize.xy * float2(, );
o.uv[] = v.uv + _MainTex_TexelSize.xy * float2(-, -);
o.uv[] = v.uv + _MainTex_TexelSize.xy * float2(, -);
o.uv[] = v.uv + _MainTex_TexelSize.xy * float2(, -);
return o;
} fixed4 frag(v2f i) : SV_TARGET
{
float4 col = float4(, , , );
for(int k = ; k < ; k++)
{
float4 tex = tex2D(_MainTex, i.uv[k]);
col += tex;
}
return col * 0.1111;
} ENDCG
}
} Fallback Off
}

效果,左边为正常,右边为均值模糊:

 

最新文章

  1. 解决:win10_x64 VMware Workstation and Hyper-V are not compatible. Remove the Hyper-V role from the system before running VMware Workstation
  2. wlan-mcs来自百度百科
  3. swift 项目 oc 和 swift 混用,文件相互引用
  4. 杭电ACM题目分类
  5. DW(二):SqlServer PDW
  6. 使用PyInstaller将Python程序打包成一个单独的exe文件
  7. MongoDB牛刀小试
  8. Debian5.04安装oracle11g 笔记
  9. JQuery设置缓慢下拉大行多次执行的解决办法,以及stop()函数的简单理解
  10. Java POI 两种导出方式
  11. 自适应SimpsonSimpson积分
  12. duilib之源码分析
  13. AjaxPro实现无刷新更新数据
  14. DELPHI XE5安装
  15. ASP.NET core1.0 EF MYSQL搭建中碰到几个问题记录
  16. React Native开发工具Nuclide使用
  17. H5内联视频总结
  18. veu——引入iconfont图标
  19. Java与JS判断请求来是否来自移动端
  20. hdu 4888 最大流慢板

热门文章

  1. 创建结点 与 分配内存 Function to create a Node. Allocates memory for a new node. 主动申请内存 链表 指针的写法
  2. java中获取字母和数字的组合
  3. Python开发【模块】:aiohttp(二)
  4. linux 修改密码命令
  5. linux strtock()函数使用问题
  6. 并查集——合作网络D306
  7. 跨域的问题(nginx解决才是王道)
  8. 第 7 章 Data 类型
  9. 给予Java初学者的学习路线建议
  10. tomcat 的acceptCount、acceptorThreadCount、maxConnections、maxThreads 如何确定