Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411525 Posts in 69377 Topics- by 58431 Members - Latest Member: Bohdan_Zoshchenko

April 28, 2024, 04:37:43 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsCommunityTownhallForum IssuesArchived subforums (read only)TutorialsSimple Motion blur (Well motion trail actually)
Pages: [1]
Print
Author Topic: Simple Motion blur (Well motion trail actually)  (Read 12798 times)
Geeze
Level 5
*****


Totally.


View Profile
« on: September 01, 2011, 08:48:26 AM »

I was a bit bored so I made my 1st tutorial 4ever!

HOW TO MAKE A SIMPLE MOTION BLUR EFFECT IN GAME MAKER

Bad example:
I used an old abandoned project of mine to test this thing  Smiley


PART 1: How it is done

STEP 1: Add these to your project: object oBlur and script draw_blur (You can rename them ofc)

Necessary information about object oBlur

Sprite: <no sprite> (Of course as it is controller object) Or if you want i recongizable in level editor then why not. Just turn visibility off. Oh wait, drawing event makes it invisible.

Depth: 1000 (To make the blur stay under most objects)

Persistent: false (Or true if you don't want to initialize it in every room. It's your choice)

Create Event:

Code:
screenWidth = view_wview[view_current]
screenHeight = view_hview[view_current]
global.mblur = surface_create(screenWidth,screenHeight)
temp = surface_create(screenWidth,screenHeight)

surface_set_target(global.mblur)
draw_clear_alpha(c_white,0) //Actually any color would do
surface_set_target(temp)
draw_clear_alpha(c_white,0)
surface_reset_target()

camLastX = view_xview[view_current]
camLastY = view_yview[view_current]


 Step Event:

Code:
difX = camLastX-view_xview[0]
difY = camLastY-view_yview[0]

//Copyroutine
surface_set_target(temp) //This part moves the trail in camera
draw_surface_ext(global.mblur,difX,difY,1,1,0,c_white,0.94)
surface_reset_target()
surface_copy(global.mblur,0,0,temp)

surface_set_target(temp)//We clear the temp-surface
draw_clear_alpha(c_white,0)
surface_reset_target()
//End of copyroutine


camLastY = view_yview[0]
camLastX = view_xview[0]


Draw Event:

Code:
draw_surface_ext(global.mblur,view_xview[0],view_yview[0],1,1,0,c_white,0.8)

Code:
Script draw_blur:

surface_set_target(global.mblur)
draw_sprite_ext(sprite_index,image_index,x-view_xview[0],y-view_yview[0],image_xscale,image_yscale,image_angle,image_blend,image_alpha)
surface_reset_target()

STEP 2:
Remember to modify surface sizes appropriate to your game
Call draw_blur in endstep event for every object you want to have motion blur
Tweak anything you have to. Re-factor if needed.

That's it

Coming Part 2: Explanation and variations?

Code:
Changelog:
1.9.2011
 - Created 1st part
2.9.2011
 - Corrected some stuff and made it screensize independent.
 - Added draw_clear_alpha's to code. Thanks Desert dog
 
« Last Edit: September 01, 2011, 09:27:04 PM by Geeze » Logged

Geeze
Level 5
*****


Totally.


View Profile
« Reply #1 on: September 01, 2011, 08:51:32 AM »

Part 2: More related techniques
Solid-color trail (Pics will come later)
HOW IT'S DONE
This is very simple actually.
All you have to do is surround draw_blur() like this:
Code:
d3d_set_fog(1,c_white,0,0)
draw_blur()
d3d_set_fog(0,c_white,0,0)
Just replace c_white with your color of choice.

EXPLANATION
If you already know what d3d_set_fog() does skip this.
What can you do with fog in 2D?
d3d_set_fog() is a good technique to display a sprite in a solid color or if you want to fade it in to single color. Not sure. I'll check this ASAP (Not to be confused with image_blend which just colorizes sprite)

Most 3d functions work in 2D but might have unexpected result, so experimenting might yield very interesting results.

What is it meant for?

Quote from: Game Maker Manual
Fog can be used in 3D games to make objects in the distance look blurred or even disappear. This helps in creating atmosphere and it makes it possible to not draw objects that are far away. To enable or disable fog use the following function:

    d3d_set_fog(enable,color,start,end) Enables or disables the use of fog. color indicates the fog color. start indicates the distance at which fog must start. end indicates the distance at which fog is maximal and nothing can be seen anymore.

To better understand what is happening, there are actually two types of fog, table based fog and vertex based fog. The first type calculates fog values on a pixel basis. The second type calculates the fog value for each vertex and then interpolates these. The first type is better but not always supported. Game Maker tries to use table based fog when supported and otherwise uses vertex based fog (unless no fog is supported). Note that certain graphics card indicate that they can handle table based fog but offer the user the possibility to switch this off in the advanced display settings. In this case the result might be a black screen!

Solid color trail variant: The RAINBOW! COMING SOON!
« Last Edit: September 03, 2011, 06:16:40 AM by Geeze » Logged

Desert Dog
Level 4
****



View Profile
« Reply #2 on: September 01, 2011, 04:02:38 PM »

Don't forget to call draw_clear(), or draw_clear_alpha(), after creating those surfaces.

Reference (read paul23, and xot's post)
Logged

Geeze
Level 5
*****


Totally.


View Profile
« Reply #3 on: September 01, 2011, 07:59:38 PM »

Yeah thanks telling about that. I'll fix that and few other inconsistencys ASAP.
Logged

sedna16
Level 0
**


View Profile
« Reply #4 on: September 03, 2011, 01:12:52 AM »

great tut!!

I could use this as a booster for my vertical space shooter.  Smiley
Logged
Geeze
Level 5
*****


Totally.


View Profile
« Reply #5 on: September 03, 2011, 05:42:06 AM »

Glad it's helpful. If you want to know how to make some specific trail effects (Like solid color, rainbows!,Better trails for super fast things etc.) Just make a post here.
Logged

kamac
Level 10
*****


Notoriously edits his posts


View Profile
« Reply #6 on: September 03, 2011, 06:30:00 AM »

Nice  Smiley

This is pretty cool effect. I wonder if someone is actually making good games in Game Maker without coding?
Logged

Geeze
Level 5
*****


Totally.


View Profile
« Reply #7 on: September 03, 2011, 07:04:02 AM »

Nice  Smiley

This is pretty cool effect. I wonder if someone is actually making good games in Game Maker without coding?
Not.  My Word!

"But why use GM if you have to code to make not bad games?"
BECAUSE GM CAN DO ANYTHING! It's Magic!
Logged

ink.inc
Guest
« Reply #8 on: September 03, 2011, 01:03:40 PM »

Why use GML instead of the Drag and Drop functions? Because GML is easy as shit to learn. 10 year olds can do it. And also because Drag n Drop is a complete headache to sort through/edit.
Logged
Desert Dog
Level 4
****



View Profile
« Reply #9 on: September 03, 2011, 01:35:06 PM »

Nice  Smiley

This is pretty cool effect. I wonder if someone is actually making good games in Game Maker without coding?

Generally for a 'full game' your bound to run into some place where you need code. So some 'D&D' users, even when they make big games still use codes/scripts in places.

I heard The Power was made only with D&D, and that's pretty popular/gets nice reviews. But yeah, generally speaking one should get off D&D ASAP, and onto GML.
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic