Motion Blur Shader

0 views
Skip to first unread message

Jeremiah Morrill

unread,
May 16, 2008, 2:52:22 PM5/16/08
to wpf-di...@googlegroups.com
Here's a motion blur shader I found on the inter-web.  [Very] Slightly modified for WPF goodness.  Sorry it's not a full project, but my playground is in Greg S's example project and I gotta get ready to goto OR tonight...so no time and WPF till monday.  I played with it and works pretty well.  Hopefully one of you guys can make something cool with it over the weekend.
 
 

sampler2D Src: register(s0);

float fspeed : register(C0);

float fangle : register(C1);

float4 main( float2 TexCoord : TEXCOORD0 ) : COLOR0

{

float4 gaussFilter[7] =

{

-1.0, 0.0, 0.0, 1.0/56.0,

0.0, 0.0, 0.0, 6.0/52.0,

1.0, 0.0, 0.0, 15.0/48.0,

2.0, 0.0, 0.0, 20.0/44.0,

3.0, 0.0, 0.0, 15.0/40.0,

4.0, 0.0, 0.0, 6.0/36.0,

5.0, 0.0, 0.0, 1.0/32.0

};

float4 totalblur = (1.0/32.0)+(6.0/36.0)+(15.0/40.0)+(20.0/44.0)+(15.0/48.0)+(6.0/52.0);

float4 color = 0.0;

float cosangle = cos(fangle);

float sinangle = sin(fangle);

int i;

for (i=0;i < 6;i++)

{

float tempx = gaussFilter[i].x;

gaussFilter[i].x = tempx*cosangle - gaussFilter[i].y*sinangle;

gaussFilter[i].y = gaussFilter[i].y*cosangle + tempx*sinangle;

}

for (i=0;i < 6;i++)

{

color += tex2D(Src,float2(TexCoord.x + gaussFilter[i].x * fspeed,

TexCoord.y + gaussFilter[i].y * fspeed)) * gaussFilter[i].w;

}

return color/totalblur;

}

Jeremiah Morrill

unread,
May 16, 2008, 2:54:19 PM5/16/08
to wpf-di...@googlegroups.com
BTW - Use small numbers for the fspeed, like 0.005.
Reply all
Reply to author
Forward
0 new messages