Shader "Hidden/radialBlur" {
Properties {
_MainTex ("Input", RECT) = "white" {}
_BlurStrength ("", Float) = 0.5
_BlurWidth ("", Float) = 0.5
}
SubShader {
Pass {
ZTest Always Cull Off ZWrite Off
Fog { Mode off }
CGPROGRAM
#pragma vertex vert_img
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
uniform samplerRECT _MainTex;
uniform half _BlurStrength;
uniform half _BlurWidth;
uniform half _iWidth;
uniform half _iHeight;
half4 frag (v2f_img i) : COLOR {
half4 color = texRECT(_MainTex, i.uv);
// some sample positions
half samples[10] = half[](-0.08,-0.05,-0.03,-0.02,-0.01,0.01,0.02,0.03,0.05,0.08);
//vector to the middle of the screen
half2 dir = 0.5 * half2(_iHeight,_iWidth) - i.uv;
//distance to center
half dist = sqrt(dir.x*dir.x + dir.y*dir.y);
//normalize direction
dir = dir/dist;
//additional samples towards center of screen
half4 sum = color;
for(int n = 0; n < 10; n++)
{
sum += texRECT(_MainTex, i.uv + dir * samples[n] * _BlurWidth * _iWidth);
}
//eleven samples...
sum *= 1.0/11.0;
//weighten blur depending on distance to screen center
half t = dist * _BlurStrength / _iWidth;
t = clamp(t, 0.0, 1.0);
//blend original with blur
return mix(color, sum, t);
}
ENDCG
}
}
}
using UnityEngine;
[ExecuteInEditMode]
public class RadialBlur : MonoBehaviour
{
public Shader rbShader;
public float blurStrength = 0.0f;
public float blurWidth = 0.7f;
private Material rbMaterial = null;
private bool isOpenGL;
private Material GetMaterial()
{
if (rbMaterial == null)
{
rbMaterial = new Material(rbShader);
rbMaterial.hideFlags = HideFlags.HideAndDontSave;
}
return rbMaterial;
}
void Start()
{
if (rbShader == null)
{
Debug.LogError("shader missing!", this);
}
isOpenGL = SystemInfo.graphicsDeviceVersion.StartsWith("OpenGL");
}
void LateUpdate()
{
blurStrength = camera.velocity.magnitude * 0.03f;
}
void OnRenderImage(RenderTexture source, RenderTexture dest)
{
//If we run in OpenGL mode, our UV coords are
//not in 0-1 range, because of the texRECT sampler
float ImageWidth = 1;
float ImageHeight = 1;
if (isOpenGL)
{
ImageWidth = source.width;
ImageHeight = source.height;
}
GetMaterial().SetFloat("_BlurStrength", blurStrength);
GetMaterial().SetFloat("_BlurWidth", blurWidth);
GetMaterial().SetFloat("_iHeight",ImageWidth);
GetMaterial().SetFloat("_iWidth", ImageHeight);
ImageEffects.BlitWithMaterial(GetMaterial(), source, dest);
}
}
Neodrop писал(а):А чего автомат влево куда то лупит?
Приятненько так с блюром.
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 2