Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] 3D rain function

Author
Message
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 9th Jun 2010 12:01 Edited at: 9th Jun 2010 13:27
This is just a quick function I made for a game I'm working on. I know it's fairly simple but could I find an easy to integrate function of this sort for something so simple?

It just makes raindrops fall from the sky:


EDIT: Took minus out from this line;


Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 12th Jun 2010 20:47
Using spheres as particles is quite bad practice. They have a lot of polygons that require a lot of processing. Use plains that face the camera.

"everyone forgets a semi-colon sometimes." - Phaelax
bergice
17
Years of Service
User Offline
Joined: 5th Jun 2007
Location: Oslo,Norway
Posted: 13th Jun 2010 19:46
Looks nice but i think it may be a performance killer when added to a scene.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 14th Jun 2010 11:24
Quote: "Using spheres as particles is quite bad practice. They have a lot of polygons that require a lot of processing. Use plains that face the camera."

I just did a test using the code below and over 30 seconds the planes method was 517 frames slower. Maybe the orientation code slows it down more than the polycount?

I wasn't really expecting it to be faster but the results were:
Framecount1 (using spheres): 24535
Framecount2 (using planes) : 24018

Code:


TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 14th Jun 2010 18:50
What about three plains stuck into each other on every axis? That would be a poly count of 6 for each particle, and you wouldn't have to rotate it to face the camera.

TheComet

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 14th Jun 2010 18:54 Edited at: 14th Jun 2010 19:05
Quote: "What about three plains stuck into each other on every axis? That would be a poly count of 6 for each particle, and you wouldn't have to rotate it to face the camera"

...but I already showed that by using just 1 plane (2 polys) it was slower than using the spheres in my function.

Poly count is making little to no difference here!

EDIT: Just to further test this I used 200 rain objects in my test program and got 25536 frames for spheres and 34623 frames for planes so it does have some impact if you want to use a lot of rain (this would work out as a reduction from 1154fps to 851fps), using 50 raindrops looks fine for my game and is virtually lossless but I haven't tested it for textured planes yet either...

Either way it's a simple system that you could adapt fairly easily for whatever effect you want which is why I made it!

Madscientist
15
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 29th Jun 2010 21:41 Edited at: 29th Jun 2010 21:50
I modified your code for 2 planes each particle and added an extra setup function. The 2 planes are combined into 1 object which the rain is cloned off of.
The parameters are size# and image number to texture the planes (use either tga or png for transparent rain drops)
It returns the object number of the base object which is passed to the draw rain function which clones the base object.


draw_rain takes these parameters
obj start, obj end, base object to clone, size, area x,y,z,ceiling, ground



Test Code:
(attached the png you need to run this code.)


If it hasn't exploded yet, I haven't touched it.

Attachments

Login to view attachments
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 29th Jun 2010 22:48
@Madscientist, nice work! I'm sure that anyone looking for an effect like this has plenty to choose from now!!

Also, I like your version so much I think I'll replace the version I'm using in "Hell for Leather" with yours

Madscientist
15
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 30th Jun 2010 03:53
Thanks no problem.

If it hasn't exploded yet, I haven't touched it.
HowDo
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 30th Jun 2010 13:04
could make a good star field. like it now to study it.

Dark Physics makes any hot drink go cold.
Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 30th Jun 2010 21:30
making a bunch of seperate objects in DBPro leads to a lot of overhead. Try using instance object to speed things up (a LOT).


Is't life, I ask, is't even prudence, to bore thyself and bore thy students?
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 30th Jun 2010 23:53
Quote: "Try using instance object to speed things up (a LOT)."

Great suggestion!! I did and it was about 25% to 30% faster!!!

Login to post a reply

Server time is: 2024-11-21 20:53:54
Your offset time is: 2024-11-21 20:53:54