motion blur
Moderator: InsideQC Admins
4 posts
• Page 1 of 1
motion blur
I tried to add a motion blur on the tutorial from Nvidia
http://http.developer.nvidia.com/GPUGem ... _ch27.html
problem - blurring the whole frame, Far plane more, looks like the depth of field, but with active blur of moving objects.

my code
setup matrix for motion blur
render frame
setup 2d
postprocess
after postprocess
shaders
vp
fp
Any ideas?
http://http.developer.nvidia.com/GPUGem ... _ch27.html
problem - blurring the whole frame, Far plane more, looks like the depth of field, but with active blur of moving objects.

my code
setup matrix for motion blur
- Code: Select all
Matrix4_Multiply(r_world_matrix, r_project_matrix, r_modelViewProjection);
InvertMatrix(r_modelViewProjection, r_modelViewProjectionInv);
render frame
setup 2d
postprocess
- Code: Select all
void R_MotionBlur (void) {
unsigned defBits = 0;
int id;
if (r_newrefdef.rdflags & RDF_NOWORLDMODEL)
return;
if (r_newrefdef.rdflags & RDF_IRGOGGLES)
return;
// setup program
GL_BindProgram(motionBlurProgram, defBits);
id = motionBlurProgram->id[defBits];
qglUniformMatrix4fv(qglGetUniformLocation(id, "invMatrix"), 1, GL_FALSE, r_modelViewProjectionInv);
qglUniformMatrix4fv(qglGetUniformLocation(id, "PrevMatrix"), 1, GL_FALSE, r_oldModelViewProjection);
GL_SelectTexture (GL_TEXTURE0_ARB);
GL_BindRect (ScreenMap->texnum);
qglCopyTexSubImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0, 0, 0, vid.width, vid.height);
qglUniform1i (qglGetUniformLocation(id, "u_screenMap"), 0);
GL_SelectTexture (GL_TEXTURE1_ARB);
GL_BindRect (depthMap->texnum);
qglUniform1i (qglGetUniformLocation(id, "u_depthMap"), 1);
qglBegin(GL_QUADS);
qglVertex2f(0, vid.height);
qglVertex2f(vid.width, vid.height);
qglVertex2f(vid.width, 0);
qglVertex2f(0, 0);
qglEnd();
GL_BindNullProgram ();
GL_SelectTexture (GL_TEXTURE0_ARB);
}
after postprocess
- Code: Select all
Matrix4_Copy(r_modelViewProjection, r_oldModelViewProjection);
shaders
vp
- Code: Select all
void main ()
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
fp
- Code: Select all
uniform sampler2DRect u_depthMap;
uniform sampler2DRect u_screenMap;
uniform mat4 PrevMatrix;
uniform mat4 invMatrix;
void main(void)
{
vec4 zOverW = texture2DRect(u_depthMap, gl_FragCoord.xy);
// H is the viewport position at this pixel in the range -1 to 1.
vec4 H = vec4(gl_FragCoord.x * 2 - 1, (1 - gl_FragCoord.y) * 2 - 1, zOverW.g, 1);
// Transform by the view-projection inverse.
vec4 D = invMatrix * H;
// Divide by w to get the world position.
vec4 worldPos = D / vec4(D.w);
// Current viewport position
vec4 currentPos = H;
// Use the world position, and transform by the previous view-projection matrix.
vec4 previousPos = PrevMatrix * worldPos;
// Convert to nonhomogeneous points [-1,1] by dividing by w.
previousPos = previousPos / vec4(previousPos.w);
// Use this frame's position and last frame's to compute the pixel velocity.
vec2 velocity = vec2(currentPos.xy - previousPos.xy)/4000.0; // scale value for q2, was 2.0
// vec2 velocity = vec2(1.5, -0.5); //debug vector
// Get the initial color at this pixel.
vec4 color = vec4(0.0, 0.0, 0.0, 0.0);
for(int i = 1; i < 8; ++i)
{
// Sample the color buffer along the velocity vector.
vec4 currentColor = texture2DRect(u_screenMap, gl_FragCoord.xy + vec2(velocity)*i);
// Add the current color to our color sum.
color += currentColor;
}
// Average all of the samples to get the final blur color.
gl_FragColor = color / 8;
}
Any ideas?
-

Barnes - Posts: 226
- Joined: Thu Dec 24, 2009 2:26 pm
- Location: Russia, Moscow
Re: motion blur
sounds a bit like the same issue the last tenebrae had with postprocessing effects (also affected the entire screen) i newer quite figured out what goes wrong with it :S
Productivity is a state of mind.
-

revelator - Posts: 2567
- Joined: Thu Jan 24, 2008 12:04 pm
- Location: inside tha debugger
Re: motion blur
Looks like normal behaviour for this kind of effect. You're taking 8 samples, so for further objects those 8 samples will be from parts of them that are further apart in world-space, and so they'll blur more. It's likely also frame-rate dependent as it updates the blur every frame, so it will look very different running at 20 fps to how it would look at 200 fps.
One thing I would do with this kind of effect is fold the polyblend into it too - that way, if a polyblend is active, you get it (almost) for free rather than having to do another fillrate-intensive pass over the full screen.
One thing I would do with this kind of effect is fold the polyblend into it too - that way, if a polyblend is active, you get it (almost) for free rather than having to do another fillrate-intensive pass over the full screen.
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
We knew the words, we knew the score, we knew what we were fighting for
-

mh - Posts: 2292
- Joined: Sat Jan 12, 2008 1:38 am
Re: motion blur
motion blur with polyblend (copy screen and draw up of frame) look so ugly 
-

Barnes - Posts: 226
- Joined: Thu Dec 24, 2009 2:26 pm
- Location: Russia, Moscow
4 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest