Search Unity

  1. The 2022.1 beta is now available for testing. To find out what's new, have a look at our 2022.1 beta blog post.
    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
    Making Progress on my demo scenes but my lack of 3D modeling skills is starting to hold me back and i don't think I am allowed to use any free art assets off the unity store in anything i sell to the public which makes things difficult. I sent out a couple of emails to get permission to use the rock and plane assets above but haven't received any replies yet :(.

    hard object demonstration using emissive + my normal mapped particles. I'm aiming for a Tron/space invaders feel. haven't made a cutout version of my shader yet but i think i might in the future.


    Multi light demonstration with street light and lightning.
    I'm Going to add card driving past to complete the effect.
     
  2. MikeUpchat

    MikeUpchat

    Joined:
    Sep 24, 2010
    Posts:
    1,034
    Looking great, would love to get your smoke into this system and have a car driving through steam on a city street.
     
    jack-riddell and John-G like this.
  3. caladluin

    caladluin

    Joined:
    Jan 29, 2014
    Posts:
    24
    This looks really awesome!
     
  4. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    having trouble with soft particles in orthographic view, might have to disable it for orthographic
     
  5. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    so unitys built in soft particles don't work in an isometric view, in the future i might try and build a shader that does soft particles in isometric but it wont be in the first release
     
  6. Nyt0x

    Nyt0x

    Joined:
    Feb 3, 2014
    Posts:
    18
    And shadows are also disabled, due to an optimisation choice they made on how they fill the depth buffer (in ortho view your depth buffer represent something linear so you can't easily "compresse" the depth info without loosing precision, especially when you're trying to render for a large z (depth) distance so you can't use non-linear depth representation.)
     
  7. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    While waiting on some things for the release of Advanced normal mapped shaders i started work on a mobile version using GLSL. here is a test of some back lighting features I wanted to include in my first release but couldn't.
     
    Haagndaaz and manpower13 like this.
  8. FPires

    FPires

    Joined:
    Jan 5, 2012
    Posts:
    151
    I'm really interested in this product. I've recently started experimenting with generating procedural smoke and cloud textures:

    https://filterforge.com/filters/13772.html



    Really anxious to try some of my own particles with your system and see how it holds. Looking great so far.
     
  9. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    So while I'm waiting for my non mobile version of my shader to go live I have been working on an iPhone compatible version but unfortunately i don't have a Mac or a low end iPhone to test some of the shader features on so I'm wondering if anyone here has a developer account with apple and an iPhone 4s or lower who is willing to test a couple of shaders for me?
     
  10. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    750
    Nice lighting effect! Which shader do you use to get the translucency?
     
  11. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
  12. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,407
    Purchased :) Looking forward to testing it out.
     
    jack-riddell likes this.
  13. John-G

    John-G

    Joined:
    Mar 21, 2013
    Posts:
    1,114
    Oh wow, that was unexpected. Purchased it snappy, cant wait to see it in action.

    Edit :
    Have a small bug, copied the drain smoke from the included scene and duplicated it.
    A soon as the second copy was created neither smoke system was visible, if I deactivate one of the then the other one becomes visible.
    Also noticed while both are activated and not visible, if I pan the camera around they both become visible for an instant flickering between visible and invisible.
     
    Last edited: Apr 27, 2016
    jack-riddell likes this.
  14. Obsurveyor

    Obsurveyor

    Joined:
    Nov 22, 2012
    Posts:
    277
    So does the version on the store have the shadows that you were showing way back when?
     
    Petter_G and Arkade like this.
  15. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,440
    @jack riddell - Will this work for rain particles in a night time urban scene? If so, that would be a great application.
     
    jack-riddell likes this.
  16. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    it will but it is limited to 4 lights per mesh/particle system so if your rain consists of one big particle system it might have problems but if your rain is made up of several smaller particle systems then you shouldn't have a problem.

    the rain in the drain smoke scene is using my normal mapped particle shader
     
    Last edited: Apr 28, 2016
    hopeful likes this.
  17. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    god dam it unity the least you could do is send me an email before going live with my stuff.
    anyway thanks for everyone's support i couldn't have done it without you having people to bounce ideas off makes a big difference.
    This isn't the end for this project i still have a lot of stuff i want to do to it so stay tuned.
     
    Prodigga likes this.
  18. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    sounds like it might be a draw order issue. unity has some wonky draw order issues with in development shaders ill look into fixing it. are you having any other errors?

    also if its not to much hassle can people rate and review my package when they can it makes a big difference.
     
    John-G likes this.
  19. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    no unfortunately this version does not have the smoke on smoke shadows and the smoke on ground shadowing is disabled due to conflicts with the latest versions of unity. I am still working on getting the more advanced smoke system in to unity but i want it working good before i add it to the store.
     
  20. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,441
    seems to be broken on openglcore: all particles in all demo scenes are simply black.
    or do i miss something?
     
  21. John-G

    John-G

    Joined:
    Mar 21, 2013
    Posts:
    1,114
    No other errors, all working OK regards shadows and lighting. Really makes a difference to the look of my particles.
    Will post a review shortly.
     
    jack-riddell and Prodigga like this.
  22. Arkade

    Arkade

    Joined:
    Oct 11, 2012
    Posts:
    643
    Congrats!

    So this thread jumped to my attention due to the self-shadowing stuff. What is the probability and estimated timeline for the current version to get those features, please?
     
  23. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    ok so my current dev plan is this

    1 make current release bug free

    2 make mobile release with back lighting

    3 release mobile version

    4 incorporate back lighting into non mobile version

    5 add normal mapping to volumetric lighting (big job)

    6 release volumetric lighting with only directional light support

    7 start work on a deferred particle lighting solution

    8 add volumetric lighting to deferred lighting solution

    9 release deffered lighting solution

    10 hopefully mad profit

    all these things take time and if i get a job wont happen quickly. on top of that I am not sure what unity is doing particle wise so they might sweep in and under cut me at any second. at a guess i would say 6 months before self shadowing is released in any form but who knows. if my current package makes enough money for me to live off it while i work on the volumetrics then i can get stuff done quickly but if i have to get a job to keep the lights on then that will slow me down a lot.
     
    Seneral and John-G like this.
  24. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,441
    but is openglcore broken or do i do something wrong?
    anybody else here having any issues using openglcore?
     
  25. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    can you give me any more details on whats happening and how its broken?
     
  26. HakJak

    HakJak

    Joined:
    Dec 2, 2014
    Posts:
    189
    Yes! The most annoying thing about the particle system by far.
     
  27. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,441
    particles are simply black: no lighting at all.

    Unity 5.3.3.F1:

    Bildschirmfoto 2016-04-30 um 13.39.23.png
     
  28. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    and it doesn't do this in any other rendering mode? I'm looking into it now, hope to have an answer to you in 24 hours.
     
  29. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,441
    os x, so i do not have any other api...
     
  30. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    ok i found the error and am working on a solution but that might take a couple of days to make it through the asset store certification process. For a temporary quick fix at line 55 in NormalMappedShader in the shader folder it has the text
    "#define CALC_ATTENUATION_USING_LOOKUP"
    just add "//" in front of it to comment it out (the line should turn green once you do that) and the smoke lighting will start working.

    For those of you wondering what the error is, to calculate the light falloff in unity they use a lookup texture called _LightTextureB0.

    in direct x the lookup texture looks like this with the light falloff in the red channel
    LightFalloffDirectX.png
    however for some unknown and undocumented reason in opengl the texture looks like this with the lighting lookup value to the alpha channel
    LightFalloffOpenGL.png
    and that is what was causing the lighting problems.

    by commenting out "#define CALC_ATTENUATION_USING_LOOKUP" you turn off using lookup texture for the lighting and instead use slower less accurate code i have written for mobile platforms to manually calculate the falloff. you might notice your particles being slightly brighter towards the center of the light source than the surrounding unity geometry.
     
    Seneral likes this.
  31. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    an updated version of the package with the opengl fix is pending review and should be live shortly, sorry for any inconvenience this error has caused.
    If you have any trouble feel free to post it here or contact me via email at encapgamedevelopment+anmphelp@gmail.com and i will get on it as soon as i can.
     
  32. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    On thing that i have found missing from a lot of shaders on the unity store is good optimization.
    The picture below is of two shaders i have been working on.
    The smoke on the right is not optimized and does a lot of complex calculations in the pixel shader which runs hundreds of times per particle depending on how big the smoke is.
    The smoke on the left is optimized and does most of the lighting calculations like light direction and light intensity in the vertex shader which runs a fixed 4 times per render.
    Optimisation.png
    (left optimized, right unoptimized)

    The optimized smoke is almost 4 times faster than the unoptimized smoke running only 10 to 16 percent slower when rendering 4 lights as the unoptimized smoke rendering 1 light.

    The current Advanced normal mapped particle shader package is fully optimized like the shader on the left but with my work on a new mobile shader i thought i would try adding light scatter for light traveling through the smoke.
    Optimisation2.png
    (left unoptimized, right optimized)

    unfortunately light scattering requires much more accurate lighting calculations and in this world you get nothing for free.
    at a distance the smoke looks almost identical but when you get close the inaccuracy inherent in per vertex calculations become apparent.

    Optimisation3.png
    (unoptimized smoke)

    Optimisation4.png
    (optimized smoke)

    The issue lies with how graphic cards interpolates the values calculated in the vertex shader and passes them to the pixel shader.
    Graphics cards linearly lerp the values when passing data from the vertex of a triangle to the pixels inside the triangle, this works fine for most things but with vector distances and directions it can cause the vector to change length and not accurately represent the data its meant to.

    Optimisation5.png
    (top = per pixel, bottom = per vertex)

    The differences in length throws out all the lighting calculations and result in the darkness you see in the above light scattering.
    In my next release I plan on releasing an optimized and unoptimized version so if people really need the quality regardless of the cost they can opt for the slower version.
     
    Last edited: May 2, 2016
    Seneral, manpower13, Seith and 3 others like this.
  33. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    Re wrote unity's soft particle system today to be more efficient and work better with my existing framework.
    I optimized it by shifting more of the calculation to the vertex shader and away from the fragment shader reducing the amount of data that needed to be passed between the two.
    Shader model 2.0 (what old iPhone's use) has a limit of 8 variables containing a maximum of 4 values that can be passed between the vertex and fragment shader.

    In my current shader:
    Texture UV takes up 1 spot.
    Particle colour/transparency takes up 1 spot.
    Direction from the particle to the camera (used for back scatter) takes up 1 spot.
    Fog takes up 1 spot.
    Soft particle factor takes up 1 spot.
    Lighting takes up 4 spots (1 per light).
    making a grand total of 9 variables being passed from the vertex to the fragment shader (not good).
    by rewriting the soft particles i squeezed the variables into 2 float values instead of 4 which will allow me to pack another variable like fog in with it which reduces the total number of variables used down to 8.

    SoftParticles.png
    all this optimization is not free though. If you look carefully at the image you can see a couple of tiny white pixels around the edge of the box, that's caused by the inaccuracy of doing things on the vertex. the errors only show up when an object is inside or just in front of the smoke so I'm hoping this small graphical glitch is worth the speedup in performance but if it isn't I have a plan to fix it.
     
    Seneral likes this.
  34. Obsurveyor

    Obsurveyor

    Joined:
    Nov 22, 2012
    Posts:
    277
    Make sure to test it with a good bloom filter. Sometimes those white pixel artifacts end up being really bright and bloom when they shouldn't.
     
  35. IronDuke

    IronDuke

    Joined:
    May 13, 2014
    Posts:
    132
    The way you dropped this so casually in passing brought a guffaw from me.
    "Oh yes, I reprogrammed soft particles in one day 'cause I didn't like the way they worked... no big deal."
    :D
    Keep it up!

    --IronDuke
     
  36. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    good idea i didn't think of that.
     
  37. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    The fix to the openglcore issues has finally been accepted onto the store. update to the latest version to get the best particles on all platforms!
     
  38. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    so it turns out the built in unity soft particle system has the exact same problems as my replacement.

    (unity soft particles)
    SoftParticles2.png

    (My soft particles)
    SoftParticles3.png

    whats more my solutions is actually better when objects are in front of the smoke

    (unity soft particles)
    SoftParticles4.png

    (My soft particles)
    SoftParticles5.png

    my guess is its being caused by the anti aliasing. Knowing that unity has the same faults fills me with confidence because if it hasn't caused problems for unity then it shouldn't cause any problems for me.
     
    Seneral and John-G like this.
  39. John-G

    John-G

    Joined:
    Mar 21, 2013
    Posts:
    1,114
    Excellent,
     
  40. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    Making progress on my mobile version of the shader, just added mapped emissive lighting.
    With standard emissive the entire particle is lit evenly, with mapped emissive a texture holds where to apply the emissive and how much emissive to use allowing you to selectively light your particles.
    in the example below I am using the mapped emissive to dissolve the flame effect of the particle over time creating the effect of the smoke swallowing the flame.
    MappedEmissiveNormalMappedParticels.gif
    I'm still perfecting my blender smoke sim skills, I know the shader can create much more beautiful effects but my particle texture art is the big thing holding it back at the moment :(
     
    Last edited: May 7, 2016
    Martin_H, ElectroMantis and Seneral like this.
  41. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    So with a small addition to my shader (emissive multiplyer) and a few small changes to my emitter I managed to make my smoke fire combination look a lot better. The effect below is all one particle effect not several effects stacked on top of each other like most particle effects. Using multiple particle effects causes popping and incorrect ordering especially when used in sub emitters or in large groups.

    I also made a small script that kills a percent of particles based off how old the particle is and an animation curve.

    with unitys built in particle system you don't have good control over the percent of particles that remain over time.
    If you set a percent of particles to have a shorter life than the others then they grow to their final size to quickly and mess up the effect but if you leave all the particles to have the same life time you get the problems illustrated in the image below.

    close to the emitter the particles are smaller so you need more of them to make the smoke seem solid and consistent.
    towards the end of the particle effect the particles are quite large so you need fewer of them.
    If you have to many particles at the tail end of the smoke you loose the fluffy shape of the particles and the smoke just turned into a grey cone.
    ParticleCount1.png
    blue area = to few particles
    red area = to many particles

    my particle kill script allows me to control the number of particles alive at any point along the effect this allows me to get a more even coverage of particles like what is shown below.

    ParticleCount2.png

    I intend to include the particle kill script with the ANMP package in the next update and any other packages i put together but that might take a while so if you want it now message me and ill send you a drop box link.
     
    Arkade, Martin_H, John-G and 4 others like this.
  42. TheEndersWAR

    TheEndersWAR

    Joined:
    Jan 8, 2015
    Posts:
    58
    @jack riddell how can I contact you by email, I wanna discuss a some stuff''
     
  43. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    Getting a bit better at making smoke renders but still cant get the fire smoke combination to look 100 percent right. experimented with some spark particles, I like them but i think they would work better in a higher frame rate texture/sprite sheet.
    SparksAndFire.png

     
    Martin_H, giraffe1, eskovas and 2 others like this.
  44. Lahzar

    Lahzar

    Joined:
    May 6, 2013
    Posts:
    87
    I just have to say this looks absolutely amazing!
    I was really surprised by the price tag, I was expecting something around the $100 mark, not $20. Definitely worth purchasing. Good job, man!
     
  45. John-G

    John-G

    Joined:
    Mar 21, 2013
    Posts:
    1,114
    Nice, the glowing embers really add to the look.
     
  46. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    thanks for support, if you could rate or review my asset that would be a huge help because it still doesn't have enough reviews to get a star rating.
     
    Lahzar likes this.
  47. giraffe1

    giraffe1

    Joined:
    Nov 1, 2014
    Posts:
    248
    Will this be included in the current asset when you are content with it? Or is this seperate add-on for the future?
     
  48. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    I am making a mobile version of the asset which will include this along with a few other examples.
    Once the mobile version is out I plan on updating the non mobile version to include the new emissive and light scattering features and include that smoke with that package as well but that's still a while off.
     
  49. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    Final smoke test
     
    Arkade, Seneral and hopeful like this.
  50. TheEndersWAR

    TheEndersWAR

    Joined:
    Jan 8, 2015
    Posts:
    58
    Nice, those the smoke work with unitys fog?
     
unityunity