Unity3D Shader:径向模糊

C#代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class blur_power : MonoBehaviour {

    [Range(0, 1f)]
    public float blurPower = 0.1f;

    [Range(0, 1)]
    public float blurLerp = 0.5f;

    public int downScale = 2;

    public Vector2 blurCenter = new Vector2(0.5f, 0.5f);

    public Material mat;

    private void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        RenderTexture rt1 = RenderTexture.GetTemporary(source.height >> downScale, source.width >> downScale, 0, source.format);
        RenderTexture rt2 = RenderTexture.GetTemporary(source.height >> downScale, source.width >> downScale, 0, source.format);
        Graphics.Blit(source, rt1);

        mat.SetFloat("_blurPower", blurPower);
        mat.SetVector("_blurCenter", blurCenter);
        Graphics.Blit(rt1, rt2,mat, 0);

        mat.SetTexture("_blurTex", rt2);
        mat.SetFloat("_blurLerp", blurLerp);
        Graphics.Blit(source, destination, mat, 1);

        RenderTexture.ReleaseTemporary(rt1);
        RenderTexture.ReleaseTemporary(rt2);

    }
}

Shader代码: 

Shader "Unlit/Test"
{
	Properties
	{
		_MainTex ("Texture", 2D) = "white" {}
		_blurTex("blurTex",2D)="white"{}
	}
	CGINCLUDE
	sampler2D _MainTex;
	sampler2D _blurTex;
	float _blurPower;
	float2 _blurCenter;
	float _blurLerp;
	float4 _MainTex_TexelSize;
	#include "UnityCG.cginc"
	#define deifu_count 6

	fixed4 frag_blur(v2f_img i):SV_Target
	{
		float2 dir=i.uv-_blurCenter;
		float4 colorout;
		for(int j=0; j

 

 Unity3D Shader:径向模糊_第1张图片

你可能感兴趣的:(Shader)