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);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);
}Code: Select all
Matrix4_Copy(r_modelViewProjection, r_oldModelViewProjection);vp
Code: Select all
void main ()
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}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;
}