Jump to content


Photo
- - - - -

Realistic Windy Snow With Motion Blur


  • Please log in to reply
27 replies to this topic

#1 petenka

petenka

    The Chosen One

  • New Member
  • 911 posts

Posted 27 December 2009 - 02:19 AM

  • Title: Realistic Windy Snow with Motion Blur
  • Description: An example of how to make windy snow that looks real by using motion blur and averaged randoms.
  • GM Version: 8
  • Registered: Yes
  • File Type: .gmk and .exe and .scr installer
  • File Size: 686 KB and 2.9 MB and 14.96 MB
  • File Link: .gmk and .exe and .scr installer
Additional Info
The movement is a combination of the following...
  • Gravity
  • Friction
  • Averaged directional changes
  • Double averaged wind changes
The averaged stuff is the most complex part and is the key to how the snowflakes move around realistically.

The motion blur is drawn by simply stretching the snowflake along it's path of travel and then lowering alpha to account for the larger snowflakes.

I apologize for making this gm8 pro only but I provided an exe for those who don't have gm8 pro. Maybe someone who isn't as lazy as me will port this to earlier versions of gm.

And now... The screenshot!
Posted Image

Edited by petenka, 09 November 2011 - 09:57 PM.

  • 1
My Stuff:
Attack of the Jelly - A game about (oh, the horror) strawberry jelly!
Math Based Platformer Engine - The best physics for a platformer, ever.
Realtime Dynamic Fog - For realistic environmental effects.
Windy Snow - The best snow in all of gmc.
My Hate List:
Kubanen, Alex4Red, johnjoe

#2 SolvedSnake

SolvedSnake

    GMC Member

  • New Member
  • 21 posts

Posted 28 December 2009 - 01:10 AM

This looks great!
The blur effect is just pure awesomeness!
When I look at it, it tickles my eyes ;)
Although it uses a bit much horsepower... I don't know if that could be improved a little :huh:

Edited by SolvedSnake, 28 December 2009 - 01:15 AM.

  • 0

#3 petenka

petenka

    The Chosen One

  • New Member
  • 911 posts

Posted 28 December 2009 - 01:13 AM

Although the speed could be improved a little bit ;)

Well, I couldn't use particle effects because they don't have the features needed to make snow like this.
Instead I used an object for each snowflake.
Granted, it's not very fast, but it's easier to make and understand.
Even so, it still runs at a decent 45 fps for me.
Perhaps someone who isn't as lazy as me will make this example use data structures instead of objects...

Edited by petenka, 28 December 2009 - 01:23 AM.

  • 0
My Stuff:
Attack of the Jelly - A game about (oh, the horror) strawberry jelly!
Math Based Platformer Engine - The best physics for a platformer, ever.
Realtime Dynamic Fog - For realistic environmental effects.
Windy Snow - The best snow in all of gmc.
My Hate List:
Kubanen, Alex4Red, johnjoe

#4 dadio

dadio

    Potato King

  • YoYo Games Staff
  • 2740 posts
  • Version:GM:Studio

Posted 28 December 2009 - 01:32 AM

Very nice! ;)
Really lovely realistic softness, movement & blurring.
Excellent example! (& very much in the "Christmas time" spirit) :huh:
Thanks for sharing!

Edited by dadio, 28 December 2009 - 01:34 AM.

  • 0

AczgxAZ.png5aj9t5.jpg
 


#5 Dylijn

Dylijn

    GMC Member

  • New Member
  • 553 posts

Posted 28 December 2009 - 11:45 AM

Dam, cant see it otherwise then the exe cuz I dont have GM8...
  • 0


#6 membrain

membrain

    GMC Member

  • GMC Member
  • 668 posts

Posted 28 December 2009 - 02:34 PM

wow that really does look cool.
good job on this one-
  • 0

#7 coolist

coolist

    The Coolist

  • New Member
  • 913 posts

Posted 28 December 2009 - 04:00 PM

Wow that looks nice.

