Oct
6
2012

Radial Blur Shader

Using the same godrays shader, you get nice radial blur effect for images. This one is also modified to use objectUV, instead of screenUV,
so you can rotate the plane around..

Webplayer:
http://unitycoder.com/upload/demos/Radial_Blur_shader_unity/ *webplayer broken in current unity webplayer version?

Shader source:

// FakeRadialBlur shader for Unity (v1.0)
// based on this shader: http://unitycoder.com/blog/2012/10/02/fake-godrays-shader/
// which is converted/based on this webgl shader: http://demo.bkcore.com/threejs/webgl_tron_godrays.html

Shader "UnityCoder/FakeRadialBlur"
{
Properties
{
tDiffuse ("Base (RGB)", 2D) = "white" {}
fX ("fX", Float) = 0.5
fY ("fY", Float) = 0.5
fExposure ("fExposure", Float) = 0.6
fDecay ("fDecay", Float) = 0.93
fDensity ("fDensity", Float) = 0.96
fWeight ("fWeight", Float) = 0.4
fClamp ("fClamp", Float) = 1.0
//iSamples ("iSamples", Int) = 20
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
Cull Off

CGPROGRAM
#pragma target 3.0
#pragma surface surf Lambert

sampler2D tDiffuse;
float fX,fY,fExposure,fDecay,fDensity,fWeight,fClamp,iSamples;

struct Input {
float2 uvtDiffuse;
float4 screenPos;
};

void surf (Input IN, inout SurfaceOutput o)
{
int iSamples=100;
float2 vUv = IN.uvtDiffuse;
//vUv *= float2(1,1); // repeat?
float2 deltaTextCoord = float2(vUv - float2(fX,fY));
deltaTextCoord *= 1.0 /  float(iSamples) * fDensity;
float2 coord = vUv;
float illuminationDecay = 1.0;
float4 FragColor = float4(0.0);
for(int i=0; i < iSamples ; i++)
{
coord -= deltaTextCoord;
float4 texel = tex2D(tDiffuse, coord);
texel *= illuminationDecay * fWeight;
FragColor += texel;
illuminationDecay *= fDecay;
}
FragColor *= fExposure;
FragColor = clamp(FragColor, 0.0, fClamp);
float4 c = FragColor;
o.Albedo = c.rgb;
o.Alpha = c.a;

}
ENDCG
}
FallBack "Diffuse"
}


About the Author:

.fi

3 Comments + Add Comment

  • Very nice!!! Wish I had found this site earlier, but from now on I’ll come back always looking for new shaders 🙂
    Thank you very much.

  • ^ shader source added

  • Thanks for this, helped a lot.
    I had to make some changes for this to work for WebGL builds.

Leave a comment

Connect

Twitter View LinkedIn profile Youtube Github Join Discord Twitch Instagram BlueSky

UnityLauncherPro

Get UnityLauncherPRO and work faster with Unity Projects!
*free unity hub alternative

@unitycoder_com

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.