Is there any radial blur effect hiding in the world wide unity web somewhere? ^^
Would be nice to use it with anti aliasing together, maybe in Unity 2.6?
Or how I could simulate a camera, flying with high velocity, which is actually looking and feeling fast too?
Do you mean a spinning blur (like a fan moving really fast) or do you mean a blur where the center of the screen is clear, but it gets blurrier as you get close to the edges?
I haven’t played with motion blur much, I’m just asking because you could mean a few things by “radial blur”.
What’s wrong with the inbuilt motion blur? (http://unity3d.com/support/documentation/Components/script-MotionBlur.html)
If your camera is moving forward fast, the blur is - by its very nature - going to be radial. If you’re asking because you have Indie, and not Pro, then I think radial blur won’t help as that would also require rendering to a texture.
The only other trick I can think of offhand to increase the sense of speed is to increase the FOV of your camera.
I think the desired effect is like the zoom blur option on Photoshop’s radial blur - there is no such effect script that ships with Unity and I couldn’t find one on the wiki either. There might be a third party effect script somewhere.
Example:
http://www.borisfx.com/images/bcc3/radial_blur.jpg
@sybixsus2 Yea, the built-in motionblur is cool but it blurs with a dynamic blur shape, the radial thing is static and blurs always in the same way. So it’s really a different looking blur, especially when you move the camera.
More info:
http://www.gamerendering.com/2008/12/20/radial-blur-filter/
It seems that this effect isn’t too hard to accomplish, so I’ll look into some shader scripting but I guess it’s too expensive for my project time Or maybe someone wants to do it?
This topic may belong to the ShaderLab now
I quickly converted the shader for Unity…
The the ImageEffects class from “Pro Standard Asset/Image Based” is required.
Hope it works… I didn’t test openGL.
RadialBlur.shader
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;
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 - 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);
}
//eleven samples...
sum *= 1.0/11.0;
//weighten blur depending on distance to screen center
half t = dist * _BlurStrength;
t = clamp(t, 0.0, 1.0);
//blend original with blur
return mix(color, sum, t);
}
ENDCG
}
}
}
RadialBlur.cs
using UnityEngine;
[ExecuteInEditMode]
public class RadialBlur : MonoBehaviour
{
public Shader rbShader;
public float blurStrength = 2.2f;
public float blurWidth = 1.0f;
private Material rbMaterial = null;
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);
}
}
void OnRenderImage(RenderTexture source, RenderTexture dest)
{
GetMaterial().SetFloat("_BlurStrength", blurStrength);
GetMaterial().SetFloat("_BlurWidth", blurWidth);
ImageEffects.BlitWithMaterial(GetMaterial(), source, dest);
}
}
Thanks! Now I have a .shader and a .cs file, but how I’m supposed to use these files in unity now?
The built-in image effects have a script in addition in order to work, I need it too?
Add the RadialBlur script to the main Camera and in the inspector add the shader into the Rb Shader field…
If you get an error message like “The name ImageEffects
does not exist in the current context” you probably need to add the ProStandardAssets.
@DerWoDaSo - Doesn’t seem to work in OpenGL, tested on my Macbook Pro with ATI X1600 graphics. I didn’t get any errors reported and I tried different values for the two variables with no apparent change.
Thanks bigkahuna, the problem is that the shader uses a texRECT sampler and in OpenGL mode. This means the UV Range is not from 0-1, but from 0-textureSize. So several values have to be scaled accordingly.
Here is a little work around for that. But isn’t there a … more elegant way?
radialBlur.shader
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
}
}
}
radialBlur.cs
using UnityEngine;
[ExecuteInEditMode]
public class RadialBlur : MonoBehaviour
{
public Shader rbShader;
public float blurStrength = 2.2f;
public float blurWidth = 1.0f;
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 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);
}
}
That fixed it!
This would make a very nice addition to the wiki…
Yeah, really nice =D
I searched for this first in the wiki, so there it would be good placed :idea:
Is this effect fully compatible with Unity 3.0?
thanks
Do you have unity3 compatible version?
radialBlur.shader
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 lerp(color, sum, t);
}
ENDCG
}
}
}
This works for me in 3.0. Just changed the mix to lerp and it seems to work well.
how to make this work on iPad2 ?
how to make this work on iPad2 with Unity3.4.1 Pro?
Thanks man… Your shader works great for me…
on OpenGL mode it is not work :S, any idea ?
can this be edited to include only motion? It seems to stay on for me and I could use it for just motion