Unity3D Shader 高斯模糊

//Shader
Shader "Hidden/GaussianBlur"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_BlurSize ("Blur Size", Float) = 0.1
} CGINCLUDE #include "UnityCG.cginc" sampler2D _MainTex;
uniform half4 _MainTex_TexelSize;
uniform float _BlurSize; static const half weight[] = {0.0205, 0.0855, 0.232, 0.324};
static const half4 coordOffset = half4(.0h,.0h,-.0h,-.0h); struct v2f_blurSGX
{
float4 pos:SV_POSITION;
half2 uv:TEXCOORD0;
half4 uvoff[]:TEXCOORD1;
}; v2f_blurSGX vert_BlurHorizontal(appdata_img v)
{
v2f_blurSGX o;
o.pos = mul(UNITY_MATRIX_MVP,v.vertex);
o.uv = v.texcoord.xy;
half2 offs = _MainTex_TexelSize.xy*half2(,)*_BlurSize;
o.uvoff[] = v.texcoord.xyxy+offs.xyxy*coordOffset*;
o.uvoff[] = v.texcoord.xyxy+offs.xyxy*coordOffset*;
o.uvoff[] = v.texcoord.xyxy+offs.xyxy*coordOffset; return o;
} v2f_blurSGX vert_BlurVertical(appdata_img v)
{
v2f_blurSGX o;
o.pos = mul(UNITY_MATRIX_MVP,v.vertex);
o.uv = v.texcoord.xy; half2 offs = _MainTex_TexelSize.xy*half2(,)*_BlurSize;
o.uvoff[] = v.texcoord.xyxy+offs.xyxy*coordOffset*;
o.uvoff[] = v.texcoord.xyxy+offs.xyxy*coordOffset*;
o.uvoff[] = v.texcoord.xyxy+offs.xyxy*coordOffset; return o;
} fixed4 frag_Blur(v2f_blurSGX i):SV_Target
{ fixed4 c = tex2D(_MainTex,i.uv)*weight[];
for(int idx=; idx<; idx++)
{
c+=tex2D(_MainTex,i.uvoff[idx].xy)*weight[idx];
c+=tex2D(_MainTex,i.uvoff[idx].zw)*weight[idx];
} return c;
} ENDCG SubShader
{
// No culling or depth
Cull Off ZWrite Off Pass
{
ZTest Always
CGPROGRAM
#pragma vertex vert_BlurHorizontal
#pragma fragment frag_Blur ENDCG
} Pass
{
ZTest Always
CGPROGRAM
#pragma vertex vert_BlurVertical
#pragma fragment frag_Blur ENDCG
}
}
}
//c#
using UnityEngine;
using System.Collections; [RequireComponent(typeof(Camera))]
[ExecuteInEditMode]
public class Blur : MonoBehaviour { public Material ma; public float BlurSize =;
public int interator = ; void OnRenderImage (RenderTexture sourceTexture, RenderTexture destTexture)
{ ma.SetFloat ("_BlurSize", BlurSize);
int rtW = sourceTexture.width/;
int rtH = sourceTexture.height/; RenderTexture rtTempA = RenderTexture.GetTemporary (rtW, rtH, , sourceTexture.format);
rtTempA.filterMode = FilterMode.Bilinear; RenderTexture rtTempB = RenderTexture.GetTemporary (rtW, rtH, , sourceTexture.format);
rtTempB.filterMode = FilterMode.Bilinear; for (int i = ; i < interator; i++) {
if ( == i) {
Graphics.Blit (sourceTexture, rtTempA,ma,);
Graphics.Blit (rtTempA, rtTempB, ma, );
} else { Graphics.Blit (rtTempB, rtTempA, ma, );
Graphics.Blit (rtTempA, rtTempB,ma,);
} } Graphics.Blit(rtTempB, destTexture); RenderTexture.ReleaseTemporary(rtTempA);
RenderTexture.ReleaseTemporary(rtTempB);
} }
Unity3D Shader 高斯模糊的更多相关文章
- 【译】Unity3D Shader 新手教程(1/6)
本文为翻译,附上原文链接. 转载请注明出处--polobymulberry-博客园. 刚开始接触Unity3D Shader编程时,你会发现有关shader的文档相当散,这也造成初学者对Unity3D ...
- Unity3D shader简介
Unity3D shader简介 可以肯定的说Unity3D使得很多开发者开发游戏更容易.毫无疑问,shader(着色器)编码,仍有很长的路要走.shader是一个专门运行在GPU的程序,经常被神秘包 ...
- 【浅墨Unity3D Shader编程】之一 夏威夷篇:游戏场景的创建 & 第一个Shader的书写
本系列文章由@浅墨_毛星云 出品,转载请注明出处. 文章链接:http://blog.csdn.net/poem_qianmo/article/details/40723789 作者:毛星云(浅墨) ...
- 转 猫都能学会的Unity3D Shader入门指南(二)
猫都能学会的Unity3D Shader入门指南(二) 关于本系列 这是Unity3D Shader入门指南系列的第二篇,本系列面向的对象是新接触Shader开发的Unity3D使用者,因为我本身自己 ...
- Unity3D Shader入门指南(二)
关于本系列 这是Unity3D Shader入门指南系列的第二篇,本系列面向的对象是新接触Shader开发的Unity3D使用者,因为我本身自己也是Shader初学者,因此可能会存在错误或者疏漏,如果 ...
- Unity3d Shader
Unity3d Shader 预览Surface Shader主要用来实现光照相关处理,可能更简洁. Vertex and Fragment Shader 如果不与光照交互, 则可以用这个shader ...
- 【浅墨Unity3D Shader编程】之二 雪山飞狐篇:Unity的基本Shader框架写法&颜色、光照与材质
本系列文章由@浅墨_毛星云 出品,转载请注明出处. 文章链接:http://blog.csdn.net/poem_qianmo/article/details/40955607 作者:毛星云(浅墨) ...
- 【淡墨Unity3D Shader计划】四 热带雨林的文章: 排除、深度测试、Alpha测试和基本雾编译
本系列文章由@浅墨_毛星云 出品,转载请注明出处. 文章链接:http://hpw123.net/a/C__/kongzhitaichengxu/2014/1222/163.html 作者:毛星云 ...
- 【淡墨Unity3D Shader计划】五 圣诞用品: Unity在Shader三种形式的控制&混合操作编译
本系列文章由@浅墨_毛星云 出品,转载请注明出处. 文章链接:http://blog.csdn.net/poem_qianmo/article/details/42060963 作者:毛星云(浅墨) ...
随机推荐
- 【面试 redis】【第十二篇】redis的相关面试问题
redis的相关面试问题 redis教程:http://www.redis.net.cn/tutorial/3501.html ==================================== ...
- Java HashSet工作原理及实现
1. 概述 This class implements the Set interface, backed by a hash table (actually a HashMap instance). ...
- Exception的ToString()方法究竟返回的是什么
最近项目上线后遇到exception没有堆栈信息.所以跟踪一下 源码,其中主要的code如下: // Returns the stack trace as a string. If no stack ...
- 常见的机器学习&数据挖掘知识点
原文:http://blog.csdn.net/heyongluoyao8/article/details/47840255 常见的机器学习&数据挖掘知识点 转载请说明出处 Basis(基础) ...
- linux网络设备—PHY
一.结构体 1.PHY设备 struct phy_device { struct phy_driver *drv; //PHY设备驱动 struct mii_bus *bus; //对应的MII总线 ...
- JAVA中通过JavaCV实现跨平台视频/图像处理-调用摄像头
一.简介 JavaCV使用来自计算机视觉领域(OpenCV, FFmpeg, libdc1394, PGR FlyCapture, OpenKinect, librealsense, CL PS3 E ...
- elasticsearch日志删除命令
通过curl发送DELETE命令给elasticsearch服务器,进行日志删除操作.命令示例如下: curl -XDELETE *' curl -XDELETE 'http://192.168.10 ...
- 使用Kotlin优雅的开发Android应用
来源:https://juejin.im/post/5915c0a744d904006c4e3bcd demo下载地址:https://github.com/xiehui999/KotlinForAn ...
- [转载]从100PV到1亿级PV网站架构演变
原文地址:http://www.uml.org.cn/zjjs/201307172.asp 一个网站就像一个人,存在一个从小到大的过程.养一个网站和养一个人一样,不同时期需要不同的方法,不同的方法下有 ...
- 关于tomcat不同版本的maxPostSize
tomcat7.0.63之前: maxPostSize The maximum size in bytes of the POST which will be handled by the conta ...