Search Unity

Volumetric Smoke Shader

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

  1. yc960

    yc960

    Joined:
    Apr 30, 2015
    Posts:
    228
    the default unity water is planar I think, but I do know that they reflect alpha effects. Default alpha unity shaders are reflected, so I was a bit surprised that this one is not.
     
  2. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    I may have incorrectly set a flag or something. I am in the process of porting lit smoke and fire over to direct x so i will try and fix it in the process
     
    Martin_H likes this.
  3. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    Ok i have ported almost all the shaders across to direct x / unity 5.5. all that's left is to package them up and release them.
     
    yc960 likes this.
  4. yc960

    yc960

    Joined:
    Apr 30, 2015
    Posts:
    228
    would also like some docs on how to use the shaders to its fullest potential, recommended settings and senarios as well as some example to show the best practices.
     
  5. yc960

    yc960

    Joined:
    Apr 30, 2015
    Posts:
    228
    I am currently using the volumetric light http://hitboxteam.com/HxVolumetricLighting/ . it supports transparency but need shaders to be adjusted according to the docs.

    Can you provide a compatible version of your shaders? My limited shader knowledge prevents me from doing this myself.
     
  6. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    I had a quick look at the docs for the package and it looks easy enough to add the fix but i would need to buy the volumetric lighting package in order to test the added code and unless there is a few people who would use this feature it does not make sense financially for me to do that. I make 25$ off each purchase, for me to then spend 40$ to buy the lighting package plus an additional 60$ worth of man hours fixing, debugging and uploading the code would only make sense if i make at least an additional 4 to 5 sales.
    I wish I had infinite time and money to help everyone but I don't so I need to worry about making enough money to keep food on the table and a roof over my head.
    I might reach out to the guys building the volumetric lighting solution and see if they want to do a cross promotion which would be the only business case that makes sense but I wouldn't hold your breath.
     
    Martin_H and yc960 like this.
  7. yc960

    yc960

    Joined:
    Apr 30, 2015
    Posts:
    228
    no problem, thanks for the consideration anyways. Guess I gotta learn shader codes.
     
  8. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,007
    Based on what I've picked up over the years, I think a fair number of devs do asset trades, esp. for the purpose of extending compatibility.
     
    Martin_H likes this.
  9. yc960

    yc960

    Joined:
    Apr 30, 2015
    Posts:
    228
    the new 5.5 beta seems to expose many info in the particle system including UV info, would this be helpful doing something like a fade in or lerp between texture sheet animation frames to avoid the jarring look?
     
  10. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    already in lit smoke and fire under frame blending and the next update makes it 5.5 compatible.
     
    yc960 likes this.
  11. Little_Gorilla

    Little_Gorilla

    Joined:
    Oct 11, 2013
    Posts:
    69
    Sent an email, but haven't heard back yet so posting here!
    I bought Advanced Normal Mapped Particles and it works well, but I am really digging the combined fire and smoke effect in your Lit Smoke and Fire asset as shown in the web demo here (https://riddellriddell.itch.io/lit-smoke-and-fire):


    I can't seem to find a similar effect in the Advanced asset, do I need to download the Lit Smoke asset for this one?
     
  12. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    I sent back a reply on the same day you emailed me but it might have gotten lost in spam.
     
  13. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    Current progress on my next release. I have switched over to a new format for storing the lighting information and the results so far look good. The new format combines the normal map , occlusion map , emissive map and transparency map all into one texture (packing 8 floats into 4 floats is a nightmare). To render the new texture format I have made a new shader that fixes a few of the bottlenecks on mobile platforms specifically the number of values being passed from the vertex to the fragment.
    Another advantage of the new shader is that it can handle 8 lights plus ambient lighting when i hack it in with almost no extra cost.

    The shader also has improved emissive lighting control. With Lit Smoke And Fire the emissive lighting colour was made by overdriving a single colour and using low dynamic range to force the shader to create different colours. With this new package I am experimenting with a 1D lookup texture to select the emissive lighting. A texture lookup adds a lot more colour control and more intuitive production pipeline but it will come with a performance cost which I need to profile before I commit to it.

    Unfortunately the new format is completely incompatible with both lit smoke and fire as well as Advanced normal mapped particles so i am splitting it off into a new yet to be named package.

    for some reason gif embedding seems broken

    http://i.imgur.com/1XSvCAz.gif

     
    Last edited: Nov 9, 2016
    Little_Gorilla and yc960 like this.
  14. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    I sent another email with everything i have sent you so far
     
  15. Little_Gorilla

    Little_Gorilla

    Joined:
    Oct 11, 2013
    Posts:
    69
    Thanks for that, but unfortunately I'm still not receiving anything and there's nothing in spam :(
    Are you able to post the reply here?
     
  16. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
  17. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    I added HDR support in the form of an emissive brightness multiplier so now bloom has the correct colour and intensity.

    TriAxisFire4HDR.gif

    Once i have made enough progress and artwork I am going to split this asset off into its own thread just like lit smoke and fire.
     
  18. StaffanEk

    StaffanEk

    Joined:
    Jul 13, 2012
    Posts:
    380
    Wait a minute. You are splitting of the same functionality into three different paid assets?
     
    Last edited: Nov 12, 2016
  19. yc960

    yc960

    Joined:
    Apr 30, 2015
    Posts:
    228
    Great work, what is the improvement/features for this one? And is shadow receiving/casting still on the table or deemed impossible.
     
    jack-riddell likes this.
  20. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    Feature wise it will be almost identical to Lit smoke and fire with (hopefully) the addition of light probe support if i can work out how to extract that data from unity and pass it to my shader. As for improvements it will run a lot faster, has better control over emissive flame colour and intensity and has occlusion in the smoke adding that depth that was missing in previous versions.

    This asset has different tools, texture format, shaders and art asset creation pipeline than both my previous assets. If i combined it with my previous assets It would create confusion. People would use a texture formatted for this asset with shaders built for previous assets then complain that the smoke wasn't rendering correctly. I would need to add extra documentation to explain all the subtle differences to avoid confusion which would take extra time. At the moment both my previous packages sit around 1.5 gig in size and contain 50+ textures If I started combining each new generation of smoke renderer into the same package the file size and count would start to get unreasonable. 1.5 gigs split across 50 textures can make source control a pain, 6 gig split across 200 textures would be a nightmare.

    My plan at the moment is to release this as Lit Smoke And Fire 2 and create a discount to upgrade from Lit smoke and fire 1.
     
    John-G and Martin_H like this.
  21. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    906
    I've got https://www.assetstore.unity3d.com/en/#!/content/60561 , would you be setting a discount if I own that? the new smoke looks very real. I would like to see that as a free upgrade but it is up to you of course..
     
    jack-riddell likes this.
  22. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    The plan (if i get time) is to take everything I have learnt making Lit Smoke and Fire 1 and 2 and make Advanced Normal Mapped Particles 2 with a bunch of new features once i have finished lit smoke and fire 2. once that is done i will offer a reduced upgrade price to go from ANMP 1 to ANMP 2.

    I also want to add a discount to buy both ANMP and LSAF packages but i just haven't had the time to set that up.

    while i would like to be able to give stuff away for free there is just not enough money in this to do that. the money i make from this barely covers rent let alone bills and food.
     
    yc960 and khos like this.
  23. yc960

    yc960

    Joined:
    Apr 30, 2015
    Posts:
    228
    I suggest a collaboration with the volumetric light guy https://forum.unity3d.com/threads/released-hx-volumetric-lighting.420343/. Since his transparency support already mapped out a volumetric shadown map, inplementing shadow receiveing for the particles would cost much less performance. His plugin already modulate density based on whether light is shinning on the particles, I think it would be a breeze to add the long awaited showdow receiving feature, and his plugin is pretty popular so a collab should be really beneficial.
     
  24. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    I added Light Probe Support to the shader. The new shader format can do this with almost no effect to performance whilst still responding correctly to the normal maps. It's not a perfect solution as it uses only one light probe sample at the center of the smoke volume as opposed to the new Light Proxy Volume system but It should make the smoke fit a lot better in levels with pre baked lighting.
    TriAxisFire5LightProbes.gif
     
    JamesArndt and Martin_H like this.
  25. Petter_G

    Petter_G

    Joined:
    Apr 19, 2016
    Posts:
    12
    Looks very good. Has Unity 5.5 particle changes helped with having the particles face the camera position, so that your particles work correctly in first person camera mode.
     
  26. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    I managed to fix that problem in lit smoke and fire 1 with a bunch of hacks and some ugly code but with my new shader for LSAF2 and unity 5.5 it just works strait out of the box no hacks required. as an added benefit my new code also does stretched particles a lot better now to.
     
    Last edited: Nov 16, 2016
  27. Petter_G

    Petter_G

    Joined:
    Apr 19, 2016
    Posts:
    12
    Fan-tastic!
     
  28. yc960

    yc960

    Joined:
    Apr 30, 2015
    Posts:
    228
    I am have problems trying to integrate the lit smoke and fire shader into my project. Any reason you are not using the unity helper ComputeScreenPos or COMPUTE_EYEDEPTH functions?

    Anyways in CGNormalMappedVertex file vertex function the line:
    o.vertex = UnityObjectToClipPos(v.vertex);
    was repeated on 394 and 388. hardly seems intentional
     
  29. yc960

    yc960

    Joined:
    Apr 30, 2015
    Posts:
    228


    One more thing, when the particle system rotates or camera rotation around the particle system, the smoke shows ugly pop in due to distance sorting. Now that most of the data is exposed in particlesystem, can you fix it?
     
  30. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    You are right that was a mistake. the compute screen pos and eye depth is because i wrote my own soft particle function that is more efficient and passes fewer values around. What issues are you having with your integration?

    the only easy way to fix the popping i have found is to use more particles at lower alpha. To truly fix the problem I would have to completely gut the unity particle system and rewrite it from scratch unfortunately. To fix the problem I would need to detect when 2 particles are getting close, place a clone of the closest particle behind the particle that's about to pop to the front then fade the closest particle out and the clone particle in. To do this fix i would need to write my own particle sorter and probably particle color system if not more. The big issue is if i did all that i would be competing against Particle Playground as well as the unity devs who are in the process of upgrading the particle system. If i had infinite time and money I would try and fix it (particle popping has been driving me mad for the last year+ ) but at the end of the day I need to eat and pay rent :(.
     
    Martin_H likes this.
  31. yc960

    yc960

    Joined:
    Apr 30, 2015
    Posts:
    228
    I am trying to find the equvalent of :
    o.projPos = ComputeScreenPos(o.pos); COMPUTE_EYEDEPTH(o.projPos.z);
    for volumetric lighting support
    The custom function does not work in this regard.
     
  32. yc960

    yc960

    Joined:
    Apr 30, 2015
    Posts:
    228
    As for the pop in caused by sorting, since the position and size data are exposed, maybe you can do a blending between 2 particles at the overlap position as they are getting close in distance to camera and overlapping, maybe some kind of UV magic?

    Something like:
    1. extract rotation,position,size and calculate distance to camera
    2. this will yield particles that are overlapping and close in distance to camera
    3. Since you have rotation, position and size, you can compute the exact overlapping area
    4. do a blend between those particles in the overlapping area as they get closer
    5. no more pop in!
     
  33. yc960

    yc960

    Joined:
    Apr 30, 2015
    Posts:
    228
    I got a new idea!

    Image effects! Since all the alpha are being drawn anyways, the pop in blend can be done in an image effect too, if that is better. Pass the data to the image effect and have it blend and sort to avoid pop in. And maybe even add it at the shadow pass to add shadown receiving and casting on the particles too!

    If you are not comfortable keeping the discussion in this thread we can do PM to avoid clottering the thread if you want.
     
  34. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    ok so the exact lines for that in cg vertex are

    450 //setup soft particle value
    451 VertParticleSoftFactor(o.vertex, o.ScreenSpaceCordAndFog.xy);
    this is the equivalent to "o.projPos = ComputeScreenPos(o.pos);"

    "VertParticleSoftFactor" is a function with its code at line 252 to 262
    the reason I used my own code is with "o.projPos = ComputeScreenPos(o.pos);" they need to pass 3 values and perform something called the perspective divide in the fragment function.
    I do that perspective divide in the vertex function at line 256 and pass only 2 values to the fragment function saving a precious vert to frag texcord and making the fragment function run faster. The down side to my approach is if the particles are not perfectly facing the camera render direction it breaks the soft particle rendering. if you set the particle facing mode to facing instead of view you will see the limitations.

    413 //vert view pos
    412 float3 VertViewPos = mul(UNITY_MATRIX_MV,v.vertex).xyz;

    453 //save depth
    454 o.UV2BlendAndDepth.w = -VertViewPos.z;
    this is the equivalent to "COMPUTE_EYEDEPTH(o.projPos.z);" I used my own version instead of theirs because I was already computing the view space position of the particle for the light calculation and it just made sense to reuse that value


    I will start a PM convo of this just to avoid clogging the thread
     
    Last edited: Nov 28, 2016
    yc960 likes this.
  35. yc960

    yc960

    Joined:
    Apr 30, 2015
    Posts:
    228
    Following error shows when building lit smoke and fire for windows 64bit with 5.5.0f2:

    Shader error in 'Encap/LitSmokeAndFire/CGNormalMappedVertex': Program 'frag', error X4506: ps_4_0_level_9_3 input limit (8) exceeded, shader uses 9 inputs. (on d3d11_9x)
    Shader error in 'Encap/LitSmokeAndFire/CGNormalMappedVertex': invalid subscript 'a' at line 495 (on d3d9)
    Shader error in 'Encap/LitSmokeAndFire/CGNormalMappedVertex': invalid subscript 'a' at line 495 (on d3d11)
    Shader error in 'Encap/LitSmokeAndFire/CGNormalMappedVertex': invalid subscript 'a' at line 495 (on d3d11_9x)

    I think i got similar error for ANMP too.
    Package downloaded with 5.5 editor.
     
  36. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    is this before or after you made changes?
     
  37. yc960

    yc960

    Joined:
    Apr 30, 2015
    Posts:
    228
    fresh project, fresh import, no changes
     
  38. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    if you click on the first error can you see a list of all the #defines written in capital letters? that shader can be compiled into an ungodly number of sub variants with different settings turned on and off (200,000 + from memory) if I can narrow down what variant is broken It makes it a lot easier to fix.
     
  39. yc960

    yc960

    Joined:
    Apr 30, 2015
    Posts:
    228
    error 1:
    Shader error in 'Encap/LitSmokeAndFire/CGNormalMappedVertex': Program 'frag', error X4506: ps_4_0_level_9_3 input limit (8) exceeded, shader uses 9 inputs. (on d3d11_9x)

    Compiling Fragment program with PIXEL_LIGHT_OPTION_BIT_2 PIXEL_LIGHT_OPTION_BIT_1
    Platform defines: UNITY_NO_SCREENSPACE_SHADOWS UNITY_ENABLE_REFLECTION_BUFFERS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING SHADER_API_MOBILE SHADER_API_DESKTOP UNITY_COLORSPACE_GAMMA

    error2:
    Shader error in 'Encap/LitSmokeAndFire/CGNormalMappedVertex': invalid subscript 'a' at line 495 (on d3d9)

    Compiling Vertex program with ORTHOGRAPHIC
    Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING SHADER_API_DESKTOP

    error3:
    Shader error in 'Encap/LitSmokeAndFire/CGNormalMappedVertex': invalid subscript 'a' at line 495 (on d3d11)

    Compiling Vertex program with ORTHOGRAPHIC
    Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING SHADER_API_DESKTOP

    error4:
    Shader error in 'Encap/LitSmokeAndFire/CGNormalMappedVertex': invalid subscript 'a' at line 495 (on d3d11_9x)

    Compiling Vertex program with ORTHOGRAPHIC
    Platform defines: UNITY_NO_SCREENSPACE_SHADOWS UNITY_ENABLE_REFLECTION_BUFFERS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING SHADER_API_MOBILE SHADER_API_DESKTOP UNITY_COLORSPACE_GAMMA

    This is fresh project btw.
     
  40. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    Making steady progress on lit smoke and fire 2. just in the final stages of converting over all the old art assets to the new formats. I plan on releasing LSAF2 with a few extra tools for tweaking the assets to better fit your art style. For example I have made a tool that will allow you to blur the normals and transparency as well as increase or decrease the occlusion and bump intensity. The additional controls will allow you to make smoke effects with very subtle lighting effects or smoke with very harsh lighting effects depending on your scene.

    I am also including all the raw emissive intensity maps so you can re colour them to your hearts content using unitys new sprite sheet tools.
    this is a pic with some re balanced emissive lighting with tweaked normal maps the have their transparency blurred.
    TriAxisFire6SmallFlame.gif
     
  41. crudeMe

    crudeMe

    Joined:
    Jul 8, 2015
    Posts:
    81
    Hi! Sorry if you've already mentioned it somewhere, but what's the ETA of LSAF2? Couple of weeks or Q1 2017?
     
  42. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    So at this point all the artwork, tools and code are complete all that is remaining is the demo scenes, store page and documentation. It takes unity 10 days to ok a package for sale during which I will be doing the documentation so by the 24th at the soonest but probably in the first week or 2 of next year.
     
    yc960 likes this.
  43. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    First Demonstration scene showing off multiple light sources.
    still not 100% happy with the smoke and fire but i cant spend my whole life tinkering with it.
    TriAxisFire7DemoScene1.gif
    Does anyone have any ideas or suggestions?
     
    IronDuke likes this.
  44. crudeMe

    crudeMe

    Joined:
    Jul 8, 2015
    Posts:
    81
    Fire&Smoke looks awesome already! Is it possible to add some dynamics to this? Will it be possible to show sort of fire inner explosion, when base fire expands and contracts quickly? I tried to find a reference quickly, but all I found is burning cop car -


    Also, there are some monstrosity fires, where everything is sort of slow-mo. Sorry, don't have much time to find references atm.

    And the second though is if your new shaders set is capable of emitting smoke only, that also should be shown in dynamic. Probably, throwing a smoke grenade, which is then rolling on the floor by inertia and emitting smoke on the way.

    Those are probably basic usage for action packed game, not shown by you. But as to me, I'm more interested in white tire smoke.
     
    jack-riddell likes this.
  45. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    Demonstration scene for Light Probe support. Interestingly I found a bug in my code that once fixed allowed me to make everything faster and add light probe light scattering.

    TriAxisFire8DemoScene2.gif
     
    John-G, yc960, IronDuke and 1 other person like this.
  46. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    Demonstration scene showing light forward scattering (Light shining through smoke). not sure if it is the best for showing off the forward scattering but i think it looks cool.
    TriAxisFire10DemoScene3.gif
    I think this will be the last of the complex demonstration scenes. It takes me about a day to make one and considering they are for PR only its a bit of a waste. From here on out its just going to be boring scenes just showing off the effects.
     
    John-G, yc960, IronDuke and 3 others like this.
  47. crudeMe

    crudeMe

    Joined:
    Jul 8, 2015
    Posts:
    81
    Thank you very much for such a presentation and time taken. Waiting for release.
     
    jack-riddell likes this.
  48. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    spent a day gutting my code trying to work out why it wasn't running on webgl. turns out webgl doesn't support 1D textures
     
    yc960 likes this.
  49. jack-riddell

    jack-riddell

    Joined:
    Feb 11, 2014
    Posts:
    326
    WebGL version of the scenes I have posted above. the file is quite large and is a dev build because unity is refusing to build anything else but for those willing to wait It should show the graphical quality the new package brings. I am using bloom and a bunch of other screen space scripts to make things a little prettier so if it runs slow on your machine then that is probably the culprit not the smoke shader.

    https://riddellriddell.itch.io/lit-smoke-and-fire-2
     
  50. StaffanEk

    StaffanEk

    Joined:
    Jul 13, 2012
    Posts:
    380
    I think the engine stripping might have removed a necessary component. Have you tried force including your shaders in the Preload Assets section of the Player settings?

    EDIT: Would it be possible to have some sort of camera interaction in the WebGL demo?