Motion Blur With Shader Example

I’ve been working on this for around a week and cannot seem to find a GLSL example of doing motion blur. I’ve searched for hours on the internet and the forums ( and am surprised by how little information I can find.

I can do a motion blur with accumulation buffer but on my ATI card it runs pretty slow and I would rather go the shader method, however finding a good GLSL example is difficult.

I can find some examples in CG or HLSL but they are difficult for me to try and convert. For example a million posts link to this article (…haderTricks.pdf), but I haven’t been able to make use of it. It doesn’t explain what variables I need to provide from C to the shader, and it’s also not writting in GLSL so it’s very difficult for me to understand. It does seem to be a pure shader solution, so it proves what I want is possible, I just have been unable to convert it to GLSL with any success.

Any more experienced users out there know of an article that explains a shader only GLSL solution that also says what to do on the C code side? Or a conversion of the popular non-GLSL shader link above would be great!

Thanks for any help!

This kind of image space trick is similar to “deferred rendering”, which may be easier to search for.
Rather than storing normal information to do lighting in the second pass, you will store motion vector to do blurring in the second pass.

you can render to frame buffer. then bind the fbo to shader and uniform vec3 for the motion vector.
vertex shader:
void main()
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
frag shader:
void main()
vec2 uv = gl_TexCoord[0].st;
vec4 color = vec4(0.0, 0.0, 0.0, 1.0);

	int j = 0;
	int sum = 0;
	for(int i=-kernel_size; i<=kernel_size; i++) {
		vec4 value = texture2D(texScreen, uv + mv);
		int factor = kernel_size+1 - abs((float)i);
		color += value * factor;
		sum += factor;
	color /= sum;

gl_FragColor = color;
gl_FragColor.a = 1.0;


when mv is the motion vector, texscreen is the fbo and kernel_size is the blur depth