# How to get depth texture for the motion blur

This topic is 2749 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am following GPU gems tutorial for motion blur. I am unable to understand how to get depth buffer texture.

// Get the depth buffer value at this pixel
float zOverW = tex2D(depthTexture, texCoord);
// H is the viewport position at this pixel in the range -1 to 1.
float4 H = float4(texCoord.x * 2 - 1, (1 - texCoord.y) * 2 - 1, zOverW, 1);
// Transform by the view-projection inverse.
float4 D = mul(H, g_ViewProjectionInverseMatrix);
// Divide by w to get the world position.
float4 worldPos = D / D.w;

// Current viewport position
float4 currentPos = H;
// Use the world position, and transform by the previous view- projection matrix
float4 previousPos = mul(worldPos, g_previousViewProjectionMatrix);
// Convert to nonhomogeneous points [-1,1] by dividing by w.
previousPos /= previousPos.w;
// Use this frame's position and last frame's to compute the pixel velocity
float2 velocity = (currentPos - previousPos)/2.f;

// Get the initial color at this pixel
float4 color = tex2D(sceneSampler, texCoord);
texCoord += velocity;
for(int i = 1; i < g_numSamples; ++i, texCoord += velocity)
{
// Sample the color buffer along the velocity vector
float4 currentColor = tex2D(sceneSampler, texCoord);
// Add the current color to our color sum.
color += currentColor;
}
// Average all of the samples to get the final blur color

float4 finalColor = color / numSamples;

This is the code mentioned in the GPU gems tutorial.

##### Share on other sites
This has little to do with Math & Physics, so you sort of posted this in the wrong place

You get the depth buffer by either rendering to it by drawing to multiple render targets when you do your normal drawing, drawing the distance of each pixel from the camera to the depth texture target.

Or, if your hardware and software API allow it, you can access the GPU's depth buffer directly.

Tell us what technologies you are using, and maybe we can tell you more about how to do the corresponding method.

1. 1
Rutin
37
2. 2
3. 3
4. 4
5. 5

• 11
• 15
• 12
• 14
• 9
• ### Forum Statistics

• Total Topics
633352
• Total Posts
3011483
• ### Who's Online (See full list)

There are no registered users currently online

×