Skip to main content
GameDev.net gamedev.net
🔒 Locked

Motion Blur with FBO

Started by harshman_chris Apr 11, 2013 at 4:53 PM 5 replies 3.4k views
Original Post
harshman_chris
harshman_chris

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.

harshman_chris
harshman_chris

What do these 4 frames contain?

The current frame and the previous three frames

powly k
powly k

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.

harshman_chris
harshman_chris

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.

powly k
powly k

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?

harshman_chris
harshman_chris

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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.