Unity shader学习之屏幕后期处理效果之均值模糊
2024-10-10 12:16:40
均值模糊,也使用卷积来实现,之不过卷积中每个值均相等,且相加等于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
}
效果,左边为正常,右边为均值模糊:
最新文章
- 解决:win10_x64 VMware Workstation and Hyper-V are not compatible. Remove the Hyper-V role from the system before running VMware Workstation
- wlan-mcs来自百度百科
- swift 项目 oc 和 swift 混用,文件相互引用
- 杭电ACM题目分类
- DW(二):SqlServer PDW
- 使用PyInstaller将Python程序打包成一个单独的exe文件
- MongoDB牛刀小试
- Debian5.04安装oracle11g 笔记
- JQuery设置缓慢下拉大行多次执行的解决办法,以及stop()函数的简单理解
- Java POI 两种导出方式
- 自适应SimpsonSimpson积分
- duilib之源码分析
- AjaxPro实现无刷新更新数据
- DELPHI XE5安装
- ASP.NET core1.0 EF MYSQL搭建中碰到几个问题记录
- React Native开发工具Nuclide使用
- H5内联视频总结
- veu——引入iconfont图标
- Java与JS判断请求来是否来自移动端
- hdu 4888 最大流慢板
热门文章
- 创建结点 与 分配内存 Function to create a Node. Allocates memory for a new node. 主动申请内存 链表 指针的写法
- java中获取字母和数字的组合
- Python开发【模块】:aiohttp(二)
- linux 修改密码命令
- linux strtock()函数使用问题
- 并查集——合作网络D306
- 跨域的问题(nginx解决才是王道)
- 第 7 章 Data 类型
- 给予Java初学者的学习路线建议
- tomcat 的acceptCount、acceptorThreadCount、maxConnections、maxThreads 如何确定