[A5] Motion Blur Effect
tolgagerekci

I want to create motion blur effect with Allegro5. I simply created a blur bitmap for this effect.

My steps:

1-) Draw backbuffer to blur using
al_draw_tinted_bitmap(backbuffer, al_map_rgba_f(1,1,1,0.95), 0, 0, 0);

2-) Clear backbuffer using

3-) Draw blur to backbuffer using

4-) Draw sprites to backbuffer

5-) Flip display

But when my blurred pixels transparency goes 255, they become white. And i get something like this pictures.(fitsr pic is from starting of game. second picture is when im moving ... )
http://www.allegro.cc/files/attachment/606036
http://www.allegro.cc/files/attachment/606037

Trent Gamblin

1) clear your buffer to black at the start of the level/game
2) draw translucent black rectangle to the buffer
3) draw your sprites/scene to the buffer
4) draw the buffer to the screen backbuffer
5) repeat from step 2

Just make sure you draw an "opaque-enough" black rectangle to suit your desired trail length.

Not sure a good way to get motion blur on some parts and not on others.

Todd Cope

I create a cheap motion blur effect for certain sprites in one of my games by taking a few "snapshots" of the sprite going back into the past and drawing them with a lower opacity the older they are. The "snapshot" consists of a pointer to the bitmap to draw, positioning data, and a timer used to calculate the opacity.

tolgagerekci

I think you don't understand me. My code is:

#SelectExpand
1//-----INIT PART--------------- 2 3ALLEGRO_BITMAP *tri = al_create_bitmap(al_get_bitmap_width(al_get_backbuffer(display)),al_get_bitmap_height(al_get_backbuffer(display))); 4 5ALLEGRO_BITMAP *blur = al_create_bitmap(al_get_bitmap_width(al_get_backbuffer(display)),al_get_bitmap_height(al_get_backbuffer(display))); 6 7al_set_target_bitmap(tri); 8 9al_clear_to_color(al_map_rgb(0,0,0)); 10 11al_set_target_bitmap(blur); 12 13al_clear_to_color(al_map_rgb(0,0,0)); 14 15al_set_target_bitmap(al_get_backbuffer(display)); 16 17//-----DRAWING PART------------ 18 19//--------------------------------------- 20al_set_target_bitmap(blur); 21 22al_draw_tinted_bitmap(tri,al_map_rgba_f(1,1,1,0.95), 0, 0, 0); 23 24//---------------------------------------- 25 26al_set_target_bitmap(tri); 27 28al_clear_to_color(al_map_rgba(0,0,0,255)); 29 30al_draw_bitmap(blur,0,0,0); 31 32cam.StartCamera(); 33 34int j = 0; 35for(j = 0; j < bullets.size(); j++) 36{ 37 bullets[j]->Draw(); 38} 39for(j = 0; j < enemybullets.size(); j++) 40{ 41 enemybullets[j]->Draw(); 42} 43spaceship.Draw(); 44 45al_set_target_bitmap( al_get_backbuffer(display) ); 46 47al_clear_to_color(al_map_rgb(0,0,0)); 48 49al_draw_bitmap(tri,0,0,0); 50 51gamemenu->Draw(); 52 53gameBar->Draw(); 54 55mouse->Draw(); 56 57al_flip_display();

How can i draw " translucent black rectangle" with Allegro 5?

Todd Cope

al_draw_filled_rectangle(left, top, right, bottom, al_map_rgba_f(0.0, 0.0, 0.0, 0.5));

Replace the 0.5 with whatever value suits your needs. A lower value will produce more blurring. This works with fine with the default blender setting.

tolgagerekci

Thanks thanks thanks million time thanks :D I really appreciate it.

Hyena_

can you upload the screenshot of your result? I'd like to see motion blur in action using A5.

tolgagerekci

Results:
{"name":"606044","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/6\/56f38fab2ac52b5560e00f2700482d01.png","w":1297,"h":1038,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/6\/56f38fab2ac52b5560e00f2700482d01"}606044
{"name":"606045","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/9\/59b88b15447e45bca01c2728a5b5b3b3.png","w":1293,"h":997,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/9\/59b88b15447e45bca01c2728a5b5b3b3"}606045

Alpha values:

First 80
Second 50

Thread #610240. Printed from Allegro.cc