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.

DarkBASIC Professional Discussion / Creating a Particle System

Author
Message
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 29th Jul 2010 23:03
Hi guys. I've been playing with particles for a time now and finally created something that suits my needs, an event based particle system very similar to 3ds max's particle flow system. But I need to sort out a few things and thought I'd make a general thread for it.

So first would be, what's the math to set the initial velocity (3d) of the particle based on emitter direction? The method I'm currently using is the limb one, but I'd rather do the maths.

Second being Colour and Alpha which has been a pain. I'm working with shaders for the blending so I can have cool effects but when it comes to colour and alpha. I can't put it in a shader or I'd have to load a shader for each particle that's active. I have shaders for each blending mode since I can't use just one but I need colour and alpha. So is there a way to set the colour and alpha for shader affected objects in DBP? (I believe you can with memblocks but not sure)

Just two for now, Thanks in advance

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 30th Jul 2010 00:40
Quote: " I can't put it in a shader or I'd have to load a shader for each particle that's active."

No you don't. The shader (.fx) can be assigned to all your particles; assuming you want the same affect to be on all of them.

As far as keeping track of the objects: Each particle can be it's own limb/object. Each one has it's own xyz. So use the particle system has a set of rules you made from looking at 3dsMax. You have to do each one of them seperately or in small groups that act as one object but move within the group (I don't recommend the second part tho).

If you are having trouble with the specifics of your system, post it and I'll have a look.

The fastest code is the code never written.
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 30th Jul 2010 00:53 Edited at: 30th Jul 2010 00:55
Quote: "No you don't. The shader (.fx) can be assigned to all your particles; assuming you want the same affect to be on all of them."


True. But all active particles will have the same blending mode/colour/alpha of the last particle. You can't pass multiple value for one parameter to a shader, whatever the last value say colour value was passed, when it comes to rendering everything assigned to the shader will have the same colour. The only way to get round this is to have a separate shader for each particle (avoid this), or what I want to do which is have separate shaders for each blend mode. But when it comes to colour and alpha, there's way to many values so it has to be done outside the shader.

Quote: "As far as keeping track of the objects: Each particle can be it's own limb/object. Each one has it's own xyz. So use the particle system has a set of rules you made from looking at 3dsMax. You have to do each one of them seperately or in small groups that act as one object but move within the group (I don't recommend the second part tho)."


Not sure what your referring to here.

Solved the first problem, think I got this right:



A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 30th Jul 2010 02:29 Edited at: 30th Jul 2010 02:48
Just tested something out and it's pretty neat. This is an example of a particle flow system:





And the result is the attached exe. WASD + Mouse to move, Press E to start/stop flow. (Warning, particle intensive, about 1024 cubes)

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 30th Jul 2010 03:12
Now I'm confused. Did you have a question? I thought I was answering one..... Is this just a program/example or is there something you need help with?

The fastest code is the code never written.
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 30th Jul 2010 03:20
Quote: "Now I'm confused. Did you have a question? I thought I was answering one..... Is this just a program/example or is there something you need help with?"


My Questions:
1. What's the math to set the initial velocity (3d) of the particle based on emitter direction? - (I solved this)

2. Is there a way to set the colour and alpha for shader affected objects in DBP? - (ongoing)

I just posted the particle demo and what not so people could get an idea of what I'm doing, where I'm at or whatever you can extrapolate from it.

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 30th Jul 2010 03:39
Sorry, I don't have winzip (I refuse to buy something I used to get for free). But regardless, I couldn't help with it anyway with the color and alpha problem. I'm sure someone will.

The fastest code is the code never written.
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 30th Jul 2010 03:49
You should download 7zip. It's free and is the best packer/unpacker, even better than winrar: 7zip

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Jeff032
18
Years of Service
User Offline
Joined: 13th Aug 2007
Location:
Posted: 30th Jul 2010 03:57 Edited at: 30th Jul 2010 03:58
Quote: "Sorry, I don't have winzip (I refuse to buy something I used to get for free). But regardless, I couldn't help with it anyway with the color and alpha problem. I'm sure someone will."

Go search for 7-zip. It's free.

Quote: "Is there a way to set the colour and alpha for shader affected objects in DBP? - (ongoing)"

If you aren't going to use instancing, you could use a vertex format that contains color data I think. Though, it would probably be better if you were using instancing. (It doesn't look like you are)

[EDIT]
Looks like you beat me to recommending 7-zip

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 30th Jul 2010 04:39 Edited at: 30th Jul 2010 04:40
Quote: "If you aren't going to use instancing, you could use a vertex format that contains color data I think. Though, it would probably be better if you were using instancing. (It doesn't look like you are)"


I didn't instance cause I knew I would have issues with it like I did before. But I'll lookup the vertex method, cheers.

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Duke E
17
Years of Service
User Offline
Joined: 10th Mar 2009
Location:
Posted: 30th Jul 2010 05:07 Edited at: 30th Jul 2010 05:27
Hi susake, we have come across each other now and then with the particle system stuff

To set the alpha is pretty easy whats, the problem is you can't have a particle setup where every particle is separate and use the same shader for all.

