Motion blur for Unity 3

I’ve worked out the kinks in my motion blur implementation for Unity 3. I basically did this:

http://wiki.gamedev.net/index.php/D3DBook:Motion_Blur

It has the usual bleeding problems of this sort of approach, and I didn’t do anything to fix them.

I actually had this working six months ago, but it took a while for Unity 3’s rendering pipeline to stabilize, and then more time for me to bother making it compatible with Direct3D.

Here’s what it looks like:

To use it:
• Attach MotionBlurEffect to your camera (CameraInfo is also required but will be attached automatically).
• Attach ObjectBlur to all objects which you wish to blur. The easiest way to do this is to choose Custom>Add Object Blur, which will attach it to all selected MeshRenderers that don’t already have the script.
That’s it! Objects will blur when they or the camera move, for any reason other than skinned mesh animation. Unfortunately I can’t think of a way to support skinned mesh animation using this technique in Unity.

Note that you need ImageEffectBase.cs from the Image Effects (Pro Only) package in order for this script to work.

The attached package has a demo scene with draggable objects that use the blur script.

Let me know how it works or doesn’t work for you.

Update: v4 has better comments and removes the unused minimumVelocity variable.

391748–13485–$motion_blur_v4unitypackage_203.zip (319 KB)

very nice

Wow,this implementation seems so sleek and clean compared to my rather hamfisted approach
runs miles faster too,I’m sure :wink:
kinda makes me feel ashamed,but oh well,it’s been a learning experience
Could you post a demo for us 2.6 folks?

I’m guessing motion blur for skinned meshes can only be done with a per pixel motion vector based solution.

Still, this looks interesting.

Unfortunately I have lost the 2.6 version of the code. The current version could be back-ported, but I don’t have the time right now. The obvious changes that come to mind are:

.NET 3 things:
HashSet → Dictionary
auto-implemented properties
Unity 3 things:
Unity matrix names
velocity storage format

Velocity storage relies on the Unity 3 UnityCG functions for storing and reading floats encoded in two channels of a texture. I’m guessing that Aras would be Ok with people copying those and using them in Unity 2.

It should work fine using per-vertex velocity, but the issue is how to get the previous position of each vertex. Since Unity handles all the skinning transparently on the CPU, I don’t know how you’d get that information into the shader.

Looks sweet Daniel. Does it work on iPhone? If so, what’s the performance impact?

Certainly not as-is. I should be getting into iPhone programming sometime soon, so I’ll have a better idea of its capabilities under Unity 3.

Can’t you find vertex positions from the Depth Buffer…?

This link seems interesting :

No, only fragment positions. But where do you think that this might be useful?

Looks great! Nice work!

I’ve cleaned up the code a bit and uploaded v4. Hopefully the comments will help people understand how it works. I also removed the minimumVelocity variable, which I’d stopped using because it wasn’t a good optimization.

Sorry for the thread necromancy but i wonder if somebody knows how to make this work when you have two cameras instead of one and one of them is set to “depth only” (you know, typical case of a FPS weapon camera). I tried with two cameras and shows everything in gray.

Thanks.

This is a very sweet motionblur effect. Just tested it right now, and it harkens Resident Evil 5. haha

Thanks for the share!

Grate! thanks pal!

I tested it and works phenomenal! but i wondering if it some day is coming to work with character animations, right now it’s works when the object is moving but is the object have translation 0 and just play a animation Idle, Kick, Punch don’t work :frowning:

I’m having the same problem.

Thank you so much for this code.

I added another camera (depth-only) to the demo scene and it worked (no gray). If I get the same problem later, I’ll mention it, since I’m making a FPS.

Hey this is great, thanks so much. the demo scene works well.

I would like to know, does this work for a moving camera? does it calculate the velocity relative to the camera, or just the absolute velocity of objects themselves?

Also, I’ve started to apply it to objects in my own scene but it causes a serious flickeryness. Any ideas what could be wrong?

It seems that i files in the package are corrupted o.o can you re-upload it again?

another question, does this work with multiple cameras? o.o

It works for me. Make sure you’re not letting your zip program decompress the package itself. I think it should work with multiple cameras.