Sign in to follow this  
Koroldev

ParticlesSystem from AtlasSubPicture

Recommended Posts

Hi! How I can create paticleSystem with subPicture fromTextureAtlass? In past I used texture atlases for Sprite2D, but now I have many textures for my particles systems and I want combine all my textures in one big textures, but how I can get subTexture from my big atlas texture or it is imposible and atlases using only for Sprite2D? Thank for any information :)

Share this post


Link to post
Share on other sites

Hi again, Negrant.

I don't think that is possible with our standard particle system, but perhaps it is... with a custom shader.  Not sure.

Here is a Solid Particle System, using planes, with texture = atlas... which shows it can be done with SPS system.

I'm not pro with SPS, but let's tour:

Lines 22-23 - scaling... smaller number = bigger sprite face.  :)  Experiment.

Lines 26-27 - offsets... careful micro-adjusting picks the sub-image in the atlas sheet.

Lines 30-35 - A Wingnut uOffset and vOffset animation.  Activate for fun.

Line 40... set shape and how many.

Lines 72-83 - a scaling, rotation, and color section... disabled by Wingnut to make tests easier to see.  Please re-enable at-will.

Helper:  You can highLight large blocks of code, and toggle activation ON/OFF with control /

If all your particle textures are the same size within the particle-atlas, and all spaced proportionately, then you will be able to index-into the particleAtlas with a math formula.  (You probably knew that already.)  :)

If your particleSprites are varying sizes and spaced inconsistently, you may wish to maintain a little array of u/v Scales and u/v Offsets... pre-calculated atlas targets.  :)

I tried using standard particleSystem, but u/v Scales and u/v Offsets did not work, for that.  Perhaps I tried it incorrectly, but, perhaps not.

If you see color-changing, it is likely due to red-ish specular in line 12 light.  (I borrowed this playground code from Jerome)  :)

Also, hemispheric light in line 8 is aimed in an unusual way.  They are most-often aimed 0, 1, 0... straight up.

This is the ONE WAY I know how to do this.  There may be other ways, and/or better ways.  Others may comment soon.  Be well, we'll talk.

Share this post


Link to post
Share on other sites

Wingnut, thank you, cool ideaB) One question about perfomance - it is the main thing for what I am doing this. What better for perfomace on your opinion, 10 textures each one it is single file and using it for ParticleSystem or one big texture atlass and using it for SolidParticleSystem? Because I want that game working on the weak laptops and I am trying to maximal optimize my game, Thank you so much for help!

Share this post


Link to post
Share on other sites

Thanks... I'm glad you like.

You ask a very good question.  I will ping @jerome for his opinion, too.  He invented SolidParticleSystem (SPS) and was always concerned-with performance during its dev.  SPS is more feature-packed than particleSystem... allowing planes, boxes, tetrahedrons, nearly any shape.  SPS also has basic particle collision feature, and also MIGHT allow particles to cast shadows and emit godrays.  But you might not NEED any advanced features.

Also, do you know about "profiling"?  It is a performance tester inside browser f12 dev tools.  Perhaps you need to make tests in there.  It would be FAR wiser than Wingnut opinion.  :)  I GUESS that standard particleSystem would be faster, but 10 textures has extra load-time.  Is load-time part of performance?  Perhaps.

Maybe... someone has ideas for using atlas with standard particleSystem.  Take a look at particleSystem shader.  See line 4?  There is a vector4 (4 values) called options.  In line 25, you see that LAST 2 values (z & w) is an "offset".  Then in line 40, vUV = offset.  vUV perhaps === uOffset and vOffset - the same values we adjust in SPS. 

But I am not sure how we users can change z and w values of options Vector4... in particleSystem.  Hopefully, others will tell us more.  Are you under a deadline?  (I hope not, they are stressful)

Perhaps you can do some test profiling, and we can wait some more time... for more/better replies and advice.

Shader gods... please help.  Can we do uOffset and vOffset on particleSystem refmaps?  Can someone show us HOW?

Thanks for help, fellow forumers.  :)  Talk soon, Negrant.  Reply, as wanted, of course.

Share this post


Link to post
Share on other sites

In theory the standard particle system is faster than the SPS. You should be able to start to notice a little difference for more than 12-15K particles emitted at once (more visible above 50K particles)

That said, if you need :

correctly sorted particles relatively to other transparent meshes or per particle color/texturing/scaling/pickability or particle intersection computation or solid particles... well, you have no other choice to use the SPS...

The SPS is quite optimized and its performances will be really close from the standard particle system and you would probably notice no difference for thousands of particles.

Share this post


Link to post
Share on other sites
1 hour ago, Wingnut said:

SPS is more feature-packed than particleSystem... allowing planes, boxes, tetrahedrons, nearly any shape.  SPS also has basic particle collision feature, and also MIGHT allow particles to cast shadows and emit godrays.

Quote

But you might not NEED any advanced features.

I immediately thought about explosions :Dwith using the spheres like in old lowpoly games on sony playstaion1 or sega dreamcats, I will hold this idea to the future. In past I was going to do explosions with sprites, but now only SPS :)

Quote

Also, do you know about "profiling"?  It is a performance tester inside browser f12 dev tools

Oh, I did not know about profiling, I am just using console, Thank, now I will use profiling

Quote

 Are you under a deadline?

Yes, I making games for social networks, it is my basic pay :) That's why some changes I will make in updated version of my game

Quote

Shader gods... please help.  Can we do uOffset and vOffset on particleSystem refmaps?  Can someone show us HOW?

:D:D maybe They will hear

Okay, thanks, I got it, and now I will dicide what better for current situations in my game

Most likely SPS it is good desicion, maximum counts of all particles emitted on scene at once it is 1-2k, as jerome said

Quote

you would probably notice no difference for thousands of particles

jerome, Thanks too! Very helpful info

Share this post


Link to post
Share on other sites

For 1 to 2K, the SPS is your friend anyway :-D

It's quite easy to make explosions with solid different particles rotating in every direction.

Have a look please at those demos featured by the BJS web site : 

http://www.babylonjs.com/demos/boom/

http://www.babylonjs.com/demos/spscollisions/

http://www.babylonjs.com/demos/facets/ 

Share this post


Link to post
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...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.