Jump to content


Photo
- - - - -

Realistic Windy Snow With Motion Blur


  • Please log in to reply
27 replies to this topic

#21 Vile Smile

Vile Smile

    Oh, Outrageous!

  • GMC Member
  • 539 posts
  • Version:GM7

Posted 13 January 2010 - 10:38 PM

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

#22 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14392 posts
  • Version:GM:Studio

Posted 13 January 2010 - 11:32 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:39 PM.

  • 0

#23 petenka

petenka

    The Chosen One

  • New Member
  • 911 posts

Posted 14 January 2010 - 04:55 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 - 04:56 AM.

  • 0

#24 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14392 posts
  • Version:GM:Studio

Posted 14 January 2010 - 06:29 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

#25 jabelar

jabelar

    GMC Member

  • New Member
  • 2980 posts

Posted 14 January 2010 - 06:33 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 - 07:59 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:02 PM.

  • 0

#27 spicydeath82

spicydeath82

    Awesomesauce

  • New Member
  • 138 posts
  • Version:GM8

Posted 18 January 2010 - 08:21 PM

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

#28 petenka

petenka

    The Chosen One

  • New Member
  • 911 posts

Posted 18 January 2010 - 08:28 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:15 AM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users