Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am not sure how right it is to ask this question, but still here it goes.

I have a full 2D environment, with sprites going around as landscape, characters, etc And to make it more state-of-art looking, i want to implement a motion blur effect, similar to modern FPS's (i.e. crysis) blur when moving fast the camera.

In a sidescroller, the desired effect is having this slight blur appearing to give the idea of fast movement, when the camera is moving. If anyone could give me some tips on doing this, im assuming in a pixel shader, i'd be grate.

Also, if anyone has other good tips on cool pixel shader effects for 2D games it would be awesome, like some stylizing post fx, such as previous Prince of Persia illustrative style.

Thanks

share|improve this question
    
Keep multiple copies of your rendered buffer. For example, blur four of the previous frames to create your current frame. That should create the effect you want. –  knight666 Feb 19 '11 at 10:23
    
@knight666 wouldn't it be better (memory certainly, speed I'm not sure) to keep 1 extra buffer (call it A) and than mix a fraction (say 0.75) of that with the output buffer (going to the screen, call it B) and then copy B to A afterwards. This would create a rolling average and increasing motion blur wouldn't cost anything extra. –  Kevin van der Velden Feb 19 '11 at 15:44
1  
I meant to make this a comment, but couldn't find the comment button. Anyways, what Dave O. says is probably you're best bet and what's used in games like Crysis. This works a bit like this. During object render, Render object velocities into a separate buffer. MRT will make this a bit quicker, and there are multiple ways to compute the velocities, but you want to end up with an additional buffer that has the velocities for the entire render buffer. Then in a post-process shader, based on the velocity at every pixel, you sample into the color buffer in the opposite direction of the veloc –  Arelius Feb 23 '11 at 20:03
    
The HLSL/Cg code in Listing 27-1 uses the previous equations in a full-screen post-processing pixel shader to compute the world-space position of the objects rendered at a given pixel, using the depth buffer and the inverse of the current view-projection matrix. ... HLSL.... In your code it's not GLSL ..... –  user18122 Jul 18 '12 at 8:48

2 Answers 2

up vote 5 down vote accepted

Keep a copy of the last framebuffer. Get the camera movement vector and invert it. Draw your scene as usual, then draw the last framebuffer with a slight offset (the camera delta you just calculated) and 0.75 alpha. Repeat as many times as you like to give the motion blur effect.

share|improve this answer
1  
This approach is very easy to implement but very hard to fine tune (it can look like objects leaving traces instead of being blurred). Another also simple approach is to "smear" pixels in the inverted camera movement direction in a post processing pixel shader. –  Dave O. Feb 20 '11 at 2:31
1  
The main problem with this approach is that it's framerate dependent - it'll look very different if you're running at 20 fps to how it looks if you're running at 100 fps. So long as you're aware of that and get the result you want at the framerate you run at it's fine, but you do need to be aware of it. –  Darth Satan Jul 18 '12 at 11:50

I would recommend using this method : Motion Blur as a Post-Processing Effect

Very simple to implement, it's the one I used in my glsl demo Ruin island [link]

share|improve this answer
    
This method is far superior to blending in past frames... –  Steven Lu Feb 15 '12 at 15:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.