使用unity自带shader blurEffect

unity 4.7的版本 自带的shader 特效 说明:http://www.ceeger.com/Components/comp-ImageEffects.html

路径在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 的介绍

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值