• Advertisement
Sign in to follow this  

Implementing motion blur

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

first of all i am not implementing motion blur for a developing game but for a developed game.yes i am adding this to compiled game by directx8 hooking.i created the hooking dll now how and where to add them.got a basic idea from other forum ------------------------------------------------------------------------ A) Render everything to a texture the size of the backbuffer. B) Render this texture to your backbuffer using a quad that covers the whole screen. C) Render the texture a second time to your backbuffer, this time the quads alpha set to 1/2 and offset by 1 pixel to the left. D) Render the texture a second time to your backbuffer, this time the quads alpha set to 1/3rd and offset by 1 pixel to the right. E) Render the texture a second time to your backbuffer, this time the quads alpha set to 1/4th and offset by 1 pixel up. F) Render the texture a second time to your backbuffer, this time the quads alpha set to 1/5th and offset by 1 pixel down. Now to make motion blur only a few changes need to be made. One is that you wish to start with the previous frames blured image already in texture rather that with a clear texture (you would still want a fresh zbuffer) and the other is that you want to fade the initial texture a bit which can be accomplished by either rendering a mostly transparent black quad over it or by adjusting the quads vertex colors. ------------------------------------------------------------------------- now how to implement this in a hooking way.some code would be great!!.pls help thanks

Share this post


Link to post
Share on other sites
Advertisement
I think you can use the multisample parameters in the presentation parameters to get a motion blur. At least I read that in a book, but haven't tried it out yet.

Share this post


Link to post
Share on other sites
ok now i got the texture created from back buffer,next how to render it back to back buffer which is B) to F).

Share this post


Link to post
Share on other sites
First off, reading from the buffer is slow and should be avoided. If you want to do it using the fixed pipeline render the scene to a texture FIRST and then you can display it with a screen-aligned quad. You can do this several times with various alpha blending with slight offsets to get a decent blur. Alternatively (and this looks nicer, in my opinion) you can use an accumulation buffer using the following procedure:

1) Render frame 1 to a texture and display it with a quad
2) Render frame 2 to A TEXTURE, alpha blend frame 1 with frame 2 and render to ANOTHER TEXTURE(not displayed to the screen yet)
3) Now display the result of the 1+2 render.
4) On frame 3 you will combine the result of the last frame (ie. 1+2) with the new frame (ie. Frame 3)

This sounds kind of confusing but it's actually much simpler to implement than it sounds. To vary the amount of blur you change the ratio between the last frame and the new frame -- for instance, (0.6(last) + 0.4(new) = 1) will give you a decent blur but not huge. The closer the last frame gets to 1.0 the more blur you will get. A value of 1.0 will accumulate completely and just give you a white screen. 0.0 will give no blur.
I would recommend doing this in a pixel shader however. It is much simpler and it will be a lot faster -- as it can run on the GPU which handles this type of thing with ease. In fact, all it requires is a one-line pixel shader as follows

////////////////////////////////
texture last_frame;
texture this_frame;
float4 ps_blur(...)
{
return lerp(last_frame, this_frame, 0.6);
}
/////////////////////////////////

I hope this helps.

Share this post


Link to post
Share on other sites
The best solution that I've seen is to implement a form of "accumulation buffer"

I wrote a VB6 version that you can download (source code zip), based on a chapter from Kelly Dempski's Real-Time Rendering Tricks and Techniques in DirectX.

Basically, you create a texture of similar size to the screen (you could simulate super-sampled AA if you make it bigger, or spacial blur by making it smaler) and using it as your primary render target. That is, for each frame you clear ONLY the render target texture. At the end of each frame you render this texture using a TLQuad (with vertex defined alpha) to the main backbuffer using alpha blending.

The net result is that the image that's displayed on-screen is the accumulation of the previous ~10 or so frames (depending on what alpha value you use).

I particularly like it as (with some funky maths) use it to simulate a photography/film like approach to rendering an image. Anything that moves whilst the shutter is open will be blurred. However it also "settles down" if geometry and/or camera stays still for a while.

For some reason, the other type of approach (extruding geometry along a velocity vector for example) always looked very artificial to me.

Jack

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement