Jump to content

mesh based particle system


jerome
 Share

Recommended Posts

You love it, and you know it.  :)  It's like a crossword puzzle with three words yet unanswered.  It keeps you coming back, and often obsessively, right?  The sign of a great project.

 

Billlboard mode.  hmmm.  I think you should say goodbye to it.   Maybe it's time to use statics.

 

BABYLON.SolidParticleSystem.ROTATIONMODE_X  et al.

 

_x _y _z _xy _xz _yz _all _none _random

 

Then, for particle rotation speed... allow value or random as well... and allow zero... which would be the same as ROATATIONMODE_NONE, right?

 

In fact, it would be nice if ALL of BJS... allowed Math.Random() to be abbreviated IN THE CODE... with ?  ...a question mark.  :)  Hey ECMA.

 

Good luck on your bug find, ParticleMan!  Don't try to find it too quick... or you'll need to think-up yet another feature.  ;)

 

Oh crap, I didn't cover BILLBOARD in my list of particle rotation constants.  Yep, we still got trouble.  Rotation modes aside, there's still three axes that could be told to face the camera.  hmm.  *scratch scratch*  And the many billboard modes could "fight" against the particle rotation modes.  Crap!

 

User has sps rotationMode set to all, but billboardmode_x set... and is in the forum, asking why their particles won't rotate on the x axis.  Trouble.

 

Okay, ignore me and this post.  :)

Link to comment
Share on other sites

but I have another just-backed nice feature : the per particle texture ! :)

from a single BJS classic texture

 

something you can set either in initParticles() either in setParticles() ... yes, live texturing in the render loop if you want !

 

It already works

But I want to fix this f$*%§@#king billboard mode for plane particles. My afternoon on it and ... nothing, pffff

I give up for today.

Link to comment
Share on other sites

Hi guys !

 

What is the worst bug you ever had to fix ? the bug that doesn't exist !

I wasted my afternoon yesterday trying to fix the billboard mode... that wasn't broken.

Let's forget this...

 

So at last, today, here is the new feature I wanted to introduce you yesterday : http://www.babylonjs-playground.com/#2KSQ1R#32

Here are some textured and colored quad particles slowly rotating in billboard mode. You should recognize the wise old man and his famous tongue in the picture.

As you can see at the line 24, it's a very classical BJS Texture what is then then applied to the SPS mesh material (line 34).

 

Let's now use a new particle property that I called uvs for now (may a better name would be needed). This uvs property is just an array with 4 numeric elements [u0, v0, u1, v1].

u0, v0 are the "coordinates" of the upper left point from where you want to crop the particle image in the loaded texture

u1, v1 are the "coordinates" of the lower right point down to where you want to crop the particle image in the loaded texture

 

u0, v0, u1, v1 are just expressed in percentages of the original texture, it is to say with values between 0 and 1.

 

Dont talk, show !

Line 50, in the initParticles function, I set random values to uvs for each particles : http://www.babylonjs-playground.com/#2KSQ1R#33

 

Of course, it would be better to have a real image with many different patterns (like a texture atlas) and to set them to each particle. But I don't have such a file here, sorry.

 

Does this work only in initParticles() ?

No, sir, it can work at run time !

 

Line 56, in the updateParticle() method. Beware if you are epilectic : http://www.babylonjs-playground.com/#2KSQ1R#34

:)

 

Note : API changed and billboard is now a SPS property that can be changed at any time.

There are also other new  available methods to optimize the SPS setParticles() method if you know you don't need (even temporarily) some features :

SPS.enableParticleRotation()        // prevent from computing particle.rotationSPS.disableParticleRotation()      // re-activate particle.rotation computingSPS.enableParticleTexture()         // prevent from computing particle.uvsSPS.disableParticleTexture()       // re-activate particle.uvs computingSPS.enableParticleColor()           // prevent from computing particle.colorSPS.disableParticleColor()         // re-activate particle.color computing

Everything is unfrozen by default.

 

doc updated : https://github.com/BabylonJSX/SolidParticleSystem

 

 

[EDIT] all freezeXXX() method names changed into enableXXX() because they don't keep the last values hypothetically used.

Link to comment
Share on other sites

I stole a sprite atlas somewhere on the Web just to show you how a single texture can make different particle images :

 

http://www.babylonjs-playground.com/#2KSQ1R#37

 

As you can see, the original image contains 6 x 4 sprites : http://jerome.bousquie.fr/BJS/images/spriteAtlas.png

So in the initParticles() function, I simply set random sprites to each particle (line 46)

      var hSpriteNb =  6;  // 6 sprites per raw      var vSpriteNb =  4;  // 4 sprite raws      var u = Math.floor(Math.random() * hSpriteNb) / hSpriteNb;      var v = Math.floor(Math.random() * vSpriteNb) / vSpriteNb;      this.particles[p].uvs = [u, v, u + 1 / hSpriteNb, v + 1 /vSpriteNb];

easy, isn't it ? :)

Link to comment
Share on other sites

I keep checking the thread now and then.. when it's done I might try to create a really cool space scene with god ray sun, partcle paralax stars in the background, some planets orbiting the sun and a cool spaceship in an asteroid filed.

 

Can your Mesh Particle System do that? I mean a really cool asteroid field? and derbies from the spaceship that got hit by the asteroids? I assume it can. This will be AWESOME! :D

