GLBasic forum

Codesnippets => 2D-snippets => Topic started by: Hemlos on 2009-Sep-27

Title: SpriteZ - 2d particle engine (Updated: June 15,2012)
Post by: Hemlos on 2009-Sep-27
An API for a 2d particle engine.

SpriteZ.gbas

Download, includes 4 working sample projects, and a help file:
Arrowmode
Zonemap
Gravity
Animated

Update:
A few options have been improved for easier to understand useage.
Also a new option is in the api: (friction)


Feel free to ask questions here.
This project is 3 years+ in the making.
This project is open sourced, and free for anyone to use and publish in thier software.

PS. The only thing i kindly ask in return is for programmers to show me what theyve done with the engine, so please, let all of us see what you published(ill buy a user copy of anything made using this engine)!!!

PPS. 3d...well, its going to take a huge effort to complete, im going to try this year.
Link to download below:

[attachment deleted by admin]
Title: Re: SpriteZ - a 2d particle system
Post by: mgarnett on 2009-Sep-28
Hi Hemlos,

I'm a new user in these forums and I have recently been following the SpriteZ thread.  By posting this source, are you still going to continue development of the system?

I haven't used the system yet, I'm still working my way through the "built-in" features but I was eagerly anticipating the 2D and 3D versions of your library.

Cheers

Mark
Title: Re: SpriteZ - a 2d particle system
Post by: Schranz0r on 2009-Sep-28
Nice work, Hemlos!
Title: Re: SpriteZ - a 2d particle system
Post by: codegit on 2009-Sep-28
Hemlos

Thank you, if I use it in my game I will mention you. I am still prepared to pay for a commercial version as I do not think your work should go unrewarded.  :good:
Title: Re: SpriteZ - a 2d particle system
Post by: 9940 on 2009-Sep-28
Thanks !
The 3d version will be open too ?
Title: Re: SpriteZ - a 2d particle system
Post by: Hemlos on 2009-Sep-28
@Schranz0r:
Thanks friend, im glad you pushed me into making this library.
Its alot more versatile than we originally discussed.

@mgarnett:
Yes, i will maintain this 2d library, as GLBasic evolves, so will this api.

@9940:
No, it wont be open source.

@all tweakers:
I know people are playing with it alot now, and many people are going to attempt "tweaking" and what-not.
I have spent alot of time merging all the physics, and some thing can be speeded up ABSOLUTELY, but it will reduce performance(if not destroy completely) and quality in other areas!
If you find things that can be improved, let me know, ill research the changes to see if it is going to be compatible with the whole library.
At the cost of performance or quality, i will not be making major changes.
If i notice things can be improved, i will update this library accordingly, as i will use this library to make software for my own purposes.
To be honest with everyone, i dont recommend tweaking this library at all, as you may induce memory leaks.
Also, making an addition or changes can have profound and undesirable affects throughout the library.
The only things that might need to be altered, are the things that may hinder platforms other than win32.

Title: Re: SpriteZ - a 2d particle system
Post by: Hemlos on 2009-Sep-28
I added a sample to SpriteZ.rar, it demonstrates how to setup the auto-animation ability.

Note: This animation mode does one full pass through the animation, during the life of a particle.
It doesnt matter how many frames your animation has, this mode splits up the lifetime into the number of frames the animation has.
So in this sample, i used 2 seconds lifetime, and it rolls through 12 frames during this time.
As you will notice the frame size set is 32,32.
There are 12 frames in the animation image, size of the image is 128x128.
You can make the animation larger, such as, 256x256, just resize it, and copy over more frames into the empty area. As long as you leave the frame size 32x32, you wont need to change any code...only the image.
Title: Re: SpriteZ - a 2d particle system
Post by: WPShadow on 2009-Sep-28
It's really great!!!

If 3D is in too, I'll use it for LR, if it's allowed
Title: Re: SpriteZ - a 2d particle system
Post by: Hemlos on 2009-Sep-28
@WPShadow:
You may use it in LR if you like, however, SpriteZ is only 2d atm.
Title: Re: SpriteZ - a 2d particle system
Post by: WPShadow on 2009-Sep-29
No problem, there are many parts ingame, where I can use it!!!  :good:
Title: Re: SpriteZ - a 2d particle system
Post by: kaotiklabs on 2009-Sep-29
Tested on Iphone 3.1 SDK and working  :good:
Just remember to check the case sensitive paths.

Pretty good job mate!
Title: Re: SpriteZ - a 2d particle system
Post by: Hemlos on 2009-Sep-29
Tested on Iphone 3.1 SDK and working  :good:
Just remember to check the case sensitive paths.

Pretty good job mate!

Thanks for the compliment :)

