Cheap, Faked Motion Blur (Pro Edition)

Posted By: Ichiro

Cheap, Faked Motion Blur (Pro Edition) - 06/20/06 17:27



I tried my hand at a largely-framerate-independent motion blur, and figured I'd put it out there for some feedback/bashing/improvement. This basically renders a camera view to a bitmap on a transparent panel, then changes that panel's alpha based on the framerate and desired blurring. First, we define the panel:

Code:
// Load in a blank 1024x768 bitmap to render to:
bmap bitmap_motion_blur="bitmap_motion_blur.tga";

// This is the panel that contains that bitmap:
panel panel_motion_blur {
bmap = bitmap_motion_blur;
layer = -1;
flags = transparent;
}



(See www.dejobaan.com/misc/bitmap_motion_blur.tga for the bitmap_motion_blur I'm using.) Next, we create the function that we use to set the blur amount:

Code:
var motion_blur;
// This essentially sets the transparency (alpha value) of our view at 100fps. Call with values of 0..100:
function set_motion_blur(newval) {
motion_blur=newval;

if(newval==0) {
// No blur; shut off the panel:
panel_motion_blur.visible=0;
camera.bmap = 0;
} else {
// Blur is positive:
panel_motion_blur.visible=1;
camera.bmap = bitmap_motion_blur;
}
}



We then change the panel's alpha value (call this once per frame) to account for framerate:

Code:
if(motion_blur) {
panel_motion_blur.alpha = 100 - pow( ((100-motion_blur)/100), (time/0.16) )*100 ;
}


Changing the amount of motion blur is, then, a simple call to motion_blur(<blur alpha 0..100>).

There are a number of problems with this approach; for example, any semi-transparent panels will appear slightly less transparent. (This is most noticable when motion_blur() is called with low values.) Also, it requires A6 Pro, since it uses the pelican rendering option.

However, it (somewhat) mitigates my largest concern, which is that without the constant re-evaluation of the panel's alpha value, the blurring varies wildly with framerate.

Any thoughts?
Posted By: Grafton

Re: Cheap, Faked Motion Blur (Pro Edition) - 06/20/06 20:05

I just tried your approach and I think it works suprisingly well!

I wouldnt think the re-evaluation of the panels alpha while the blur is
enabled would be much of a problem, in fact it seems a good idea.

I havent experimented with other panels that have transparency, but if it
causes a noticable, bothersome problem on a prominent semi-transparent panel,
perhaps the affected panels' alpha transparency could be adjusted while the
blur is active?

I changed the set_motion_blur function in mine to fade the blur out when
you "turn it off" instead of it just ending abrubtly like this;

Code:

function set_motion_blur(newval)
{
motion_blur=newval;

if(newval==0)
{
// No blur; shut off the panel:
while(panel_motion_blur.alpha < 100)
{
panel_motion_blur.alpha += 3*time_step;
wait(1);
}
panel_motion_blur.visible=0;
camera.bmap = 0;
}
else
{
// Blur is positive:
panel_motion_blur.visible=1;
camera.bmap = bitmap_motion_blur;
}
}



You always come up with the most amazing stuff Ichiro! Thanks for sharing this.
Posted By: PHeMoX

Re: Cheap, Faked Motion Blur (Pro Edition) - 06/20/06 23:45

Very cool indeed !! Judging from your screenshots, the effect is pretty convincing . So all you use as render target is a fully black tga as transparent panel? Nice,

Cheers
Posted By: William

Re: Cheap, Faked Motion Blur (Pro Edition) - 06/21/06 02:15

Yeah, this effect looks very good. There is no problems with transparent panels solong their layers are higher than the blur panel. The only problem that I can find is that Spheres bloom effect doesn't work along with this. When you turn bloom on, the screen slowly turns white and multi-colored. Any ideas? This is great, i'd have it as a feature if it only works with bloom. Looks great with turboboosts. Thanks for sharing.
Posted By: Grimber

Re: Cheap, Faked Motion Blur (Pro Edition) - 06/21/06 07:04

you could try something similar with a 2nd view overlaying the first ( with an alpha transparentcy to teh view

i tried something similar a while back by placing 2 view cameras ( left and right of the center of view point) which thier views overlayed the main view. then all 3 views rotated to focus at one particular spot ( used a trace to simulate varing distant focal point)

rather like how our bifocal eyes work

you can even then tweak the bluring view arc for more distorted stretch
Posted By: Ichiro

Re: Cheap, Faked Motion Blur (Pro Edition) - 06/21/06 15:01

I changed the set_motion_blur function in mine to fade the blur out when
you "turn it off" instead of it just ending abrubtly...


That's a good idea; in fact, I'll have to try having it slide around according to the player's speed and so forth as well.

So all you use as render target is a fully black tga as transparent panel?

Yep; though that brings up a good point -- what's the best bitmap format to use? I'll have to try 565, 888, and 8888.

When you turn bloom on, the screen slowly turns white and multi-colored. Any ideas?

I'm not familiar with Sphere, but perhaps overlaying the entire scene with a semi-transparent black bitmap?

you could try something similar with a 2nd view overlaying the first

I'll give that a try. I'd like to do that without having to render the view twice, though. I'll open a new thread on that.
Posted By: EdMercer

Re: Cheap, Faked Motion Blur (Pro Edition) - 06/21/06 20:17

Man, I've tried your 'temporal anti-alias' (since you don't like to call it a *real* motion blur) and it works wonders ! I've 'wired' the ammount of blur to the player speed and it gives a great illusion ! I'll try out some other formats as well to see if there's a big performance impact.

Keep it up !
Posted By: Ichiro

Re: Cheap, Faked Motion Blur (Pro Edition) - 06/21/06 23:23




I've 'wired' the ammount of blur to the player speed and it gives a great illusion !

That's a great idea; I gave that a try, and it's really neat to see everything blend together at high speeds.

I stuck a vid up here (38MB, XviD), for anyone interested. The compressed video is a bit blurry, so it makes it tough to tell when the in-engine blur is taking place(!)
Posted By: PHeMoX

Re: Cheap, Faked Motion Blur (Pro Edition) - 06/22/06 15:34

Hhaha! Very nice movie, I think that gameplay seemed pretty interesting too by the way.

I don't know why, but the movement physics reminded me a bit of the good 'ol Battlezone, must be because of the cool gravity. Anyways, yeah the blur effect is hard to see in the movie, but when the player reaches the level's edge, you'll see it... When everything goes like it should, I'll be having pro within a week or so, and I can't wait already to experiment with this code!

Cheers
Posted By: XNASorcerer

Re: Cheap, Faked Motion Blur (Pro Edition) - 06/23/06 22:16

Yes, really nice effect!
Posted By: PHeMoX

Re: Cheap, Faked Motion Blur (Pro Edition) - 07/03/06 13:31

Hmmm, guys I'm having a bit trouble figuring out how to properly set this up. I've added all the code and added the 'If' loop that evaluates the panel's alpha too. (inside the while loop of the camera).

However it gives me a transparent blue on top of my screen, but no blur or not big enough to see. What do I do wrong?? The code is basically the same..

Cheers
Posted By: Grafton

Re: Cheap, Faked Motion Blur (Pro Edition) - 07/03/06 15:10

Could it be that the tga bitmap isnt the same size as the resolution you are
using?

Try including this blur script, an toggle it with the B key;
Code:

//==================================================
// motion_blur.wdl
//==================================================

// Create a blank black (rgb = 7,7,7) bitmap the same size as the screen resolution to render to:
bmap bitmap_motion_blur="bitmap_motion_blur.tga";

// This is the panel that contains that bitmap:
panel panel_motion_blur
{
bmap = bitmap_motion_blur;
layer = -1;
flags = transparent, filter;
pos_x = 0;
pos_y = 0;
}

var motion_blur;

// This essentially sets the transparency (alpha value) of our view at 100fps. Call with values of 0..100:

function set_motion_blur(newval)
{
motion_blur=newval;

if(newval==0)
{
// No blur; shut off the panel:
while(panel_motion_blur.alpha < 100)
{
panel_motion_blur.alpha += 3*time_step;
wait(1);
}
panel_motion_blur.visible=0;
camera.bmap = 0;
}
else
{
// Blur is positive:
panel_motion_blur.visible=1;
camera.bmap = bitmap_motion_blur;
}
}

starter mot_blur()
{
while(1)
{
if(motion_blur)
{
panel_motion_blur.alpha = 100 - pow( ((100-motion_blur)/100), (time/0.16) )*100 ;
}
wait(1);
}
}

var blur_value;

function toggle_blur
{
if( blur_value > 0){ blur_value = 0;}
else{blur_value = 18;}
set_motion_blur(blur_value);//higher = less blur
}

on_b = toggle_blur;



Posted By: Ichiro

Re: Cheap, Faked Motion Blur (Pro Edition) - 07/03/06 15:11

My first guess would be that the camera.bmap isn't taking bitmap_motion_blur for some reason. Try moving panel_motion_blur's pos_x and pos_y around. If the view doesn't move, but the blue overlay does, then that's the culprit.

Of course, that still leaves the question of how to fix it, or why it works differently; I think we're using the same version of A6.
Posted By: PHeMoX

Re: Cheap, Faked Motion Blur (Pro Edition) - 07/03/06 16:08

Nope, that's not it eiher, my resolution is 1024x768 ...

Could this be the effect of an update gone wrong somehow? The refraction shader of Oliver2, originally released in time of A6.31 and off course for A6pro only, works great here. Also a render-to-texture something, albeit with a shader. I'm not sure if this shader is supposed to still work with A6.40.5 pro, but it does work here.

Do you guys use a skycube or something else as a background? It's remarkable that my background color is 0,0,0 (which shows as blue) and the color that panel looks like is also blue-ish. Take a look at this screenshot:


This time I've totally replaced the code with the one Josiah gave,

Edit:
Quote:

If the view doesn't move, but the blue overlay does, then that's the culprit.




I've added a line that changes the pos_x to -300, but it moved the entire view and on the right there's even more blue visible (fully opague that is :S ),

Edit2: When I try to render the panel none-transparent it doesn't show, so this must mean it doesn't get written at all, just like you thought Ichiro. :s I really wonder how on earth I could fix this though,

Cheers
Posted By: Ichiro

Re: Cheap, Faked Motion Blur (Pro Edition) - 07/03/06 16:45

Weird. Anyone else having this problem? I can confirm that it works under 6.40.5 Pro, as that's what I'm using here.
Posted By: PHeMoX

Re: Cheap, Faked Motion Blur (Pro Edition) - 07/03/06 16:58

It's getting weirder, because I've just managed to get your other code field depth vision to work. I did changed the layers (from -1,-2 to 19 and 20), but it can't possible be that since it gave a blue layer on top.

I've also changed the tga file a few times, even tried stuff with colored tgas, saved as 24bit. I also added a hollow cube around my level, but I guess I could take that one away again.

Anyways, it must be something I did wrong at some point with this code, or render-to-texture started working properly again somehow, because I got depth field vision working now, I guess all I have to do is strip this code down to get the motion blur,



Cheers
Posted By: EdMercer

Re: Cheap, Faked Motion Blur (Pro Edition) - 07/03/06 17:40

@PHeMoX:

You're using shaders along with the blur effect, right ?

I was able to make the code work on my testbed code here, but when I merged it with our latest tarball (wich includes all shaders/effects we intend to ship in the final version) the motion-blur started to act exactly like yours. I has nothing to do with the code 'per se' but an incompatibility with some shader. I'll try to disable them one-by-one to see if I can isolate the culprit.
Posted By: PHeMoX

Re: Cheap, Faked Motion Blur (Pro Edition) - 07/03/06 22:18

Yeah, I think I know what you're talking about, I'm not using any shaders yet in the screen I've posted to get the effect though, however in my code there are shader codes.

That might very well explain some of the odd behavior, even if they are not active. Did you mean this? The effect itself as shown on the screenshot doesn't use a shader atm. I'm planning to change that though and add a shader, we'll see what happens then.

I have to add to the incompatibility issue by the way, that sometimes my stencil shadows dissappeared too .. it must be something out there that's causing all this, I swear the upper screenshot has exactly the same code as Ichiro first posted, so it's definately not the code. It might have got to do something with render-to-texture, maybe this isn't as stable and consistent as we all expect it to be?

Cheers
Posted By: Stansmedia

Re: Cheap, Faked Motion Blur (Pro Edition) - 07/05/06 04:23

I have a problem...


Posted By: PHeMoX

Re: Cheap, Faked Motion Blur (Pro Edition) - 07/05/06 15:12

Mmmm, wow, I never had that problem, but is your code exactly the same as the code first posted by Ichiro?

Cheers
Posted By: Stansmedia

Re: Cheap, Faked Motion Blur (Pro Edition) - 07/05/06 16:12

Code:
 
// test.wdl

// Load in a blank 1024x768 bitmap to render to:
bmap bitmap_motion_blur="bitmap_motion_blur.tga";

var video_mode = 6;

// This is the panel that contains that bitmap:
panel panel_motion_blur {
bmap = bitmap_motion_blur;
layer = 5;
flags = transparent;
pos_x = 0;
pos_y = 0;
}

var motion_blur;
var newval;
// This essentially sets the transparency (alpha value) of our view at 100fps. Call with values of 0..100:
function set_motion_blur(newval)
{
motion_blur=newval;

if(newval==0)
{
// No blur; shut off the panel:
while(panel_motion_blur.alpha < 100)
{
panel_motion_blur.alpha += 3*time;
wait(1);
}
panel_motion_blur.visible=0;
camera.bmap = 0;
}
else
{
// Blur is positive:
panel_motion_blur.visible=1;
camera.bmap = bitmap_motion_blur;
}
}

function main()
{
level_load("test.wmb");
wait(3);
set_motion_blur(30);
while(1)
{

//if(motion_blur)
//{
panel_motion_blur.alpha = 100 - pow( ((100-motion_blur)/100), (time/0.16) )*100 ;
//}
wait(1);
}
}


Posted By: Ichiro

Re: Cheap, Faked Motion Blur (Pro Edition) - 07/05/06 20:40

That almost looks like a problem I was having in an earlier version of A6 Pro. If you're using the last production version of the engine (6.31.4?), you try it with the latest beta (6.40.xxx).
Posted By: Stansmedia

Re: Cheap, Faked Motion Blur (Pro Edition) - 07/05/06 20:57

That fixed it right up. I run at about 200 fps in a small room with some blocks. It works very well. Thanks so much for sharing.
Posted By: taipan

Re: Cheap, Faked Motion Blur (Pro Edition) - 08/02/06 13:49

This should be moved or re-posted in user contributions Superb!
Posted By: DarknessW

Re: Cheap, Faked Motion Blur (Pro Edition) - 10/28/06 20:37

someone could please upload an editable demo of motion blur?
cuz I tried this script several times, and nothing happens.
Posted By: ExtraCortex

Re: Cheap, Faked Motion Blur (Pro Edition) - 10/29/06 22:37

cool!!!
Posted By: Ichiro

Re: Cheap, Faked Motion Blur (Pro Edition) - 11/03/06 19:48

Quote:

someone could please upload an editable demo of motion blur?
cuz I tried this script several times, and nothing happens.




Not sure if this is the problem, but I believe you need A6 Pro to run the script.
© 2023 lite-C Forums