Sign in to follow this  
harshman_chris

Motion Blur with FBO

Recommended Posts

So I am trying to come up with a way to do a motion blur effect without using the velocity vector method, this is not because I cannot do it with that, but a section of work I am working on where the requirement is to store each frame in an FBO then motion blur them.

 

Right now I pass my 4 FBO's into my shader. Then I run this fragment shader with them and output the result, I cannot seem to get this to produce any effect other than darkening or lighting the engine depending on changes to the code below. I have also tried mixing the frames together and applying weights. I think is is an issue on how many FBO frames I am holding.

 

#version 330

in vec2 uv0;

uniform sampler2D Blur1;
uniform sampler2D Blur2;
uniform sampler2D Blur3;
uniform sampler2D Blur4;

out vec4 colour;

void main()
{
	vec3 colorA = texture2D(Blur1,uv0).rgb;
	vec3 colorB = texture2D(Blur2,uv0).rgb;
	vec3 colorC = texture2D(Blur3,uv0).rgb;
	vec3 colorD = texture2D(Blur4,uv0).rgb;
	
	colour.rgb = colorA + colorB + colorC + colorD;

	colour.rgb /= 4;
}

 

 

How can I get a passable motion blur with 4 frames? I can also go up to 8 FBO frames.

Share this post


Link to post
Share on other sites

Okay, since you can't actually read from an FBO but only use an FBO to render to a texture and then read that texture, here's the question: do you set up the active textures, bindings and uniforms correctly? How this should go is like this:

 

set active texture to N

bind your texture[N] to GL_TEXTURE_2D

glUniform1i(uniform N location, N)

 

N loops through 1...4, obviously. What this sounds like is you forgetting to call the gluniform1i - all the uniforms samplers are texture unit 0 unless you specify otherwise.

 

And please, do "uniform sampler2D Blur1, Blur2, Blur3, Blur4;" instead of what you do now. And to be extra sure, always set the alpha to something.

Share this post


Link to post
Share on other sites

Okay, since you can't actually read from an FBO but only use an FBO to render to a texture and then read that texture, here's the question: do you set up the active textures, bindings and uniforms correctly? How this should go is like this:

 

set active texture to N

bind your texture[N] to GL_TEXTURE_2D

glUniform1i(uniform N location, N)

 

N loops through 1...4, obviously. What this sounds like is you forgetting to call the gluniform1i - all the uniforms samplers are texture unit 0 unless you specify otherwise.

 

And please, do "uniform sampler2D Blur1, Blur2, Blur3, Blur4;" instead of what you do now. And to be extra sure, always set the alpha to something.

 

None of those are the issue, what I need is how to blend the 4 frames together properly so it appears blurred, rather than just making the scene lighter or darker.

Share this post


Link to post
Share on other sites

That very much seems to be the issue, if averaging 4 images that should be different doesn't produce a blurred result. Can you actually somehow verify that the 4 samplers have different textures attached?

Share this post


Link to post
Share on other sites

That very much seems to be the issue, if averaging 4 images that should be different doesn't produce a blurred result. Can you actually somehow verify that the 4 samplers have different textures attached?

 

Yes I use various tools to check this, I believe the issue is because I am using 4 frames that are too close together so the effect is not noticeable.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this