Amazing! I was worried it wouldnt work with the math in an iphone.
Thats really good news.

@E:
If anyone has an idea, and has a hard time producing it with SpriteZ, tell me what it is.
I can create a set for you very quickly, without the need of wasting alot of time with trial and error.
I can help you(anyone) create a set of parameters, to produce the output(design/look/functionality) you desire.
Title: Re: SpriteZ - a 2d particle system
Post by: Hemlos on 2009-Oct-01
I Updated the download.

SpriteZ(2d) Fixes made:
- screen dimensions memory, allocated internally now.
- time limits removed, redundant code
Title: Re: SpriteZ - a 2d particle system
Post by: Hemlos on 2009-Oct-27
Tip:
Call the GLBasic MOUSE functions near the end of the main loop, after the last emitter_ call.

This will prevent any slow mouse reactions, due to SpriteZ being a high frequency routine.
Title: Re: SpriteZ - a 2d particle system
Post by: spoke on 2010-Jan-03
nice job Hemlos   :good:
Title: Re: SpriteZ - a 2d particle system
Post by: Hemlos on 2010-Jan-03
Thanks, i appreciate the thumbs up.
Have fun with it!  :good:
Title: Re: SpriteZ - a 2d particle system
Post by: dman10001 on 2010-Apr-07
Hi, I would like to know how I can make explosions using SpriteZ.

what are the values and what do I use?

Title: Re: SpriteZ - a 2d particle system
Post by: Hemlos on 2010-Apr-08
Put this in your header:

Code: (HEADER) [Select]

numparts = 100 //partcle count max
lifetime= 1500 //1.5 seconds absolute lifetime per particle
 SpriteZ = Emitter_Create_System( "media/Fire2.PNG" , numparts ,lifetime, FALSE)
  Emitter_ColorAndAlpha( SpriteZ , RGB(255,128,0 ) , 1.0 )
  Emitter_RadiusScalars( SpriteZ , 1.0 , 0.1 )
  Emitter_Rotation_Velo( SpriteZ, 12 ) //twist 12 degrees per frame
  Emitter_Nozzle_Spread( SpriteZ, 360 )
That will make your sprite emitter: Shrink, rotate, Spread 360, colored yellow, and bright alpha.
Dont forget to put a sprite for the emitter in the app_directory/media/Fire2.PNG/   
Anything 32x32 size would be good.



Now you need to have some kind of velocity in the loop, and you need to show it each loop:

Code: (MAIN LOOP) [Select]
MOUSESTATE MX,MY,MB1,MB2
Velocity=0.05 // 0.1=low velocity 1.0=very strong velocity
Emitter_Velocities_XY( SpriteZ , Velocity, Velocity )
Emitter_Pause_Emitter( SpriteZ , 1-MB1 )
Emitter_Show_Emission( SpriteZ , MX, MY )

The left mouse button should trigger an explosion, it will create particle as long as you are holding it.

There are many options, and really the only way to make it exactly how you need it, you must do some experimenting.
If you need the particles to do something else specific, just ask.


PS. You need to create your own timer, to explode for a specific amount of time. The lifetime timer for Spritez is only for the lifetime of the particles which are rendered....not for how long the emitter is running for, for this you need to make your own custom timer...use the pause feature to turn it on an off for best looking results.

PPS. increase program performance with a second custom timer, using a timer with the above code: the timer should stop calling the Emitter_Show_Emission, 1.5 seconds(to match particle 'lifetime' set in header)  after releasing the mouse button. The just an example, i didnt provide this in the API. As you are the programmer, you must control exactly when and where the emitter is used of course.


Here is a screenshot of the above emitter:


[attachment deleted by admin]
Title: Re: SpriteZ - a 2d particle system
Post by: dman10001 on 2010-Apr-08
Hi, Thanks very much. It worked perfect. Just one thing the game slows down when its called
I tried to adjust a timer, but the particles don't last long enough.

Title: Re: SpriteZ - a 2d particle system
Post by: Hemlos on 2010-Apr-09
1. what size image are you using? (i recommend 32x32 or smaller, and triangle mode will increase perf)
2. how many particles? (i recommend very small amount <100 )

Tip 1: You must make sure you initialize ALL emitters one time! Init in the header only, before all loops.
So in other words, for each style of explosion(Bombs, Smoke, Fire, etc), you must initialize them all, before your main rendering loops.

Tip 2: Using more than 1 Emitter_Show_Emission, per render loop will significantly reduce performance, if you need  multiple explosions, just change the explosion position...the particles previously emitted will continue to live thier lifetime on the path they were already on.
Title: Re: SpriteZ - a 2d particle system
Post by: MrTAToad on 2012-Apr-10
Wondering if it would be possible to update this to use extended types and what not...
Title: Re: SpriteZ - a 2d particle system
Post by: Hemlos on 2012-Jun-14
Good question toad.  :x
To be honest, i really dont know where to begin with a conversion.
If i had started in types in the first place...that would have been so much easier.

