资源简介
使用于移动平台的unity径向模糊屏幕特效,效率不错
代码片段和文件信息
using UnityEngine;
using System.Collections;
using System;
[ExecuteInEditMode]
[AddComponentMenu (“PengLu/ImageEffect/RadialBlur“)]
public class ImageEffect_RadialBlur : MonoBehaviour {
#region Variables
public Shader RadialBlurShader = null;
private Material RadialBlurMaterial = null;
// private RenderTextureFormat rtFormat = RenderTextureFormat.Default;
[Range(0.0f 1.0f)]
public float SampleDist = 0.17f;
[Range(1.0f 5.0f)]
public float SampleStrength = 2.09f;
#endregion
void Start () {
FindShaders ();
CheckSupport ();
CreateMaterials ();
}
void FindShaders () {
if (!RadialBlurShader) {
RadialBlurShader = Shader.Find(“PengLu/ImageEffect/Unlit/RadialBlur“);
}
}
void CreateMaterials() {
if(!RadialBlurMaterial){
RadialBlurMaterial = new Material(RadialBlurShader);
RadialBlurMaterial.hideFlags = HideFlags.HideAndDontSave;
}
}
bool Supported(){
return (SystemInfo.supportsImageEffects && SystemInfo.supportsRenderTextures && RadialBlurShader.isSupported);
// return true;
}
bool CheckSupport() {
if(!Supported()) {
enabled = false;
return false;
}
// rtFormat = SystemInfo.SupportsRenderTextureFormat (RenderTextureFormat.RGB565) ? RenderTextureFormat.RGB565 : RenderTextureFormat.Default;
return true;
}
void OnRenderImage (RenderTexture sourceTexture RenderTexture destTexture)
{
#if UNITY_EDITOR
FindShaders ();
CheckSupport ();
CreateMaterials ();
#endif
if(SampleDist != 0 && SampleStrength != 0){
int rtW = sourceTexture.width/8;
int rtH = sourceTexture.height/8;
RadialBlurMaterial.SetFloat (“_SampleDist“ SampleDist);
RadialBlurMaterial.SetFloat (“_SampleStrength“ SampleStrength);
RenderTexture rtTempA = RenderTexture.GetTemporary (rtW rtH 0RenderTextureFormat.Default);
rtTempA.filterMode = FilterMode.Bilinear;
Graphics.Blit (sourceTexture rtTempA);
RenderTexture rtTempB = RenderTexture.GetTemporary (rtW rtH 0RenderTextureFormat.Default);
rtTempB.filterMode = FilterMode.Bilinear;
// RadialBlurMaterial.SetTexture (“_MainTex“ rtTempA);
Graphics.Blit (rtTempA rtTempB RadialBlurMaterial0);
RadialBlurMaterial.SetTexture (“_BlurTex“ rtTempB);
Graphics.Blit (sourceTexture destTexture RadialBlurMaterial1);
RenderTexture.ReleaseTemporary(rtTempA);
RenderTexture.ReleaseTemporary(rtTempB);
}
else{
Graphics.Blit(sourceTexture destTexture);
}
}
public void OnDisable () {
if (RadialBlurMaterial)
DestroyImmediate (RadialBlurMaterial);
// RadialBlurMaterial = null;
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1949 2015-09-22 18:00 ImageEffect_RadialBlur.shader
文件 2734 2015-09-22 17:36 ImageEffect_RadialBlur.cs
----------- --------- ---------- ----- ----
4683 2
评论
共有 条评论