I hope my quest to make a decent performing particle system is soon over.

I finished my old particle system using billboarded planes and was really disappointed in the performance even after extensive optimization.
I could run 2000 particles and then it took so much CPU it began to slow down the game too much.

I have just now put the finishing touches to the shaders in a particle system using shaders and memblock created emitter objects using "Point Sprites".
The performance is quite impressive as all particle calculations and transformations are done on the GPU. Point sprites uses the vertices in a object to represent the particle i.e three particles/triangle, so i save quite a lot of polygons compared to using quads.

The techniques i have in the shader are rotation and tile (atlas) animation, and alignment of the particle in the movement direction (a subset of rotation). Persistent - long living emitters for smoke or a fire that reuses the particles as they fade. Burst emitters - for explosions that puts out all particles in one go.
Edit: And of course fade in, fade out, lifetime and such, all with randomization.

If i put all techniques in a single shader the loading times are high, over a second/particleemitter (due to the compilation that takes place on load). Think i separate every technique to it's own shader. I have to load a shader for each emitter but an emitter can have a couple thousand particles that animates separately.

I use a re-randomization that randomizes the particles in the shader. I reseed the emitter/shader with a random number and the shader uses that random number to create a unique random sequence for that emitter at that specific time. The same emitter (object/shader) can then be re-textured, re-seeded and used again for another particle setup, this with very little CPU time consumed.

I am now working on the program wrapper to handle the shaders and emitter objects.

Screenshot or it didn't happen
(2000 particles rotating and tile animated with 16 frames. It's a persistent emitter that re-spawns the particles and some gravity to pull them in a nice arc moving at 200 DBP units/second)



Regards
Pandora beads
15
Years of Service
User Offline
Joined: 30th Jul 2010
Location: Pandora beads
Posted: 30th Jul 2010 11:32
ho! The effect is so good!!

I love game and create game and Pandora beads
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 30th Jul 2010 13:37
Quote: "You can't pass multiple value for one parameter to a shader, whatever the last value say colour value was passed, when it comes to rendering everything assigned to the shader will have the same colour. The only way to get round this is to have a separate shader for each particle (avoid this), "


Yes you can - you can use a different image for each particle if they are different limbs or objects. These images can be small, e.g. 1x1 or 4x4 and can store all sorts of useful information which you can use look up and use in the shader.

But even without that why can't you adjust the alpha, etc, using information from things like position and time?
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 30th Jul 2010 13:40
Hey Duke, looks really great. I was contemplating point sprites but had a few issues with the limitations, so I'm implementing different render types to the engine, point sprites being one of them. With the standard method, I'm quite confuse on how DBP handles objects, you can emit 2000 cubes or 2000 plains or 2000 triangles and they all take up the same performance. How the hell can a cube be equal to a triangle in terms of performance, it doesn't make sense. Anyway, I'd love to see yours in action in a vid or something in the future, cause it sounds great at the moment.

Issue with math again, I just noticed this wouldn't account for the X/roll component:



Any ideas on how to include the 'roll' in this?

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 30th Jul 2010 13:46 Edited at: 30th Jul 2010 13:49
It's a pain when someone posts right before yours, cause if you just edit your post to include what they've said they could have already missed it.

Quote: "Yes you can - you can use a different image for each particle if they are different limbs or objects. These images can be small, e.g. 1x1 or 4x4 and can store all sorts of useful information which you can use look up and use in the shader."


Really, Ooooh, would you be able to give me a small example or point me in the right direction, if you have the time that is. I'll have a search too.

Quote: "But even without that why can't you adjust the alpha, etc, using information from things like position and time?"


Not quite sure what you mean...

Edit: Mega thanks for reminding me GG, need to use limbs for particles, so much faster.

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 30th Jul 2010 14:15 Edited at: 30th Jul 2010 14:28
Quote: "Really, Ooooh, would you be able to give me a small example or point me in the right direction, if you have the time that is. I'll have a search too."


I'll have a dig around too (or create a simple demo - might even be quicker).

Edit While you're waiting for me to find/create a demo of that idea you might like to have a look at this. The "particles" are a single object (with one limb I think) whose vertices get manipulated in the shader.
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 30th Jul 2010 14:28
Cheers Sir Gandalf

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Jeff032
18
Years of Service
User Offline
Joined: 13th Aug 2007
Location:
Posted: 30th Jul 2010 14:59
Quote: "With the standard method, I'm quite confuse on how DBP handles objects, you can emit 2000 cubes or 2000 plains or 2000 triangles and they all take up the same performance. How the hell can a cube be equal to a triangle in terms of performance, it doesn't make sense."


The cost of rendering a couple extra triangles is negligible compared to the overhead of your 2000 separate draw calls.

@Duke E
I was unaware that DBPro had support for point sprites. Or are you writing a DLL to do it?

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 30th Jul 2010 15:00
Just had a peek at my old demos and I recall now why I used a single object with a single limb consisting of many billboards - I get uncapped FPS of >2000 using a single limb but only about 200 using many limbs.

You could try adapting the demo I've just posted. That demo uses vertex normals to store all sorts of supplementary information used by the shader (particles don't really need a vertex normal so you can use it to store something else). You might be able to store/modify the alpha value in one of those. You could also change the FVF so it has vertex diffuse, etc, and change that in real time per vertex and use it in the shader.