(And who ever hosted that image also has a great free, fast, image/file hosting service *Cough* ;) )
  • 0

#8 Devilfromhost12

Devilfromhost12

    GMC Member

  • GMC Member
  • 735 posts

Posted 29 December 2009 - 02:15 AM

Very nice it looks great.
  • 0

#9 Newly Discovered

Newly Discovered

    Harmonious Genius

  • GMC Member
  • 2475 posts
  • Version:GM8

Posted 29 December 2009 - 07:51 AM

wow, that's purdy gorgeous!
I would absolutely love to see this in 3D space...you would be a god.
  • 0

poof_sig.png


#10 masterofhisowndomain

masterofhisowndomain

    The Designer

  • GMC Member
  • 3650 posts
  • Version:GM8.1

Posted 29 December 2009 - 08:50 PM

That is really quite exceptional snow, although I still think you should go the extra mile and use those data structures... :whistle:
  • 0

List Of Mods And Add-Ons

(Things you must try, for the games you already have)

 

Insightful links:
Higher Order Fun -- Game Design, Maths.
The Missing Concept -- Career/Hobby?
Neither Career Nor Hobby -- Career/Hobby?
Wario Land 4 Project -- Platformer design.


#11 petenka

petenka

    The Chosen One

  • New Member
  • 911 posts

Posted 29 December 2009 - 09:19 PM

Update

I modified the code which handles random directions so the snow looks much more real when the wind is calm.
I also simplified the averaged random code to make it easier to understand and modify.

@everyone - Thanks for all your support. Keep it up!

@Coolist - Thanks for the great file host. I don't use it to host the actual example though because it's easier to update it on my svn quickly from my computer.

P.S. The nearly empty object called snow is the beginning of my attempt to switch to datastructures.

Edited by petenka, 29 December 2009 - 09:40 PM.

  • 0
My Stuff:
Attack of the Jelly - A game about (oh, the horror) strawberry jelly!
Math Based Platformer Engine - The best physics for a platformer, ever.
Realtime Dynamic Fog - For realistic environmental effects.
Windy Snow - The best snow in all of gmc.
My Hate List:
Kubanen, Alex4Red, johnjoe

#12 Devilfromhost12

Devilfromhost12

    GMC Member

  • GMC Member
  • 735 posts

Posted 31 December 2009 - 12:50 AM

Cool Snow. Nice example.
  • 0

#13 B Factory LLC

B Factory LLC

    We're awesome!!

  • New Member
  • 511 posts

Posted 31 December 2009 - 02:00 AM

Yeah, this is cool. Like the blur. Convert to 3D please, this would be useful in the mountain city of Invasion. (see sig.)
  • 0

If you are neutral in situations of injustice, you have chosen the side of the oppressor. If an elephant has its foot on the tail of a mouse and you say that you are neutral, the mouse will not

appreciate your neutrality.

Posted Image

Anti-Wikileaks Bill introduced in US Congress! (When the giant is mad, it hits hard...)

"So this is how liberty dies. With thunderous applause." - Padme

"The ruling class has the schools and press under its thumb. This enables it to sway the emotions of the masses." - Albert Einstein

Please check out my blog: My link


#14 CrazyTM

CrazyTM

    GMC Member

  • New Member
  • 121 posts

Posted 31 December 2009 - 09:00 AM

Very nice! :whistle:
Really lovely realistic softness, movement & blurring.
Excellent example! (& very much in the "Christmas time" spirit) :)
Thanks for sharing!


yes i agree :D
i really like the effects (blurring , smooth wind..)..it makes it look more realistic.
  • 0
Check out my blog at http://forbidden-in-heaven.tumblr.com/ for GML
(and HTML , C++ , php,..) examples , tutorials , news and more !

#15 Newly Discovered

Newly Discovered

    Harmonious Genius

  • GMC Member
  • 2475 posts
  • Version:GM8

Posted 03 January 2010 - 12:11 AM