If anyone feels like optimizing the code, be my guest.. if it works the same way i intended, ill update the download with it.   :whistle:
As i understand it, there is plenty of room for improvement of the original code, without trying to convert dimensions to type.

Edit: i will also accredit you in the header for your work on optimizations.

Has anyone published anything using this api?
As of yet(as far as i know), no programs exist using it yet.
It has been a long time since i began the project, im so curious to see the code in action.
I would LOVE to see SpriteZ in action!
Title: Re: SpriteZ - 2d particle engine (Updated: June 15,2012)
Post by: Hemlos on 2012-Jun-15
New stuff in the api...download is in the top message.
Many options are updated for easier to use.
A new option is in, FRICTION
And 4 working samples....this has been lacking i know.

Im going to continue to make a few more samples(theyll be separate from the main download, and in thier own messages in this thread(below)).
Title: Re: SpriteZ - 2d particle engine (Updated: June 15,2012)
Post by: mentalthink on 2012-Jun-15
 :nw: :nw: :nw:

Hemlos this new API it´s awesome... perhaps I include in my game whit your permission, becuase the effects are awesoming, the gravity effect it´s like water... I don´t know if in Mobile devices de Fps drops down a lot, but this code it´s absolutetly very advacen, at least for me... this maths are very interesting...

Thanks a lot, and a PERFECT JOB!!!
Title: Re: SpriteZ - 2d particle engine (Updated: June 15,2012)
Post by: Hemlos on 2012-Jun-15
The math...is a monster.
Of course you may use the API.
Let me know when you finish your program, i would love to see it.
Title: Re: SpriteZ - 2d particle engine (Updated: June 15,2012)
Post by: kaotiklabs on 2012-Jun-15
great news :)
Title: Re: SpriteZ - 2d particle engine (Updated: June 15,2012)
Post by: Hemlos on 2012-Jun-17
Demo for Friction here..
No source, executable only...too many changes to engine, must wait.
Basically what i did was increase emitter_friction() in the sample_gravity.gbap source...and remove emitter_gravity().


[attachment deleted by admin]
Title: Re: SpriteZ - 2d particle engine (Updated: June 15,2012)
Post by: Hemlos on 2012-Jun-18
What do you guys think about this..

optional function to limit the distance a particle goes, as opposed to using a lifetime?
Title: Re: SpriteZ - 2d particle engine (Updated: June 15,2012)
Post by: erico on 2012-Jun-18
To me, the idea means an extended controller to it, to the point it could do a lot more then the original purpose! :good:
Title: Re: SpriteZ - 2d particle engine (Updated: June 15,2012)
Post by: Hemlos on 2012-Jun-20
Something is brewing in SpriteZ land.
I am working on an experimental project, PointsGL, PGL sound ok?
Operation inject SpriteZ with steroids... multiply speed by 10.

Preliminary 3d rendering test:
60ms fixed particle movement rate
150,000 particles
screen resolution: 1280x720

On my junky video card...60fps!


Note: this is not the same way spritez renders...it is 3d.
Give this bin a whirl, test this bin.
Let me know the fps you get, and does it looks good or not, please.
http://www.glbasic.com/forum/index.php?action=dlattach;topic=3550.0;attach=5088 (http://www.glbasic.com/forum/index.php?action=dlattach;topic=3550.0;attach=5088)



[attachment deleted by admin]
Title: Re: SpriteZ - 2d particle engine (Updated: June 15,2012)
Post by: Slim on 2012-Jun-20
I am getting 63 fps.
It looks promising.

(using on board Intel graphics)
Title: Re: SpriteZ - 2d particle engine (Updated: June 15,2012)
Post by: erico on 2012-Jun-20
I get 60fps. It all looks as great as my gfx board can do (gtx460, have all options to the max overriding all programs kind of setting).
Title: Re: SpriteZ - 2d particle engine (Updated: June 15,2012)
Post by: Hemlos on 2012-Jun-20
great, good results.

