Sign in to follow this  
Volgogradetzzz

2D motion blur with velocity map

Recommended Posts

Hello! I want to implement this cool effect but there's some problems that my old brain can't solve by himself. After some digging I know that I should render velocity map and use it for blur. Also I know that all that staff is done as postprocess - i.e. in fragment shader. And this is the point I can't understand. Let's assume that I want to motion blur horizontaly moving box. Lets assume also that I have velocity map - it's the same box, but in red and green color (for example). And what next? How can I blur exactly box (and not background), how can I draw blurred tail?

Share this post


Link to post
Share on other sites
Blurring just the moving areas is easy, you're just taking a handful of samples starting from the current pixel along the motion vector. If there's no motion, all the samples end up on the same pixel, and thus there's no blur. (however, you can try to early-out in this case; I leave that as an exercise)

Trails, on the other hand, are bloody murder. The most common solution I've seen is basically a smart blur that smears the motion vector from adjacent pixels if said vector happens to intersect the pixel being shaded. The problem with this is that adjacent pixels with differing velocity can cancel each other out entirely (this can happen if, say, two objects that overlap onscreen are moving in the opposite direction, and is more common in practice than you'd think) which is pretty much impossible to solve nicely :(

Share this post


Link to post
Share on other sites
Thanks. So, as I understand blurring is simple anought - I just need to sample fragments along velocity vector. Adding trail is much harder and it can't be done as postprocess - I need to draw object several times 'between' frames.

Share this post


Link to post
Share on other sites
if you want to blur the box, not the background, you could use compute shader/opencl/cuda. in your velocity map, you'd read the pixel color of the box and the velocity map to figure out the position of the last frame for this pixel, and you'd blend the pixel with the existing image.
two important points:
-blending would need to be done with atomics
-blending the whole line per pixel might be too expensive, you might want to use some stochastic writing of the pixel (random positions inbetween)

Share this post


Link to post
Share on other sites
What i found to work well was to only consider points for blurring that have similar velocity.

Share this post


Link to post
Share on other sites
[quote name='Volgogradetzzz' timestamp='1335891640' post='4936457']
Thanks. So, as I understand blurring is simple anought - I just need to sample fragments along velocity vector. Adding trail is much harder and it can't be done as postprocess - I need to draw object several times 'between' frames.
[/quote]

Not necessarily, just that dilation is an expensive and error-prone process. (at least for a high-quality implementation)

Everything above happens in post.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this