Motion Blur with FBO

Started by
5 comments, last by harshman_chris 11 years ago

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.

Advertisement

What do these 4 frames contain?

What do these 4 frames contain?

The current frame and the previous three frames

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.

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.

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?

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.

This topic is closed to new replies.

Advertisement