Search Unity

DX11 Particle Systems WIP

Discussion in 'Works In Progress - Archive' started by bajeo88, Feb 23, 2013.

  1. bajeo88

    bajeo88

    Joined:
    Jul 4, 2012
    Posts:
    64
    Im busy making a DX11 Particle System for Unity, been working on it now for about 2 weekends so thought i would post what i have so far and see if i can get any feedback as to how to improve it so i can release it in the near future.

    Some quick screen caps!




    Technical stuff:
    - C#/Compute Shader written
    - The overall controller is C# but all particle updates are done entirely in shaders
    - Supports multiple particle systems at once
    - All particle systems are stored in XML so they can be edited/loaded/saved at runtime like prefabs. They can also be transferred easily from project to project by simply copying the XML file.
    - Easily extendable... to prove this made a Cloud extension from this which made infinite clouds 35,000ft high using scrolling perlin noise and only had to override 3 functions!
    - All particles can have custom velocities, speed, size, colour, mass, life, scale over life, emitter region size
    - All particles can also be affected by external forces such as gravity, wind, drag.
    - All particles can also collide and diffuse around simple colliders such as spheres and cubes (hoping to extend this soon to planes, capsules and then custom meshes such as terrains.
    - Also certain particle systems can actually be recorded (I have written a generic Replay Manager) so you can record a particle system then rewind it and play it back like a video!

    Future improvements:
    - Different render shaders to choose from (At the moment its only additive or multiplicative blending)
    - Perhaps extend the record/rewind/playback feature globally across all particle systems depending on difficulty and peoples urge to have it as a must have feature.
    - More particle physics, perhaps even extensions such as fluid based particles.
    - Optimisations since at the moment i havent really maxed out the system to completely test it. Im mostly messing around with multiple systems of around 60,000+ particles but have had single systems running at a few million particles with GPU sitting around 0.2ms.

    I am thinking to release this when its complete either for free or pay... haven't decided yet.
    Any suggestions for improvements, ideas or just want to say hi post below.
     
  2. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    Impressive!
    Looking forward to see more of this.
     
  3. SimtropBuggi

    SimtropBuggi

    Joined:
    Feb 15, 2013
    Posts:
    98
    wow, another great GPU particle system! Any plans to support OpenCL?

    Maybe you could join forces with the TC Particle guys and really explode this awesome technology.
     
  4. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    No. Two systems = Concurrency = Best price for us.. ;)
     
  5. bajeo88

    bajeo88

    Joined:
    Jul 4, 2012
    Posts:
    64
    Thanks for the comments! Good to see some interest in this technology.

    @ SimtropBuggi - No plans for OpenCL at the moment as my knowledge is limited in this area. In fact before last month i had no knowledge of shader language (just a few lessons from Uni a few years back) but i understand the theory and concepts and once i guessed my way around some of the lacking unity documents this system was working. DX11/Compute shaders are very simple once you get past the annoying syntax of getting stuff into the buffers and learn some of the quirks.

    @ ZJP - I agree completely while i love TC Particle System and merging might sound like a fun idea I already have a good job (making Simulators) and so dont really want to be tied down into supporting this forever. Imagine an entire community sharing the knowledge for free, how far would the community take it? Thats more the side i am interested in! Maybe someone out there will see my system learn from it spot a flaw and make it 10 times faster and re-share it with the community! After all we all want to make games?... not packages to sell in the unity asset store.

    What would the community do with this if it was available for free, what would you make next? Compute Shader AI? Database searching? Or just a really big explosion and crash your graphics card because thats what i did first! :D
     
  6. JessyDL

    JessyDL

    Joined:
    Nov 27, 2012
    Posts:
    60
    I'd honestly think the community would love you for it.

    I was actually going to take a crack at GPU particles next week, haven't delved into DX11 rendering too much yet, so was going to be a nice introduction to it. Any specific issues you ran into as you said you had some guesswork?
     
  7. bajeo88

    bajeo88

    Joined:
    Jul 4, 2012
    Posts:
    64
    Hey JessyDL, actually getting the system connected was quite difficult, theres nothing more annoying than thinking you have all the dots connected and .... nothing happens.

    The annoying bit for me was the realisation that C# side you have multiple instances of different particle systems but on the GPU they are all sharing one memory pool and so constantly overriding each others memory especially since each particle system has at the moment 3 buffers of data and in my case only certain buffers should be overridden. The obvious quick solution it to make multiple Compute shaders and rename them which while this is a temporary solution it is not a very expandable system. So after a lot of forum crawling i came across a post by Aras actually answering this same question to the TC Particles guy where he suggested C# side simply swap over the buffers and dispatch. Looking back a better solution than mine might be to have a pool of Compute Shaders which is managed but i dont know how much of a speed boost there would be so it might even be something i look into in future.

    I think as long as the community want to expand it and keep it free and treat it as a WIP as the code so far is not final by any means then as a community we could make some cool things with it.
     
  8. JessyDL

    JessyDL

    Joined:
    Nov 27, 2012
    Posts:
    60
    Ah, it's always fun isn't it, after all that work, nothing to show for and being so sure you're in the right direction :D
    Graphics programming can really be annoying like that at times, but so gratifying when it all suddenly comes together.

    Yea saw the TC post by Aras a while back as well. Thanks for the info thou, will definitely keep in mind.
     
  9. bajeo88

    bajeo88

    Joined:
    Jul 4, 2012
    Posts:
    64


    Another taster and addition the the system.

    Particle can blend between two colours over their life and also be affected by a third colour to generally tint the the entire system throughout all stages. Handy for making realistic fire and also unrealistic smokey effects. Alternatively the entire colour tinting can be completely ditched at you can declare colours from C# and have them all random colours

    I am going to be releasing this package for free in the next few days and i will include all source code! I am trying to get velocity fields working first but i may scrap them and just release the package and patch it later as all the data is optional anyway. If anyone has experience with making Curl Noise etc... and wants to get involved then get in contact.
     
  10. pvloon

    pvloon

    Joined:
    Oct 5, 2011
    Posts:
    591
    Hi there! Boy, I need to be in this WIP section more ;) That's quite cool! Looks like TC Particles is already has Concurrency, even before release!

    As to the issue with a shared memory pool: I was indeed struggling with it at the start as well. Swapping buffers is by far the best solution I found. Every frame I call a SetParticles() function, which binds all buffers and streams all data of all the particle modules. You'd think that this is slow but it actually isn't costly at all. It's a little differnt way to think, but it's the way to go!

    I love your initiative to release this for free. I intend to share some DX11 knowledge as well, when I have the time to do so.

    Also, for the noise: I use a LibNoise C# wrapper, and generate the noise on the CPU to a 3D texture. Generating it on the GPU can give animated noise, maybe even more effects, but that would be quite performance heavy, and not as flexible as CPU noise.
     
  11. bajeo88

    bajeo88

    Joined:
    Jul 4, 2012
    Posts:
    64
    See Showcase thread for more info and download link - Now released to public :)

    Enjoy!