No promise this will be implemented...im not 100% certain this is going to be a good solution, i have much testing to do.
Title: Re: SpriteZ - 2d particle engine (Updated: June 15,2012)
Post by: kanonet on 2012-Jun-20
Give us Code! Even if you do not implement it, it is interesting.
About 61 FPS here, running on Intel graphic.
Title: Re: SpriteZ - 2d particle engine (Updated: June 15,2012)
Post by: Hemlos on 2012-Jun-20
With the fixed lighting system?
Title: Re: SpriteZ - 2d particle engine (Updated: June 15,2012)
Post by: kanonet on 2012-Jun-20
Did you add it to your sample? Hmm i dont want to publish it atm can you provide your code without it (and i did some changes to it, after i gave you the code)? Or just give it to me only. :P
Btw IRC ic you want.
Title: Re: SpriteZ - 2d particle engine (Updated: June 15,2012)
Post by: Hemlos on 2012-Jun-21
your arrays are probably faster, ill test those too
Title: Re: SpriteZ - 2d particle engine (Updated: June 15,2012)
Post by: Crivens on 2012-Jun-21
228fps. Obviously it's limited to the vsync to be getting 60fps all the time so I turned off my internal intel graphics (use NVidia instead) and turned off the vsync for your program. Took a couple of seconds to ramp up but was getting an average of about 223fps with a max of 228fps. Nice.

Cheers
Title: Re: SpriteZ - 2d particle engine (Updated: June 15,2012)
Post by: Hemlos on 2012-Jun-23
New Experiment/Demo here.
The system is coming along great, and i have a feeling this one is going to end up being 10 times better than SpriteZ, performance wise. So far its not sprites, but it is pretty looking particles i created with opengl.
This test is really going to show how powerful it is, and how powerful itll be in the future after i add the optional phyiscs.


Quote
//Experimental Test:
//
//Executable: Windows only.
//Resolution: 1280x720 fullscreen.rar or window.rar
//Particle Count: 40,000
//
//this test uses a background,.png, some particles, very limited phsyics, AND very low level Ai TO move them all around independantly.
//this is just a test, but it looked so cool i had TO show everyone!

[attachment deleted by admin]
Title: Re: SpriteZ - 2d particle engine (Updated: June 15,2012)
Post by: mentalthink on 2012-Jun-23
Nice!!! , I have whit the las experiment in normal mode Smooth and not :

40.000 particles 60 FPS Constant

whit edge in "particle"

about 53 but usually between 55 58 FPS

Very nice Effect, and I don´t look too much, too much small and a lot of particles, they have collision between them...
Title: Re: SpriteZ - 2d particle engine (Updated: June 15,2012)
Post by: mentalthink on 2012-Jun-23
Whit the "attraction tool" I love it... I have all time 60FPS, excepts only when start the application, but only for 1 or 1 + 1/2 second, after all time are 60 FPS... :nw: :nw: :nw:
Title: Re: SpriteZ - 2d particle engine (Updated: June 15,2012)
Post by: Hemlos on 2012-Jun-24
new demo, just a demo, nothing more...just something i did while experimenting with 10k particles


ps dont stare at it too long, you might get sick

[attachment deleted by admin]
Title: Re: SpriteZ - 2d particle engine (Updated: June 15,2012)
Post by: Hemlos on 2012-Jul-07
test of dynamic particles, sand piling up

[attachment deleted by admin]
Title: Re: SpriteZ - 2d particle engine (Updated: June 15,2012)
Post by: erico on 2012-Jul-07
nice sand, the test before this didn´t work, loading bar and blank forever.
Title: Re: SpriteZ - 2d particle engine (Updated: June 15,2012)
Post by: Hemlos on 2012-Jul-07
nice sand, the test before this didn´t work, loading bar and blank forever.

The other that didn't work for u is not completely unexpected
I was messin with OpenGL commands incorrectly and get strange effect
Title: Re: SpriteZ - 2d particle engine (Updated: June 15,2012)
Post by: Xaron on 2012-Nov-02
Sorry if I'm a bit confused but have you already made the 3d version of your particle engine? :)
Title: Re: SpriteZ - 2d particle engine (Updated: June 15,2012)
Post by: Hemlos on 2012-Nov-02
Yes i have, but i did not yet release it.
There is a single bug that im aware of, which im still thinking about how to terminate.
I still need to finish writting the documentation on it too.

I have a demo that im working on, showing many possibilities it can do.
At this point it can produce a few thousand billboards or objects, running in a couple dozen emitters at once, on a slow computer and so-so gpu.

If you plan on using the 3d version, i recommend that you get fammiliar with spritez2d, because this 3d lib is the "big brother".

PS. spritez2d should be working good with the current version of GLBasic, and if it is not, i will still support it and will work out any bugs you might find if any.
PPS. There is a possiblity that i setup the system with TYPES, so i dont know when ill be finished.
Title: Re: SpriteZ - 2d particle engine (Updated: June 15,2012)
Post by: Xaron on 2012-Nov-02
Thanks for the quick answer!

Do you have any ETA on the 3d lib? I don't mind the costs. :D Will it be ready this year?