Link to comment
Share on other sites

The SPS can do :

  • asteroid fields
  • scraps blown for an explosion
  • liquid drops flowing
  • immobile buildings in the distance
  • music 3D vu-meter
  • luck in games
  • professional success
  • love regain
  • coffee

:D

 

Well, it's just one single mesh with many accessible parts.

Just see SPS as an API to program these parts.

Link to comment
Share on other sites

It's almost done anyway

 

I would love to add :

- the ability to dispose the SPS

- the ability for the end user to dynamically morph each particle 

- (maybe) the ability to sort particles according to the particle-camera distance in order to solve the exotic case of vertices with alpha wrongly z-sorted... not sure it's worth it because of the performance cost.

 

BTW, in the current SPS I re-implemented some BJS internal methods (like Matrix.RotationYawPitchRoll or Quaternion.toMatrix) with no temporary local variables.

I did it because I noticed the GC can deal pretty well with temp variable allocations if we call these methods, say, dozen times per frame.

But since in SPS we do CPU side things that usually happens GPU side (like to compute each position and rotation of each vertex of each particle...and we may have 10K particles !), we need to call rotationYawPitchRoll dozen of thousands times each frame... and it quickly reaches an amount of temp memory allocation that has a significative effect on the GC.

That's why many SPS private properties are set just for storing temporary values and to never allocate/free the related memory. The re-implemented functions then use these private properties.

Link to comment
Share on other sites

This is looking great.  Your demos run surprisingly well on my 3 year old Nokia 822 windows phone.

 

How hard would it be to get skeletons/animations working with this?  I wonder if that would just kill the performance gains you have achieved.

Link to comment
Share on other sites

cool

step after step (and my steps are shorter with such a hot weather here) :

first finish it

then push it to official extension repo

then maybe... port it to TS if you want it in BJS.... but this may keep optional

Link to comment
Share on other sites

just some news : this topic is not dead ...

Things go on under hood very slowly because it's very hot here and I have another real job to do ;)

 

Well, added :

SPS.dispose() to free the memory if you don't need the SPS anylonger

and internal refactoring to get rid off parameter variables in re-implemented legacy BJS rotation functions... a serious hunt to every case where the GC could wake up

Link to comment
Share on other sites

Hi guys,

 

"a feature a day keeps the DK away"

 

Let's go today for the particle rotation quaternion :
http://www.babylonjs-playground.com/#2KSQ1R#39

 

Here, I just set a classic SPS. Just note I don't call for now the setParticles() method in the render loop (line 78), so it doesn't call the updateParticle() method each frame.

Take a look at initParticles() (line 49) and  updateParticle() (from line 65).

As you can see, I don't use any longer the particle rotation property (which still exists, don't worry) but a new property called quaternion in order to set each particle rotation quaternion (amazing, isn't it ?).

 

Why a quaternion and not just a rotation ?

Because it could be easier sometimes to define a rotation around an axis than from euler angles only.

If you look at the updateParticle() code, you will see that I give each particle a rotation (zero for now) around the axis origin-particle position. So each particle will then rotate around the axis what starts at the origin and what holds the particle.

 

Let's uncomment the line 78 : http://www.babylonjs-playground.com/#2KSQ1R#40

 

It's not that easy to check, but each particle now rotates around a radius (O-particle)... maybe slower (sorry DK for this one-more-PG ;) ) : http://www.babylonjs-playground.com/#2KSQ1R#41

 

 

[EDIT] : added radius lines so it is easier to understand : http://www.babylonjs-playground.com/#2KSQ1R#42

 

As for standard BJS meshes, if you define a particle quaternion, its rotation property is ignored.

 

updated doc : https://github.com/BabylonJSX/SolidParticleSystem

Link to comment
Share on other sites

Hi people,

 

As usual, here is the second feature of the day ;)

 

Well, as this one is really powerful and complex (imHo), it is not enabled by default.

Let's go : http://www.babylonjs-playground.com/#2KSQ1R#43

 

You can see a usual SPS with 100 cubes and 50 spheres orbiting.

Line 71 :

PS.enableParticleVertex();

This will  make the user custom updateParticleVertex(particle, vertex, i) to be called on each vertex of each particle !

particle is the current particle

vertex the current vertex

i the index of the current (i-th) vertex

 

What is this for ?

Well you can now morph your particles dynamically !

line 64 , let's define a custom function :

        PS.updateParticleVertex = function(particle, vertex, i) {            if (particle.shapeId == 1) {              vertex.x += 1.2 * Math.cos( ang * i / 1000 );            }      };

Here, I set a new x value to each vertex of particles with shapeId equal to 1 (my spheres). Since I can access the vertex index, I use this value to multiply it by an increasing angle :

http://www.babylonjs-playground.com/#2KSQ1R#44 :P

 

Well, the example may be not be that pertinent because the morph function is really simple here, but you can see that only spheres are morphed.

 

Does it still work with other properties like rotation ?

Yes, sir : http://www.babylonjs-playground.com/#2KSQ1R#45

line 59

 

Have fun !

 

I think this will be the last feature of the SPS as I it is quite versatile now, being able to redo almost a BJS like particle system if you use only quads with no normals and other optimizations (with disableXXX() methods) to some complex slower and parametrable 3D shape system with all mesh properties.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...