FynnFluegge

10-14-2015, 03:49 AM

Hello Community,

I am going to extend my 3D-Engine with a Motion Blur effect. Therefore i want to compute the pixel screen-velocity in a compute shader. Current scene frame and depthbuffer is rendered into two texture samplers.

I did a lot research about that topic and changed my code many times but finally the Motion Blur effect does not work as intended. Pixel velocity only considers camera moving but not camera rotating. I detected that my transformation from ndc to eye-space is not correct but i don't know how to fix it.

I linearzie the the depth value from depthbuffer as follows:

lin_depth = 2 * near / (far + near - depth * (far - near))

I tested that linearization in my application and it seems to be correct.

Now i define the NDC as usual:

vec3 NDC = vec3(window.x * 2 - 1, window.y * 2 - 1, lin_depth);

I compute the clip-Position w as i found here https://www.opengl.org/wiki/Compute_eye_space_from_window_space#From_NDC_to_cl ip:

float Cw = projectionMatrix[2][3] / (NDC.z - projectionMatrix[2][2]);

Now i should be able to get the eye-Position with the inverse Projection

vec4 eyePos = (inverseProjectionMatrix) * vec4(NDC * Cw, Cw);

but as i tested these computations in my application, the eye space position i get is wrong.

My projection Matrix is defined as follows:

1/(tanFOV*aspect) 0 0 0

0 1/tanFOV 0 0

0 0 (-zNear-zFar)/(zNear-zFar) 2*zFar*zNear/(zNear-zFar);

0 0 1 0

Remember at my Cw-calculation i send the matrix transposed to the glsl-shader.

Tanks in advance if somebody can help me!

greetings, Fynn Fluegge

I am going to extend my 3D-Engine with a Motion Blur effect. Therefore i want to compute the pixel screen-velocity in a compute shader. Current scene frame and depthbuffer is rendered into two texture samplers.

I did a lot research about that topic and changed my code many times but finally the Motion Blur effect does not work as intended. Pixel velocity only considers camera moving but not camera rotating. I detected that my transformation from ndc to eye-space is not correct but i don't know how to fix it.

I linearzie the the depth value from depthbuffer as follows:

lin_depth = 2 * near / (far + near - depth * (far - near))

I tested that linearization in my application and it seems to be correct.

Now i define the NDC as usual:

vec3 NDC = vec3(window.x * 2 - 1, window.y * 2 - 1, lin_depth);

I compute the clip-Position w as i found here https://www.opengl.org/wiki/Compute_eye_space_from_window_space#From_NDC_to_cl ip:

float Cw = projectionMatrix[2][3] / (NDC.z - projectionMatrix[2][2]);

Now i should be able to get the eye-Position with the inverse Projection

vec4 eyePos = (inverseProjectionMatrix) * vec4(NDC * Cw, Cw);

but as i tested these computations in my application, the eye space position i get is wrong.

My projection Matrix is defined as follows:

1/(tanFOV*aspect) 0 0 0

0 1/tanFOV 0 0

0 0 (-zNear-zFar)/(zNear-zFar) 2*zFar*zNear/(zNear-zFar);

0 0 1 0

Remember at my Cw-calculation i send the matrix transposed to the glsl-shader.

Tanks in advance if somebody can help me!

greetings, Fynn Fluegge