I'll still dig out a demo of the single shader/many textures idea though.
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 30th Jul 2010 15:23
Jeff032,

Quote: "The cost of rendering a couple extra triangles is negligible compared to the overhead of your 2000 separate draw calls."


Aww, draw calls, totally forgot about that. Now it makes sense.

As for point sprites, dark coder (well it's the only one I could get working on this thread) made a demo awhile ago: Point Sprites

GG, Cheers, I check out the file and have a play with what you said

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 30th Jul 2010 15:59
Here's a demo of the single shader/many textures idea. This uses 1001 plains as separate limbs and colours them using separate textures. If you press "c" the limbs are retextured.

However, this seems to be much slower than using a single limb and you'd be better off finding a way of passing separate colour/alpha info via the vertex data as in the previous demo.
EVOLVED
23
Years of Service
User Offline
Joined: 9th Feb 2003
Location: unknown
Posted: 30th Jul 2010 21:55 Edited at: 30th Jul 2010 22:34
@ Sasuke

you can use 3d maths to turn angle in to direction:



[Edit]

I was working on a emitter system a few weeks back, I was using a single object with a shader. I was then using shader arrays to set position/scale/color and alpha.

example:


The performance was pretty good and I had full control over each particle.
Duke E
17
Years of Service
User Offline
Joined: 10th Mar 2009
Location:
Posted: 31st Jul 2010 05:16
Quote: "Jeff032@Duke E
I was unaware that DBPro had support for point sprites. Or are you writing a DLL to do it?"


No Jeff032, it is just an object created in a memblock (similar to what Green Gandalf posted). The object FVF characteristics represent PSprites that can be passed to a shader.

I found the method here, made by Dark Coder (i guess? probably GG's code from the start )
http://forum.thegamecreators.com/?m=forum_view&t=121302&b=1 and adapted it.

I began experimenting with the shader from Green Gandalf's "Vertex particle" demo found in the "Learning to write shaders" thread. I opted out the quads for the Point Sprite method and added some more control, rotation, alpha fade, and atlas animation to the shader.

Quote: "susake> you can emit 2000 cubes or 2000 plains or 2000 triangles and they all take up the same performance"


Yeah DPB running objects in CPU code are pretty much the same performance. I experimented with emitters for debris spawning multi polygon objects, no difference from quads, putting this on the GPU is the way to go imo.

@EVOLVED
Quite interesting. The drawback with the approach using a shaded emitter object is you can't move the emitter object and have the particles trail after it in a "magic wand" sparks trail fashion. Moving the emitter object will make all the particles follow the the object.
Could this be used to control the transformation , would be grateful if you could elaborate?

Regards
EVOLVED
23
Years of Service
User Offline
Joined: 9th Feb 2003
Location: unknown
Posted: 31st Jul 2010 09:59 Edited at: 31st Jul 2010 10:12
In the system Iv created you can move the emit position without it effecting the already emitted particles, I will have to do a youtube video showing this.


here is a cut down shader off what Im using.



note: particle number element is stored in the U of objects uv stage 1( set vertexdata uv vertex,1,partical,0 )

[EDIT]

here a make particle object function Im using(bit unfinished),just use this with the above shader code and fill in the rest in dbp.

Duke E
17
Years of Service
User Offline
Joined: 10th Mar 2009
Location:
Posted: 31st Jul 2010 12:50 Edited at: 31st Jul 2010 12:52
Thanks EVOLVED, i searched and found info on "Release Effect Pointer" and "get object effect". They where not in the help files .

That is a nice complement to be able to make effects for missile smoke trails and the like. It will take CPU time tracking the particles compared to the "fire and forget" approach i have now though but used in a limited way very useful, thanks again.

Regards
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 16th Aug 2010 00:47
Cheers EVOLVED and Green Gandalf for the assist.

Back to functionality for a sec. An event based system of this design is really awesome. You have so much functionality with ease to make. An example of the editor, this is a pic of 3ds Max's Particle flow view which mine is modelled off:



Though mine is more tailored to games, includes more elements, source events and time graphs. Will put pics of the editor up soon, just need sort out some bugs with scaling (stupid text).

I've been doing a bit of playing around with concepts and ideas, one being particle source or emitter. I had the idea of setting objects as a source with a global force test (global to a certain radius) event attached to it. Basically telling the engine that if an explosion went off near the object and had sufficient force, the object would emit particles. So if the object was a big rock, it could emit dust when shocked enough. It even works with collision, so if you dropped the rock and it hit something with enough force it would emit dust or even debris.

One thing I would like to make is wind with turbulence, but I haven't been able to find very much on the subject, well for particles that is. So anyone have any ideas on this one?

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 21st Aug 2010 01:39
Does anyone have any good links or knowledge of implemented forces?

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.

Login to post a reply

Server time is: 2026-07-24 20:45:38
Your offset time is: 2026-07-24 20:45:38