I've finally been able to look at the source of this, and it's awesome. Ds_list would make a huge cpu difference, also, I added a star of lines in the center of your snowflake sprite, it added a bit more...snow flake-ness to it.
I really hope to see this in 3D...it would blow my mind.

Good luck!
  • 0

poof_sig.png


#16 petenka

petenka

    The Chosen One

  • New Member
  • 911 posts

Posted 03 January 2010 - 12:48 AM

I've actually been experimenting with this in c++ which is known for being super fast and yet, it barely runs faster than gm.
This evidence has led me to conclude that it's not the object overhead but rather just drawing a thousand alpha blended sprites.
When i moved all the snowflakes offscreen but still active, the fps jumped up enormously.
So, ds_lists won't give much of an improvement.
When I decide to work on a 3d game, I might convert this to 3d, but for now the depth system already provides enough 3dish goodness in 2d.

EDIT: UPDATE
After trying to implement my snow into my comp 5 game I realized it failed when it came to views so after some confusing work with views I finally got everything to work absolutely perfectly with views. The motion blur and depth all work perfectly.
Use the 4 arrow keys to move the view.

Also, if you noticed, each snowflake has a distance. When it is equal to 1 the snowflake moves relative to the player and his surroundings. When it's below 1 the snowflakes are in the foreground moving quickly and if it's greater than 1 they are in the background moving very slowly.
Feel free to utilize this distance variable to give each snowflake a depth, thereby drawing some behind the player and some in front for added realism.

Edited by petenka, 03 January 2010 - 03:40 AM.

  • 0
My Stuff:
Attack of the Jelly - A game about (oh, the horror) strawberry jelly!
Math Based Platformer Engine - The best physics for a platformer, ever.
Realtime Dynamic Fog - For realistic environmental effects.
Windy Snow - The best snow in all of gmc.
My Hate List:
Kubanen, Alex4Red, johnjoe

#17 Schyler

Schyler

    Noskcirderf Derf

  • GMC Member
  • 2680 posts
  • Version:GM:Studio

Posted 13 January 2010 - 06:49 AM

This is very good. Keep up the good work.

Any chance of this working in 3D in the future? Render to a texture...?
  • 0

#18 DZiW

DZiW

    GMC Member

  • GMC Member
  • 978 posts
  • Version:Unknown

Posted 13 January 2010 - 01:30 PM

IMO using too many objects (for every flake) is rather lame approach.
How about sprite clustering and/or elements grouping so that one object/ sprite could refer to some 5 or 10 flakes?

Anyway looks pretty nice)
  • 0

YOU CREATE: WHERE LiFE MAY FAiL, DEAћ SHALL NOT!


#19 Topaze22

Topaze22

    GMC Member

  • GMC Member
  • 58 posts

Posted 13 January 2010 - 04:13 PM

With only 100 snows elements, it's stay very nice and not too heavy.
I will probably use it ^^ (and put you in the credit)
  • 0
English,spanish and French
Posted Image

#20 petenka

petenka

    The Chosen One

  • New Member
  • 911 posts

Posted 13 January 2010 - 07:57 PM

This is very good. Keep up the good work.

Any chance of this working in 3D in the future? Render to a texture...?

3D would be very different actually. Perspective would already handle depth for me, motion blur would involve some crazy 3d perspective calculations and so would wrapping the snowy region into the viewable area. Nonetheless, it can be done, you just need some good knowledge of perspective transformations. Yourself's 3d to 2d conversion scripts would come in handy here.
Rendering it to a texture would make it impossible to create motion blur using the technique that I use. And GM doesn't have shaders, so textures simply wouldn't work.

IMO using too many objects (for every flake) is rather lame approach.
How about sprite clustering and/or elements grouping so that one object/ sprite could refer to some 5 or 10 flakes?

Anyway looks pretty nice)


Just add a draw event with a bunch of draw_sprite_ext with different offsets so each snowflake draws itself multiple times. You can even randomize the offsets at snowflake creation to make it more random. This would give you a small speed boost. You can also try to make it use arrays or ds_lists instead of objects if you really want to optimize it.
  • 0
