使用unity自带shader blurEffect
2016-03-02 15:43
573 查看
unity 4.7的版本 自带的shader 特效 说明:http://www.ceeger.com/Components/comp-ImageEffects.html
路径在standard pakage 里。
路径在standard pakage 里。
public class blurEffect : MonoBehaviour { public Shader blurShader; public float blurSpread = 0.6f; public int iterations = 3; private static Material m_Material; // Methods private void DownSample4x(RenderTexture source, RenderTexture dest) { float y = 1f; Vector2[] offsets = new Vector2[] { new Vector2(-y, -y), new Vector2(-y, y), new Vector2(y, y), new Vector2(y, -y) }; Graphics.BlitMultiTap(source, dest, this.material, offsets); } public void FourTapCone(RenderTexture source, RenderTexture dest, int iteration) { float y = 0.5f + (iteration * this.blurSpread); Vector2[] offsets = new Vector2[] { new Vector2(-y, -y), new Vector2(-y, y), new Vector2(y, y), new Vector2(y, -y) }; Graphics.BlitMultiTap(source, dest, this.material, offsets); } protected void OnDisable() { if (m_Material != null) { Object.DestroyImmediate(m_Material); } } private void OnRenderImage(RenderTexture source, RenderTexture destination) { RenderTexture dest = RenderTexture.GetTemporary(source.width / 4, source.height / 4, 0); RenderTexture texture2 = RenderTexture.GetTemporary(source.width / 4, source.height / 4, 0); this.DownSample4x(source, dest); bool flag = true; for (int i = 0; i < this.iterations; i++) { if (flag) { this.FourTapCone(dest, texture2, i); } else { this.FourTapCone(texture2, dest, i); } flag = !flag; } if (flag) { Graphics.Blit(dest, destination); } else { Graphics.Blit(texture2, destination); } RenderTexture.ReleaseTemporary(dest); RenderTexture.ReleaseTemporary(texture2); } protected void Start() { if (!SystemInfo.supportsImageEffects) { base.enabled = false; } else if ((this.blurShader == null) || !this.material.shader.isSupported) { base.enabled = false; } } // Properties protected Material material { get { if (m_Material == null) { m_Material = new Material(this.blurShader); m_Material.hideFlags = HideFlags.DontSave; } return m_Material; } } }http://www.cnblogs.com/tekkaman/p/4128004.html 这篇文章是关于 Graphics.BlitMultiTap 的介绍
相关文章推荐
- Unity DrawCall优化
- unity3d MVC设计模式
- Unity3d优化
- Unity3D使用经验总结 优点篇
- 【Unity】Unity中获得碰撞体碰撞的位置
- Unity GameObject显示状态管理
- Unity 之 TexturePacker(TP) 的应用
- Unity3D -- 简单的UI管理结构
- unity3d有几种坐标系?
- Unity VS插件配置
- unity实现鼠标让物体绕世界Y轴旋转_C#
- Unity3D应用随笔,选择默认脚本编辑器
- 碰撞检测之Sphere-Sphere检测
- UnityVS(Visual Studio Tools For Unity)的安装与使用
- Unity3D应用随笔,MonoDevelop的中文乱码
- 关于UnityEngine.Network的一些浅显认知
- Unity中关于作用力方式ForceMode的功能注解
- [置顶] Unity中Animation与Animator组件的使用
- unity-场景重置,游戏对象的初始化改变以及复制
- [置顶] Unity基于NGUI实现拖拽功能