Search Unity

Particle Shaders Vol. 1 - Including Lit Particles

Discussion in 'Assets and Asset Store' started by varfare, Apr 20, 2015.

  1. varfare

    varfare

    Joined:
    Feb 12, 2013
    Posts:
    227
    Hi!

    For past few weeks I have been working on particle shaders designed for Shuriken particle system. Now, I am ready to present you Particle Shaders Volume 1 for Unity 5. The package features:
    - shadow casting
    - adjustable self-shadowing
    - HDR light emission
    - alpha blend & alpha erosion fade modes
    - soft particles support
    - support for all Unity 5 ambient modes (skylight, tricolor, flat ambient)
    - multi-light support (maximum lights per-system is defined by pixel light count in Unity quality tab)






    Download PC demo

    Code (CSharp):
    1.  
    2. // Stats for Vertex shader:
    3. //       d3d11 : 50 avg math (30..72)
    4. //    d3d11_9x : 50 avg math (30..72)
    5. //        d3d9 : 50 avg math (27..78)
    6. //        gles : 23 avg math (16..26), 1 avg texture (1..2)
    7. //       gles3 : 23 avg math (16..26), 1 avg texture (1..2)
    8. //       metal : 43 avg math (23..65)
    9. //      opengl : 23 avg math (16..26), 1 avg texture (1..2)
    10. // Stats for Fragment shader:
    11. //       d3d11 : 17 avg math (12..20), 1 avg texture (1..2)
    12. //    d3d11_9x : 17 avg math (12..20), 1 avg texture (1..2)
    13. //        d3d9 : 21 avg math (16..24), 1 avg texture (1..2)
    14. //       metal : 23 avg math (16..26), 1 avg texture (1..2)
    15.  

    Code (CSharp):
    1.  
    2. // Stats for Vertex shader:
    3. //       d3d11 : 9 avg math (5..13)
    4. //    d3d11_9x : 9 avg math (5..13)
    5. //        d3d9 : 9 avg math (6..13)
    6. //        gles : 11 avg math (6..16), 1 avg texture (1..2)
    7. //       gles3 : 11 avg math (6..16), 1 avg texture (1..2)
    8. //       metal : 5 avg math (3..8)
    9. //      opengl : 11 avg math (6..16), 1 avg texture (1..2)
    10. // Stats for Fragment shader:
    11. //       d3d11 : 9 avg math (5..13), 1 avg texture (1..2)
    12. //    d3d11_9x : 9 avg math (5..13), 1 avg texture (1..2)
    13. //        d3d9 : 9 avg math (6..13), 1 avg texture (1..2)
    14. //       metal : 11 avg math (6..16), 1 avg texture (1..2)
    15.  

    Current drawbacks:
    - particles don't receive shadows
    - performance may be a problem for mobiles

    Version 1.5.0 is now live!
    Asset Store link: http://u3d.as/content/micha-pi-tek/particle-shaders-vol-1/

    I hope that you'll find this useful :)
    Cheers!
     
    Last edited: Jul 2, 2017
  2. ctp

    ctp

    Joined:
    Apr 21, 2013
    Posts:
    9
    Great news!

    If I may request an additional feature, it would be to add "Clip Safe" functionality in the shaders (or make a separate set of shaders with this feature). The effect would be that particles fade to completely transparent, based on distance to camera. It is similar to what happens if you walk through smoke or mist - the density appears less intense right in front of your eyes than at a distance. Can be especially useful in a Virtual Reality experience, where experiencing large particle billboards being clipped right in your face, so to speak, is not desirable.
     
  3. varfare

    varfare

    Joined:
    Feb 12, 2013
    Posts:
    227
    I like the idea. I will definitely put this on my roadmap (maybe I should create public Trello board with features planned for this shader pack with voting options?).
     
    boysenberry and punk like this.
  4. Situacao

    Situacao

    Joined:
    Dec 4, 2013
    Posts:
    21
    Hey mate!

    Saw your shaders pack and it's exactly what I'm looking for, great job there. Will get them when they arrive at the Asset Store.
     
  5. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    2015-04-29_16h24_07.png
    This is an ongoing issue with particles in general. For example debris from an explosion in shadowed areas would be full bright - entirely stupid. Light probes can't detect realtime shadows either. Smoke in shadows will be full bright and so on. Any ideas how to fix it? I understand shadows are screen space now so perhaps sampling depth might be an option.

    Of course cutout works but then we're left with nasty edges.

    Finally: mild bug: black bits if light is shining through.
     
  6. varfare

    varfare

    Joined:
    Feb 12, 2013
    Posts:
    227
    Catching other objects' shadows is not the best idea. It is possible but the visual result won't be acceptable for professional use. The reason why transparent objects don't receive shadows is that they are not taken into account in shadowing pipeline at all. And the reason behind this is really simple - performance. Proper transparent shadows are quite costly. There are a lot of approaches around the web so you can dig into this. But be warned - it is time consuming to get this thing working.

    As for the bug - thanks for noticing. I'll have that fixed in upcoming update.

    And finally - I am pleased to say that Particle Shaders volume 1 is live and ready to buy for 10$!
    http://u3d.as/content/micha-pi-tek/particle-shaders-vol-1
     
  7. Situacao

    Situacao

    Joined:
    Dec 4, 2013
    Posts:
    21
    Varfare, have you tested this in Unity 4? Does it work at all?

    Thanks in advace!
     
  8. varfare

    varfare

    Joined:
    Feb 12, 2013
    Posts:
    227
    Current package works only with Unity 5.0+. I am creating separate package for Unity 4 but it needs some more work. Stay tuned.
     
  9. varfare

    varfare

    Joined:
    Feb 12, 2013
    Posts:
    227
    1.0.1 update has arrived and should be available within few days. Changelist:
    * Fixed black spots which were showing when looking at light source
    * Added EMLighting.cginc file which contains all lighting models. Now all shared functions and parameters will be handled inside this file

    I have also created a public roadmap with voting options so that I can focus more on features you wish to be implemented. You can also check what I'm currently working on (green indicates "work in progress", yellow is "next up" and red is "suspended").
    https://trello.com/b/XpNpScl6/particle-shaders-vol-1

    @ctp Next update should contain distance fade for Virtual Reality users.
     
    Last edited: May 9, 2015
    ctp likes this.
  10. jakehasson123

    jakehasson123

    Joined:
    May 5, 2015
    Posts:
    4
    The webdemo seems to be down. I want to give this baby a look. :)
     
  11. varfare

    varfare

    Joined:
    Feb 12, 2013
    Posts:
    227
  12. jakehasson123

    jakehasson123

    Joined:
    May 5, 2015
    Posts:
    4
    It works now. Looks great! I'm going to buy it!!
    Also:

    It is in my best interest to ask you if shadow support would be possible? I know this wouldn't be easy, but to have sunrays through the particles would look Fantastic!

    (Also point and spotlight support would be nice)

    Might I suggest adding a blur filter to the edges of the pre-rendered cutout shader? That would get rid of the nasty edges, yet still support shadows. It obviously wouldn't look good with high detail textures, but at least it would give the option for use of shadows. Just an idea. All around, LOVE THE PRODUCT!
     
    Last edited: May 9, 2015
    varfare likes this.
  13. varfare

    varfare

    Joined:
    Feb 12, 2013
    Posts:
    227
    Thank you! I really appreciate your kind words.

    About shadow receiving. I have many ideas about the future of the package. Unity have already announced receiving shadows on transparent objects that should be available somewhere during Unity 5.x cycle. But I think that I should develop my own solution anyways. Reasons for this:
    -particles are not regular "transparent" objects. They need special approach in order to be performant
    -having own solution usually gives more possibilities
    -there is no official release date for official transparent shadow receiving support

    I have created public roadmap where I'm putting all suggestions, bugs, features, you can even check what I'm currently working on and vote for most wanted feature. https://trello.com/b/XpNpScl6/particle-shaders-vol-1
    There, you can see "Better shadowing" card where I have placed few links with known, working implementations that I am considering to use with the package, like:
    http://www.roxlu.com/downloads/scholar/008.rendering.practical_particle_lighting.pdf
    http://docs.nvidia.com/cuda/samples/5_Simulations/smokeParticles/doc/smokeParticles.pdf

    But these ideas could take few month for me to implement. Transparent objects with shadow receivers were always a tricky part of realtime programming. But yea, I am definitely heading towards this direction.

    As for now, I am going to do something about these cutout shadows. One way is to implement Unity 5 transparent shadows but they are really ugly when you don't use soft shadows in your light.

    They look quite nice when you have soft shadows turned on but I cannot take for granted that everyone is using it. Soft cutout shadows is an option. I have to dig in into how exactly Unity is casting shadows and then I'll start thinking about solving the problem in the best possible way.
     
    jakehasson123 likes this.
  14. jakehasson123

    jakehasson123

    Joined:
    May 5, 2015
    Posts:
    4
    I'm really happy that you, as a developer, are taking your customers suggestions for the future product! I havn't seen too many others do that. Honestly, I like the product as it is. I've tried to achieve lit particles on my own but failed, you sir, are brilliant! And I hope your product goes a long way!
     
    varfare likes this.
  15. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,686
    I'm really not up on what can / can't be done with particles, but let's say you have rain occurring at night in a city with lots of lights (neon signs, car headlights, street lights). Can current falling rain particles be lit by a street light? My impression is they can't, and no store plugin can help. With this plugin we'd have to wait until point and spot lights are enabled before it will work.

    Is this correct?
     
  16. varfare

    varfare

    Joined:
    Feb 12, 2013
    Posts:
    227
    You are right. My package currently support one, strongest directional light. I am going to work on point&spot light support next month.
     
    blueivy likes this.
  17. blueivy

    blueivy

    Joined:
    Mar 4, 2013
    Posts:
    633
    That will probably look really awesome once supported. Can't wait! :D
     
  18. Evil_Moo

    Evil_Moo

    Joined:
    Jan 23, 2014
    Posts:
    25
    I seem to have encountered a potential issue with my particular use-case for these particles.

    I'm trying to set up particles (particularly a pale grey fog in this instance) that work seamlessly throughout a day-night cycle, but I'm finding that the ambient lighting does not update with the skybox, so the particles are still very bright at night (or dark during the day depending on the initial position of the sun). Initially the ambient lighting wasn't updating for any object in the scene, but I solved that with one massive reflection probe that only renders the skybox. However it seems that the particles don't react to the reflection probe, even when I can see that it is being detected under the 'Renderer' section of the particle system settings.

    I may be wrong, but I assume this is something that would need to be taken into account in the shader itself. Is this something you would be able to support? Is this approach to ambient lighting for particles even remotely sensible?

    I'm aware I could just update the particle colours or ambient intensity manually, but it would be a lot more convenient and likely yield better results to have the more automated solution that draws directly from the procedural skybox.

    Nice work with these assets by the way! They produce a far nicer look than the built in shaders. :)
     
  19. varfare

    varfare

    Joined:
    Feb 12, 2013
    Posts:
    227
    Hello Evil_Moo! I am happy that you like the shader pack, even though you have found some flaws.

    I have to admit that I have not tested shaders with dynamic sky, my fault. Is it possible for you to send me a sample scene with dynamic sky that you are using? Or do you have any guidelines for recreating similar system? It would really help me determining whether it is possible for me to fix this problem in a reasonable way.
     
  20. Evil_Moo

    Evil_Moo

    Joined:
    Jan 23, 2014
    Posts:
    25
    My set-up is fairly simple for the dynamic sky. I'm just using the built in procedural skybox shader with the environment lighting options in the Lighting window set to use skybox for both ambient and reflection sources, and a directional light for the sun. This will automatically update the ambient light to match the sky as you move the sun outside of runtime, but while the game is running objects seem to require a reflection probe to update ambient lighting and reflections.

    My reflection probe is set up as follows:
    ReflProbe.png

    Which is basically just making it update in realtime, while only rendering the skybox and making the size big enough to cover everything in the scene that needs the ambient lighting to update.

    Then just add a few objects (probably with the standard shader) to make sure the reflection probe is working at all and the particles to test (in my case I'm mostly using the 'Lit Alpha Blend Soft' shader). That should be everything you need to test this, as far as I can tell.

    Again, I've no idea if this is a feasible approach in general, but it looks like the simplest way to get dynamic ambient lighting from the procedural skybox at runtime.

    Thanks for taking the time to look at this.
     
  21. varfare

    varfare

    Joined:
    Feb 12, 2013
    Posts:
    227
    Thanks! I'll take a closer look at shaders in this particular light setup.
     
    Evil_Moo likes this.
  22. DrewMedina

    DrewMedina

    Joined:
    Apr 1, 2013
    Posts:
    418
    I'll buy this for sure when it supports more than directional lighting. I use points and spots for 98% of my game...
    Looks AWESOME!
    Thanks
     
    varfare likes this.
  23. varfare

    varfare

    Joined:
    Feb 12, 2013
    Posts:
    227
    After numerous tests I have found out that Unity does not support reflection probes for surface shaders with standard lighting model (non-pbr) which I'm currently using. There is no quick solution for this problem as I would have to rewrite every single shader in pure CG or utilize PBR lighting model which is not very efficient. The only workaround that I can currently think of it to use GetParticles and modify their color according to day/night cycle change.

    I think that reflection probe is the only way to go if you wan't particles which react do day/night changes. Shuriken does not support light probes and getting&setting color of every particle in the scene can be a real pain. I'll add reflection probe support to my to-do list.
     
    Evil_Moo likes this.
  24. Evil_Moo

    Evil_Moo

    Joined:
    Jan 23, 2014
    Posts:
    25
    Thanks a lot for looking into this. Sounds like an awkward issue. Unity really doesn't seem to be designed with dynamic lighting conditions in mind in a lot of ways. I look forward to seeing a solution.
     
  25. varfare

    varfare

    Joined:
    Feb 12, 2013
    Posts:
    227
    I am getting close on finishing new update. It will include reworked include files which drastically improve organisation, Distance Fade feature which allows to fade particles linearly in the given distance to camera and... a custom uber-shader inspector.


    It was getting really crazy with all these shader versions. At peak I grew from 10 shader files to 20 just because Distance Fade feature was added. Picking a right shader was really messy. Imagine a list of particle shaders with 20 items! From now on all shaders are going to use uber-shader inspector which is toggling shader keywords the same way Standard shader works inside Unity 5. It is really great because you can construct the shader you really need in few clicks and the disabled feature won't be included in shader code (performance benefits). For example: if you untoggle Distance Fade you are going to use shader variant which don't compute Distance Fade part at all.
     
    Last edited: May 25, 2015
  26. ctp

    ctp

    Joined:
    Apr 21, 2013
    Posts:
    9
    Great that you included both "start" and "end" for the distance fade function! I was missing this kind of control in a different particle shader I found a while back.
     
  27. justinl

    justinl

    Joined:
    Aug 27, 2012
    Posts:
    58
    Your web player link is broken again.
     
  28. led_bet

    led_bet

    Joined:
    May 5, 2015
    Posts:
    83
    Hi, Varfare, I'm really liking your lit particle assets. I did run into a small problem right out of the box. When I opened the example scene, I see the fire particle is rendering to the bounds of its texture:
    LitParticlesIssue.png

    Can you elaborate on how to resolve this problem?
     
  29. varfare

    varfare

    Joined:
    Feb 12, 2013
    Posts:
    227
    Could you tell me what Unity version are you using? Also, are there any warnings/errors in the console?
     
  30. led_bet

    led_bet

    Joined:
    May 5, 2015
    Posts:
    83
    There are no console messages to speak of.

    I'm using Unity 5.0.1f1
     
  31. varfare

    varfare

    Joined:
    Feb 12, 2013
    Posts:
    227
    It looks like minor bug with alpha blending tag. I'll take a look at this.
     
    led_bet likes this.
  32. led_bet

    led_bet

    Joined:
    May 5, 2015
    Posts:
    83
    Thank you!
     
  33. varfare

    varfare

    Joined:
    Feb 12, 2013
    Posts:
    227
    I have imported package from the asset store into clean, new project within Unity 5.1.0f3 and it works properly. Could you answer these questions so that I could debug it further:
    - what platform are you using (Win, Mac?)
    - what rendering path do you use
    - what is your color space
    - do you have any custom asset postprocessors

    Also, it would be nice if you could check what exact particle system is causing the problem (I assume that it's "example_emissive_big_fire" ). Thanks!
     
  34. varfare

    varfare

    Joined:
    Feb 12, 2013
    Posts:
    227
    I have sent you a PM with bugfix.

    For everyone else encountering the problem - Asset Store update should be live within few days. As for now you may contact me directly and I will send you appropriate files with bugfixes.
     
  35. justinl

    justinl

    Joined:
    Aug 27, 2012
    Posts:
    58
    I also have the same issue as ledbetterman. I've PM'd you. Thanks!

    UPDATE:
    Received. Thanks!
     
    Last edited: Jun 19, 2015
  36. varfare

    varfare

    Joined:
    Feb 12, 2013
    Posts:
    227
    Update 1.0.2 is live and ready to download on the asset store. Those of you who use DirectX11 should update the package as it fixes blending of unlit shaders.
     
  37. Stormbreaker

    Stormbreaker

    Joined:
    Aug 15, 2012
    Posts:
    161
    Bought this for the point/spot light support but just found out it's not in yet :( Hope it gets added soon.
     
  38. varfare

    varfare

    Joined:
    Feb 12, 2013
    Posts:
    227
    I am sorry that you feel disappointed in you purchase. Getting fully-lit particles in Unity is quite tricky and some features are taking a lot more time than they should. If things will work out well with uber-shader inspector and Distance Fade I should start working on more lights support next month.
     
  39. Stormbreaker

    Stormbreaker

    Joined:
    Aug 15, 2012
    Posts:
    161
    Great to hear. Out of interest, why is it so difficult to get lit-particles working? I did try to make the particles use the standard shader but they don't render correctly when in light. Does Unity treat them differently to normal objects?
     
  40. varfare

    varfare

    Joined:
    Feb 12, 2013
    Posts:
    227
    There are few major issues. The biggest one is that all particles are located in camera space and most of model-oriented lighting is done in world space. This makes all lighting calculations more complicated. You need to pass a custom Camera2World matrix from your current camera and transform all vertex informations (normals, tangents etc.) into world space. It is even more trickier with normals which have some unexpected behaviors. I am using "normal direction" factor to smooth out or roughen the normal or particles which is completely fine. It is a regular practice in most of the game engines. The bad part is - once you modify "normal direction" your normal will be stronger or weaker. If you would want to create specular particles (for blood, water etc.) your specular shininess&gloss will be modified once you change normal direction. Another common practice is to include a normal map for your diffused particles so that you can light them in more interesting way. In most cases you will use animated texture sheet. Unfortunately, Unity's "texture sheet animation" module is bugged and is modifying normals of the particle in-between frames. It looks like this:

    I have reported this issue but there was no response from Unity team just yet.

    Getting proper shadow casting and receiving requires alternating Unity's rendering pipeline which should be much easier in U5 but I have not yet digged into it.
     
  41. DrewMedina

    DrewMedina

    Joined:
    Apr 1, 2013
    Posts:
    418
    Just bought this, works really well in my exteriors! Vote for other light support someday ;) Thank you so much for soft particle support, love it!
    User Tip:
    the particle scale asset (asset store) works well with this as well, drop it on and scale the whole deal...
     
  42. TanselAltinel

    TanselAltinel

    Joined:
    Jan 7, 2015
    Posts:
    190
    I'd say instant buy, but I'll have to buy tomorrow when I am on my own PC to use credit card :)
    Edit: Bought :)
     
    Last edited: Jul 1, 2015
    varfare likes this.
  43. varfare

    varfare

    Joined:
    Feb 12, 2013
    Posts:
    227
    The news - update is almost finished. Shader-related stuff is completed. I've cleaned the code, added few include files for shader functions, variables and lighting functions. I've reduced number of shader files from 30 to 2. Everything is based on shader_feature so you can toggle on/off code portions. Distance Fade is working as expected. The only issue I have is material inspector itself but it's not a major problem.

    The downside of shader file reduction is that you will need to re-assign all your materials. Also, Distance Fade feature requires you to attach script to your main camera. This script sends _Camera2World matrix to particle shaders which is needed for proper particle->world transformation. It works properly with multi-camera setup and scene view camera.
     
  44. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,686
    Lighting is still restricted though, right?
     
  45. monoRAIL

    monoRAIL

    Joined:
    May 22, 2010
    Posts:
    9
    +1 for point light support, that's all I need for my project. I'll buy this once point lights work.
     
    Stormbreaker likes this.
  46. varfare

    varfare

    Joined:
    Feb 12, 2013
    Posts:
    227
    Yes. As I said - it will come in the next update (the one after Distance Fade ).
     
    hopeful likes this.
  47. Ekta-Mehta-D

    Ekta-Mehta-D

    Joined:
    Feb 25, 2013
    Posts:
    24
    hii .. its not working with mobile device.
     
  48. varfare

    varfare

    Joined:
    Feb 12, 2013
    Posts:
    227
    Hi.

    Could you answer these questions so I could track down what's going on?
    - what exactly is happening (it does not show at all, rendering looks wrong, there are issues with the shadows, etc.)
    - on which device you tested it?
    - what OS is installed on your device
    - could you send me some screenshots and/or a video?
    - are there any errors/warnings in the log file of your project that might come from the package?
     
    Ekta-Mehta-D likes this.
  49. Ekta-Mehta-D

    Ekta-Mehta-D

    Joined:
    Feb 25, 2013
    Posts:
    24
    I am using windows 8 and Unity 5. Particle are not rendering in android device. well as its working in unity editor.
     
  50. varfare

    varfare

    Joined:
    Feb 12, 2013
    Posts:
    227
    I have submitted package update for review so it should be live within days. New (1.1.0) version changelog:
    - Distance Fade feature
    - uber-shader inspector
    - rewritten code base
    - new free texture
    - updated documentation

    Updated package is using pixel/vertex shader 2.0 (previous versions were using 3.0) so you might want to check it out. Could you also tell me what exact device you are using?