Skip to main content
gamedev.net
🔒 Locked

2D motion blur with velocity map

Started by Volgogradetzzz 4 replies 2k views
Original Post
Volgogradetzzz
Volgogradetzzz
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?
InvalidPointer
InvalidPointer
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
clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.
Volgogradetzzz
Volgogradetzzz
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.
Krypt0n
Krypt0n
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)
InvalidPointer
InvalidPointer

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.


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

Everything above happens in post.
clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.