My Stuff:
Attack of the Jelly - A game about (oh, the horror) strawberry jelly!
Math Based Platformer Engine - The best physics for a platformer, ever.
Realtime Dynamic Fog - For realistic environmental effects.
Windy Snow - The best snow in all of gmc.
My Hate List:
Kubanen, Alex4Red, johnjoe

#21 Vile Smile

Vile Smile

    Oh, Outrageous!

  • GMC Member
  • 553 posts
  • Version:GM7

Posted 13 January 2010 - 10:52 PM

Really nice! I love the effect! I could see this being used in an FPS. :)
  • 0

banner-1.png


#22 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 13 January 2010 - 11:46 PM

from 30 fps to 200 with these changes
Information about object: snowflake

Sprite: spr_snowflake
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent: <no parent>
Mask: <same as sprite>

Create Event:
execute code:

alarm[0] = random(10)+1
//A bunch of variables that have to do with random directions
dir_speed = 0;
dir = 0;
dirr = 0.1;
dirs = 0.05;
dirp = 32;

size = 0.02;
distance = sqrt(random(0.95)+0.05);
image_xscale = size/distance;
image_yscale = size/distance;
grav = 0.1;
vspeed = 0.1;
stretch = 1/256/size;
vx = view_xview;
vy = view_yview;


ospeed = speed;
odirection = direction;


Alarm Event for alarm 0:
execute code:

alarm[0] = room_speed/8;
dir_speed = (1-dirr)*dir_speed + dirr*(random(dirp)-dirp/2);//Directional Randomness
dir += dir_speed;
motion_add(dir,dirs);

hspeed += windspeed;//Wind
vspeed += grav;//Gravity
speed = speed * 0.95;//Friction

ospeed = speed;
odirection = direction;

xv = (vx-view_xview)/distance-vx+view_xview;
yv = (vy-view_yview)/distance-vy+view_yview;

x += xv;
y += yv;

image_angle = point_direction(0,0,hspeed+xv*distance,vspeed+yv*distance);
image_xscale = image_yscale*point_distance(0,0,hspeed+xv*distance,vspeed+yv*distance)*stretch + image_yscale;
image_alpha = image_yscale/image_xscale;

speed = speed/distance;

vx = view_xview;
vy = view_yview;

speed = ospeed;
direction = odirection;


Other Event: Outside Room:
execute code:

speed = ospeed;
direction = odirection;
x = ((((x - view_xview) mod view_wview) + view_wview) mod view_wview) + view_xview;
y = ((((y - view_yview) mod view_hview) + view_hview) mod view_hview) + view_yview;

[edit]
I did not do much tweaking. but realize that the alarm method is pretty good to effect changes to the particles. Especially if there is a lot of code involved.

And the outside room to wrap instead of the end step. though it breaks the scrolling...

Edited by icuurd12b42, 13 January 2010 - 11:53 PM.

  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#23 petenka

petenka

    The Chosen One

  • New Member
  • 911 posts

Posted 14 January 2010 - 05:09 AM

