Jump to content
  • Advertisement
Sign in to follow this  
klimt

GLSL simple motion blur

This topic is 4188 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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;
}

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!