Vector Motion Blur (Update: Now works on AMD GPU!)

Hello there Blenderheads.

This is my experiment creating Vector Motion Blur using BGE GLSL. It still far from perfect and only based by camera movement. My method based from blogpost by John Chapman (http://john-chapman-graphics.blogspot.co.uk/2013/01/what-is-motion-blur-motion-pictures-are.html)

Here’s the screenshots:

https://dl.dropboxusercontent.com/u/17547612/GLSL%20Experiments/screenshots/motion%20blur/mblur_1.png

https://dl.dropboxusercontent.com/u/17547612/GLSL%20Experiments/screenshots/motion%20blur/mblur_2.png

Here’s the video demo:

https://youtu.be/pxn7Bp0wa7s

And, here’s the blend file (UPDATED to v0.7, works with skybox).
You may use it whatever you want.

My techniques are using video texture placed in front of camera. It’s because custom filter2D simply isn’t flexible. For example, custom filter2D cannot input sampler2D. It only input from color and depth texture (and maybe illumination map). This won’t work because Vector motion blur need to use linear depth map.

There’s drawback using Blender video texture too. As far as I know, video texture can only properly rendered using power of two size (source.capsize). Not only that, it will bottleneck or even broke your render if capsize is bigger that your actual screen/window size. I don’t know if this is bug or Blender limitation? Do anyone know about this?

I’m planning update this shader using per-object motion blur. John Chapman already post about this topic too (http://john-chapman-graphics.blogspot.co.uk/2013/01/per-object-motion-blur.html). Just stay tuned :wink:

And, if anything don’t go wrong, I’m going to implement this shader to my The Raid corridor demo. You can see the gallery on my Google+ page.

Have fun! :smiley:

Great work! This will be a great asset to a lot of people- thanks for posting it!

Nice! thanks for share this cool effect, I’m looking forward for per-object motion blur.

EDIT: I tested it and I’m getting around 4 to 5 fps, is really that slow?

Really nice!

But does not work in standalone blenderplayer, and some resolutions to cause problems. This needs more work.

For example, If I set the resolution to 1920x1080 the aspect of the image at standstill is different from when I move the camera. Maybe the plane needs to be in the seem aspect as your camera aspect? 4:3 or 16:9 etc?

EDIT: When I zoom in so that I do not see the borders of the camera, then I get the aspect error. Does not happen in standalone player, since you get the camera exactly.

Then, the shader does work in standalone, this is because of something in the code i cannot find at the moment. But it seems that the texture is not being rendered. Or is the shader not running at all in standalone?

EDIT: By removing “import bpy” it does work in Standalone.

EDIT2: Works really nice, I have been missing this type of motion blur!

One problem I see is that shaders on a plane does not work well with materials that are using alpha.

This is how my transparent clouds look like, and this is glitchy, sometimes it works, sometimes not. (This is a half dome with a alpha cloud texture)


This may just be a problem with my specific hardware, but I get really poor framerates with this demo. I have an AMD 5970 (dual gpu) and AMD fx 6100 (6-core cpu) with 8gb ram. I’m pretty sure I should be able to run this. The lag is coming from logic (~130ms/84%). Know what the problem might be? I would really love to mess with this as it looks stunning :smiley:

Wow that seems to work really well! I get quite a bit of lag from it, but I found a way to speed it up. Just by lowering the resolution of the videoTexture it can go up to 200fps for me :smiley:

The line looks like this for anyone who cant find it:


texsize = [512, 512]

I changed the values to 256,256 and it still looked pretty good :smiley:

I am also getting rather poor performance. I believe it might have something to do with AMD/ATI cards. Even with lowering the resolution and sample sizes to 32x32, 8 samples and 4 samples only gives 2 fps, totalling 5 fps.

Thanks for all your response.

I know the code need to be optimized. But some thing need to be considered first:

  • Your texsize cannot be bigger than your actual size of window or viewport. For example, your texsize is 512x512, but your render region is 640x480, because 512 is bigger than 480, then your render will bottlenecked. I don’t know if this Blender limitation or a bug.
  • I have updated the code (see bottom of this post), so it can take blur samples lower than two. My default samples is 16 (1st pass) and 8 (2nd pass) is maybe considered caused some performance problem. Try to lower it down (actually I have lower the default to 8 and 4).
  • I tried this demo on Radeon 3300 (onboard GPU) and Radeon 6310. It runs slow as hell, even when I set samples to 1 and 1. I don’t have another Radeon card to test. So I don’t know if it’s because of slow GPU or maybe there’s something else. I’m using Geforce 660 as my main GPU, it runs very fast, I can even use 1024x1024 texsize when using Blender at fullscreen (using 1920x1080 resolution). I will investigate this later.

No, any aspect ratio is okay, but your camera border cannot be bigger than your window/viewport.

I need bpy to get background color. I know bpy don’t supposed to be in game script. But I can’t figure out another way. Here’s my code to get background color.

# well, I found no easy way to render background color to texture
bg_r = int(pow(bpy.context.scene.world.horizon_color.r, 1/gamma) * 255)
bg_g = int(pow(bpy.context.scene.world.horizon_color.g, 1/gamma) * 255)
bg_b = int(pow(bpy.context.scene.world.horizon_color.b, 1/gamma) * 255)
bge.logic.colorTex.source.background = [bg_r, bg_g, bg_b, 255]

Do know some kind of trick to do that without bpy?

I haven’t got time to messing around with alpha texture in the background. Maybe you can share the blend, so I can easier to figure out the problem. :smiley:

I’ve updated the blend file to v0.51, changes:

  • You can input blur samples below 2 (means no blur at all), when you set blurPass2Samples to less than 2, means pass 2 won’t happen at all (will improve performance)
  • Change default samples to 8 (blurPass1Samples) and 4 (blurPass2Samples)
  • Tidying code and comments a bit

You can download the blend file here.

Still 5 fps, there should be something with the AMD cards, I hope you can figure it out what is wrong.

Maybe you can tell me what is your AMD GPU type?

10 fps…my pc is very bad, but i think this is exaggerated, the driver card is a Intel® G41 Express Chipset of 512mb. sorry english.

PD: reducing the size of the texture to 8x8 not help.

At the default settings, this blend works 60 fps- I’m using a GTX 460 though.

Found (part of) the problem: Disable “use frame rate” in the render settings. Getting ~30fps. Still not great, but much better, although logic is still 90-95% of the usage.

hey ucupumar,
awesome stuff! Your vector blur blend file is a goldmine of resources for me :slight_smile:
A lot of new ideas came up while playing around with the vector blur.
Thanks for sharing!

You’re welcome, Martin. Your amazing BGE demos inspired me to learn GLSL and BGE. :o
I’m glad my script could be helpful to you. :smiley:

Maybe, I haven’t checked on Intel GPU. I already post the problem on bug tracker. You just need to be patient. :eyebrowlift:

Nice work sir!!!

60 fps on a 7750! Yaaaay, this effect is really good. Thankyou so much.

Edit: ~450 - 500 fps in fullscreen 4:3 and ~420 fps in fullscreen 16:9. Very impressive.

  1. This does not work good with shaders, maybe you can figure out what is wrong: http://www.mediafire.com/download/mek5ffm4y2gw04b/vector_motion_blur_v0.6_w_shaders.blend (Change time of Day with ‘Z’!)

  1. Also, the 0.6 version does not play in the Standalone Player.

That crashes straight away for me, I’m afraid if that’s not the issue for you then I won’t be the one to help you. Sorry.

Thanks BluePrintRandom and Hellooo.

  1. I have looked the file. I think it will take couple of time to investigate.
  2. I guess I need to solve this problem first. I still use bpy in this version to get background color. Looks like a bit tricky to solve.