Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Unity 2022.2 is now available as the latest Tech release.
    Dismiss Notice
  3. We are making some changes to the DOTS forums.
    Dismiss Notice
  4. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Volumetric Smoke Shader

Discussion in 'Works In Progress - Archive' started by jack-riddell, Sep 30, 2015.

  1. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    ----------------------------------------------------- EDIT -----------------------------------------------------------

    As part of the Volumetric particle lighting project I have created a stand alone Asset available on the asset store called Advanced Normal Mapped Particles which is available here
    https://www.assetstore.unity3d.com/en/#!/content/60561 . the later posts in this thread mostly discuss this asset.


















    ----------------------------------------------------- END EDIT ------------------------------------------------------


    Hi i was not impressed with the current lighting solution for particle systems so i am working on integrating volumetric lighting into the particle lighting solution. here is my progress so far.

    left is my solution right is the current unity particle effects using the same texture
    Wip Smoke Shader11.png

    i have added shadowing but it still has some visual artifacts that need improving
    Wip Smoke Shader8.png
    the lighting looks good from most angles providing the particle sorting is working correctly
    Wip Smoke Shader9.png
    particle effects can cast shadows on each other as well
    Wip Smoke Shader10.png

    it is still in the prototype stage and my artwork does not really do the effect much justice. if you have any suggestions / requests I am all ears
     
    Last edited: Jun 7, 2016
    Lex4art, Gametyme, lostframe and 17 others like this.
  2. Haagndaaz

    Haagndaaz

    Joined:
    Feb 20, 2013
    Posts:
    232
    Very interested in this. What method of volumetric lighting are you using?
     
    Arkade likes this.
  3. Arkade

    Arkade

    Joined:
    Oct 11, 2012
    Posts:
    650
    This, and what requirements and performance implications, please?
    (It looks very pretty!)
     
  4. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    requirements are direct x 9 hardware so no ios or droids unfortunately as for performance i haven't done any benchmarks yet but its going to be somewhat expensive. there are a lot of ways i can trade quality for performance though so i think i can get it running on lower end systems
     
    StevenP94 likes this.
  5. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    4,420
    Looks promising! I'm watching this thread. Does it also work with animated sprite sheet particles?
     
  6. DxStd_IgnatPribylov

    DxStd_IgnatPribylov

    Joined:
    Sep 24, 2015
    Posts:
    30
    Speaker! We want to see it in action.
     
    Martin_H likes this.
  7. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    Animated sprite sheets should work fine, elongated sprites,mesh particles , trails and just plain meshes should also work fine with my current setup, the only limitation at the moment is that it only works with one directional light no spotlights or point lights but i plan on changing that in the future. at the moment I'm stripping out all the code and reorganizing it so i can build one mega shader with optional graphics setting so i don't end up with 20 shader variations but when that's done ill build some new test beds to show it off. Speaking of test beds What sort of environments / game styles would people like to use this in?
     
  8. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I'd be interested in this. Basically anywhere in any normal game where alpha particles need to be affected by shadow. That's IMHO all 3D games.
     
    QFSW, ElectroMantis, HakJak and 2 others like this.
  9. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    i should clarify my current solution only receives shadows from transparent objects at the moment it does not receive shadows from hard objects ( causes graphical glitches ) but im working on a solution to this that has reasonable performance
     
    Martin_H likes this.
  10. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    AFAIK there's a method in 5.2 that allows you to sample the shadow buffer quicker for post fx etc. Since this is a transparent pass it can be utilised.
     
  11. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    thanks man ill check it out. any idea what its called?
     
  12. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Sorry, it's in 5.3 so if you're not a pro user you won't be able to access it at the moment.
    • Graphics: CommandBuffer.SetShadowSamplingMode() can be used to enable sampling raw depth value from shadowmaps, to be copied or post-processed by user effects.
    I'm not actually sure, I go through so many alphas and betas. The best thing to do is keep a close eye on the release notes for 5.2 and 5.3. Think there's another similar one too.
     
    Arkade and Martin_H like this.
  13. eskovas

    eskovas

    Joined:
    Dec 2, 2009
    Posts:
    1,373
    Very interesting indeed :D

    Like @hippocoder said, having particles being affected by shadows from opaque objects is a must in basically all 3D games. Would be really nice if you could implement that into this!
     
    Martin_H likes this.
  14. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    4,420
    I've seen in some slides about "Uncharted" graphics, that they recommend only having SSAO in the shadow areas. With this new feature maybe someone could implement that as an option into the default SSAO effect? Maybe as a blend parameter between full AO and no AO in the directly lit parts?
     
  15. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    its easy enough to dump in shadows, only 1 or 2 lines of shader code but the performance hit can be quite harsh. the average pixel in a scene without transparency will require 10 to 20 texture lookups if you have a particle effect with 20 to 30 particles stacked on top of each other without shadows its still only one texture lookup per particle so around the 40 - 60 mark but if you add in a pcf5 shadow lookup it increases the cost 5 fold which is not good
     
    Arkade, Martin_H and eskovas like this.
  16. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    Made some more changes to the code, now you will have the option of doing the expensive light calculations per pixel or per vertex depending on the level of fidelity you need.

    Using per vertex lighting removes a lot of the fine details especially when looking up through the smoke towards the light but should dramatically reduce the overall cost especially with large particles that fill the camera. I'm planning on adding normal mapping of some kind to add back in the details that are being lost by the per vertex calculations.

    Per Pixel
    Wip Smoke Shader13.png
    Per Vertex
    Wip Smoke Shader14.png

    do you have any suggestions or ideas for any future features / requirements?
     
    Arkade likes this.
  17. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Speed is nice, it's pretty much the only thing I need except for being able to darken particles in shadow, but probes might help there as it doesn't really need per pixel accuracy? :)
     
  18. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    at the moment probes are only sampled in the center of the mesh which is not very useful. I'm going to do some tests with doing per vertex shadowing but that probably will result in nasty popping artifacts :(
     
  19. Alabatross

    Alabatross

    Joined:
    Dec 15, 2012
    Posts:
    223
    Martin_H likes this.
  20. BigB

    BigB

    Joined:
    Oct 16, 2008
    Posts:
    669
    I'm quite interested in this , but with pointlights and or spotlights :)
     
  21. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    half angle rendering (which is what the video shows) is cool and all but it only works in direct x 11 and I'm not sure it works with transparent meshes or any other media. I have only ever seen half angle rendering done with thousands of small particles with one directional light. The system im working on is the same system that unreal uses so that should give you an idea of the quality and flexibility that it can achieve.

    Adding point and spot as we speak but I'm not sure it will make the initial package
     
  22. Alabatross

    Alabatross

    Joined:
    Dec 15, 2012
    Posts:
    223
    Oh, I had pm'd him asking if it ran on dx9 and he said it does, and it isn't entirely based on the nvidia article apparently
     
  23. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    if he is doing it how i think he is doing it (rendering the smoke effect multiple times with changing near and far clipping planes) i don't have high hopes for performance or flexibility but i could be wrong
     
  24. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    Having some trouble profiling my smoke system because my graphics card is to fast my shader is to efficient and my cpu is to slow :( . i did manage to come across this interesting bug with the shuriken particle sorting though.


    Smoke Sort Errors.png
     
    SAOTA likes this.
  25. Alabatross

    Alabatross

    Joined:
    Dec 15, 2012
    Posts:
    223
    Ah well he left the stats window up during the video, seems pretty fast to me. Either way he said it won't be coming to the asset store, so I'm looking forward to yours, you guys are probably doing it very similarly and don't realize



    And at your bug that's actually known: http://forum.unity3d.com/threads/particle-system-distance-sorting-doesnt-work.358794/

    Oh lol you posted in it :p
     
    Last edited: Oct 7, 2015
  26. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    there is only a few volumetric particle setups that run at a reasonable frame and with the level of flexibility you need for a game so i am quite interested in how he is doing that effect and what the trade offs are.
     
  27. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    Work is progressing , i now have per vertex shadows, normal effected lighting and a rough idea of performance and its looking good.

    performance is looking between double and triple the cost of stock alpha blend particles depending on weather your using per vertex or per pixel blending.
    Wip Smoke Shader15.png

    per vert shadows work better than i was expecting but it will add a scene complexity dependent overhead in the form of a custom depth pass which isn't amazing but was the only way to get the light visibility data into the vert shader. Wip Smoke Shader16.png

    So I'm starting to plan out all the features for the first release of this package.
    My plan is to release with only 1 directional light supported and add additional features like point and spot lights as time goes on.
    I know other particle shaders support a lot more light styles but trying to keep performance good while adding volumetrics isn't easy!
    Hopefully the package will take off and i can add support for multiple lights and light styles.
     
    hippocoder, elbows, Martin_H and 2 others like this.
  28. Alabatross

    Alabatross

    Joined:
    Dec 15, 2012
    Posts:
    223
    That last picture looks nice, do you have a video or gif of it?
     
  29. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    I'm in the middle of porting the shadows over to the per pixel lighting version of my shader but once that's done ill try and get a gif together.
     
  30. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    Shadow Tests
    SmokeShadowsTest.gif


    SmokeShadowsTest3.gif
     
    elbows likes this.
  31. Alabatross

    Alabatross

    Joined:
    Dec 15, 2012
    Posts:
    223
    are those per pixel or vert
     
  32. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    4,420
    That's great progress! I see a bit of flickering in the top image where the block enters the smoke. Could you please keep an eye on how that testcase plays out with more complex models? E.g. smoke emitted from a window of a building that casts a shadow on the smoke. Also do the particles support soft blending? What about ambient light? Since that doesn't need shadow-casting I hope it's not hard to implement (if it isn't already). I'm asking about it because I usually try to get a realistic light setup with 1 warm directional light for the sun and a cool ambient light so that the shadows turn blue-ish.

    Keep up the great work!
     
  33. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    those are per pixel lighting with per vertex shadows which works ok with small particles but can cause flickering artifacts with large particles.

    customisable ambient light is in but it is per particle effect not per scene and not per light probe. I am planing on adding some kind of light probe support in the future but i want to get something out the door soon instead of this turning into vaperware like many other unity tec demos. Soft particles are not implemented yet but it is something on the wish list along with mult light support and many other things.

    unfortunately graphical artifacts are somewhat unavoidable with particle effects especially with any volumetric effects due to the number of shortcuts that need to be taken to make things run fast enough :( i will try to keep things running as artifact free as possible but don't expect things to be 100 percent true to life.

    if you have any specific use cases please tell me so i have something to bench mark against. at the moment my smoke effects are targeting a mostly outdoor environment that is exposed to the directional light of the sun ( or any other large directional light source) and is occasionally occluded by large objects like buildings or bridges.
     
    Martin_H likes this.
  34. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    Dithered particle Soft Shadows and particles casting shadows on each other
    SmokeShadowsTest5.gif SmokeShadowsTest4.gif
     
    SunnyChow, Lex4art and Martin_H like this.
  35. BigB

    BigB

    Joined:
    Oct 16, 2008
    Posts:
    669
    This is looking great, but please, point and spot light support :) , or at least point light
     
  36. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    the problem with point and spot lights is that you will almost always want more than 1 in your scene which means i will need a system for tracking which lights are effecting what smoke system and detect when they get turned off and on or go out of view. As soon as you go down the multi light path you end up rebuilding unity's lighting pipeline. i do have big plans for my next version of this asset with mobile support and multiple lights but for this version its going to be single directional light unfortunately.
     
  37. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    so for a while now i have been annoyed by the quality of the lighting and finally today i found the bug that was causing all the problems. The good news is the bug was easy to fix but the bad news is it has exposed a bunch of other problems i will need to solve :( .

    here is a pic before i fixed the bug
    Wip Smoke Shader18.png


    Same scene post bug fix.
    Wip Smoke Shader17.png
     
    GameTechnix likes this.
  38. BigB

    BigB

    Joined:
    Oct 16, 2008
    Posts:
    669
    How about just getting the smoke inside a trigger, and lights inside that trigger will go into account.
    Or, just a maximum of 2 lights (the closest ones).
    You don't need to make this for 100 lights, that would be insane, we can work around the limitations.
    I was saying either pointlights or spotlights, because well, I'm working on an indoor game, and this would look great in there :)
     
  39. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    whats the time frame for your game? if your release date is 6 months or more away i should have a version done by then that works indoors with hopefully a lot more lights / functionality. i am planing a mobile friendly version of this package that should support up to hundreds of lights with some form of volumetrics plus a bunch of other goodies :)
     
  40. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    Fine for me. Release it ASAP. :cool:;)
     
  41. BigB

    BigB

    Joined:
    Oct 16, 2008
    Posts:
    669
    Yeah, it's in about 6 months yup.
     
  42. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    Ill do my best to get a version up that can do what you want by then but i can't make any promises.
     
  43. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    made using the latest version of code for the first release.
    still a few tweaks left but definitely close.
    SmokeShadowsTest7.gif
     
    Seneral, John-G, chiapet1021 and 6 others like this.
  44. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    from a different angle
    SmokeShadowsTest8.gif
     
  45. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Night and day, pun intended! very nice work. Rendering depth again shouldn't be required for transparent pass (it should be there at that point) so I assume you're reading unity's depth buffer into vertex? that's not really that expensive for one texture. Really great work. The difference to the eye is far more natural!
     
  46. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    at the moment i am re rendering depth unfortunately.
    my shadow casting code was conflicting with my shadow receiving code and the shadow buffer is harder to get / not as well documented as you would expect. fortunately Im already doing a depth pass of sorts to get the bounds of all the particle effects so tacking on a low resolution depth pass was not to hard but i do want to change it in the future. as a side effect the low res of the depth pass is giving me softish edges on the shadows which helps hide the popping from the per vertex lighting. still a long way to go but if this package sells ok i have bigish plans for the future.
     
    Martin_H likes this.
  47. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    4,420
    Impressive results so far!
    I still see a seam where the shadow cast by the smoke is a bit lighter than the other cast shadows. Is that a tweakable setting/by design/by limitation? I think it would look better if they would be the same intensity and color and not have that visible seam. It might be correct that the smoke isn't a 100% light blocking volume, but I would assume the real world comparison to be a smoother transition. I haven't searched for a refence though. If there is room for changes and you are interested I can see if I can find a good ref.
     
  48. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    I am dithering the shadows to add a level of transparent support but i still need to do some tweaks.

    SmokeShadowsTest9.gif
     
    Martin_H and hippocoder like this.
  49. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I expect the shaders need to be specific somehow, are they easily modifiable?
     
  50. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,683
    sorry maybe this is really of topic. Now i'm really curious how other engine render their particle shadows or any semitransparent shadows because it seems that they didn't use any dithering at all for their transparent shadows