Interesting optimization there Icuurd.
I can see that the wrapping code is better off in the outside room event (but as you said it breaks view scrolling so it's not a perfect solution) however the rest of the code kills the whole depth functionality. You might as well take out all the depth code completely if you're going to mutilate it like that.
I can see where you're going with the alarm system, you just didn't do it correctly.
Done correctly however, the snow will remain fully functional with only a slight loss of quality.

Edited by petenka, 14 January 2010 - 05:10 AM.

  • 0
My Stuff:
Attack of the Jelly - A game about (oh, the horror) strawberry jelly!
Math Based Platformer Engine - The best physics for a platformer, ever.
Realtime Dynamic Fog - For realistic environmental effects.
Windy Snow - The best snow in all of gmc.
My Hate List:
Kubanen, Alex4Red, johnjoe

#24 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 14 January 2010 - 06:43 AM

Interesting optimization there Icuurd.
I can see that the wrapping code is better off in the outside room event (but as you said it breaks view scrolling so it's not a perfect solution) however the rest of the code kills the whole depth functionality. You might as well take out all the depth code completely if you're going to mutilate it like that.
I can see where you're going with the alarm system, you just didn't do it correctly.
Done correctly however, the snow will remain fully functional with only a slight loss of quality.


>>I did not do much tweaking.

You are in a better position to tweak it

It's a very good snow example... It would be nice if you had it done in a 3d type FPS setup... As you draw the snow in 2d with perspective, right before the 2d hud, the effect is very compatible. It would be a good thing to show.

In GM8, you can use the suposedly now working outside view event, even in 3d, because view0 is usually used for 3d (to set the port while having a large room/mao). Since it's always at 0,0, the event would still work for the 2d snow. When doing particles with instances, you want GM to handle stuff with as little GML (every step) as possible
  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#25 jabelar

jabelar

    GMC Member

  • GMC Member
  • 3003 posts

Posted 14 January 2010 - 06:47 PM

Regarding view scrolling, another possibility is to fake it. While I appreciate your attempt to keep the integrity of every single flake, I think that with view scrolling you could just simply provide some sideways blur and then just continue where you were without actually moving all the flakes with the view. I don't think human eye would generally notice the difference. In other words, I don't think you need perfect view scrolling for a bunch of blurry snowflakes, so maybe that can be useful when dealing with other optimizations (like above where you're worried about iccurd's suggestion breaking the view scrolling).

When I do rain effects I found you can go even further -- don't really have to keep the integrity of every drop. If some drops dissapper/jump, the human eye doesn't really notice. Obviously with snow moving slower it is more important to have particle integrity, but you still might be able to get away with some imperfections. Again that might help in some optimization.
  • 0

#26 petenka

petenka

    The Chosen One

  • New Member
  • 911 posts

Posted 18 January 2010 - 08:13 PM

Well, after working over what icuurd suggested I have created an optimized screensaver version of my snow.
Just download and run the installer,
open your screensaver dialog,
and select Snow as your new screensaver.
It runs at 60 fps with 2000 snowflakes :D

Download link:
http://www.upurload....7951429681c.exe

EDIT: Modified the screensaver to support resolutions other than 1028x1024.

Edited by petenka, 27 January 2010 - 04:16 PM.

  • 0
My Stuff:
Attack of the Jelly - A game about (oh, the horror) strawberry jelly!
Math Based Platformer Engine - The best physics for a platformer, ever.
Realtime Dynamic Fog - For realistic environmental effects.
Windy Snow - The best snow in all of gmc.
My Hate List:
Kubanen, Alex4Red, johnjoe

#27 spicydeath82

spicydeath82

    Awesomesauce

  • New Member
  • 138 posts
  • Version:GM8

Posted 18 January 2010 - 08:35 PM

very lovely, but i only got around 9 FPS, which is a bit un-acceptable for use in a game...
  • 0
Life is incapable of of springing from nothing. Science has proven that. So if life here didn't spring up outta the primordial muck then who's responsible? Life has to come from life.

Posted Image

#28 petenka

petenka

    The Chosen One

  • New Member
  • 911 posts

Posted 18 January 2010 - 08:42 PM

very lovely, but i only got around 9 FPS, which is a bit un-acceptable for use in a game...

Mind telling me what the specs are on that piece of scrap metal you call a computer?
Running it on a 2.5 GHz computer with an integrated graphics card nets me 60 fps for the screensaver and 45 fps for the example.

Edited by petenka, 19 January 2010 - 01:29 AM.

  • 0
My Stuff:
Attack of the Jelly - A game about (oh, the horror) strawberry jelly!
Math Based Platformer Engine - The best physics for a platformer, ever.
Realtime Dynamic Fog - For realistic environmental effects.
Windy Snow - The best snow in all of gmc.
My Hate List:
Kubanen, Alex4Red, johnjoe