GLSL simple motion blur

Started by
3 comments, last by xerodsm 16 years, 10 months ago
hi everyone! I tried to get a source code for a simple motion blur effect in glsl (vertex/fragment shader file) but I haven't found anything usefull! can anyone tell me where to find something? or does anyone have sources?
Advertisement
Vert shader doesn't really have to do much. Then just sample surrounding pixels of the texture you want to blur. I don't know if that's the best way to do it, but it will blur. The more points you sample the more it will blur.


Frag Shader:

uniform sampler2D blur;

void main()
{
vec4 color = texture2D(blur, gl_TexCoord[0].st);

color += texture2D(blur, vec2(gl_TexCoord[0].s + .01, gl_TexCoord[0].t));
color += texture2D(blur, vec2(gl_TexCoord[0].s + .01, gl_TexCoord[0].t + .01));
color += texture2D(blur, vec2(gl_TexCoord[0].s, gl_TexCoord[0].t + .01));


color += texture2D(blur, vec2(gl_TexCoord[0].s - .01, gl_TexCoord[0].t));
color += texture2D(blur, vec2(gl_TexCoord[0].s - .01, gl_TexCoord[0].t - .01));
color += texture2D(blur, vec2(gl_TexCoord[0].s, gl_TexCoord[0].t - .01));

color += texture2D(blur, vec2(gl_TexCoord[0].s + .01, gl_TexCoord[0].t - .01));

color += texture2D(blur, vec2(gl_TexCoord[0].s - .01, gl_TexCoord[0].t + .01));



vec4 final = color/9.0f;
final.w = final.r;

gl_FragColor = final;
}
Hey xerodsm:
Can you do me two favors: could you post the vertex part of the shader, and can you give me an idea on what I pass as that 2D sample? Do you render what is in the video buffer to a texture, than sample that texture? Do you have some source, or can you point me in the direction of a place I can learn about it?
I know bits and pieces of GLSL, and have been trying to make a motion blur shader for my group's game. A lot of people have an opinion on this matter, yet I've yet to find a concrete answer to a motion blur shader. thank you for your time.

Peace.
thats not a motion blur

theres no simple motion blur, usually u need to create extra verts etc.

the easiest method is to not clear the previous screen completely ie have the previous frames hand around a bit, but this really aint a proper motion blur
Yeah. That isn't a motion blur shader. It's just the frag part of the shader to create some blur. If you want to create motion blur then you'll probably want to create a texture of the screen, send that as the uniform to the shader, and then blur it and decrease the alpha. You'll probably want to store a few of the last frames in a texture buffer so you can create a more realistic looking blur. Look up how to render to a texture using the frame buffer and look up how to pass textures to shaders.

This topic is closed to new replies.

Advertisement