Search Unity

[RELEASED] Hx Volumetric Lighting

Discussion in 'Assets and Asset Store' started by Lexie, Aug 1, 2016.

  1. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    I've pushed a new build (1.3.5) that support lights larger then far clipping plane. ( @Trainwiz )
    Also fixed an issue with the shader compiler throwing an error when compiling spotlight support.

    I'm going to port my temporal filtering created from my 2D path tracer over to this plugin to create a better temporal pass that has less ghosting and should have better results. Ill include a setting to keep the old pass as there will be some cases where that will perform a little better then the new one.
     
    Last edited: Sep 11, 2018
  2. Trainwiz

    Trainwiz

    Joined:
    Aug 25, 2015
    Posts:
    20
    I'm still not sure it's working right.
    I've tried to apply this to my suns but I don't get any sort of lightshaft effect, no matter what settings I play with.

    Second, the light seems to bug out when the point light has a range of 350,000 and above.

    Like I said the effect I'm looking for is more of a subtle lightshaft effect, akin to this.
     
  3. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    Did you add the HX Volumetric Camera to your camera?
     
  4. Trainwiz

    Trainwiz

    Joined:
    Aug 25, 2015
    Posts:
    20
    Everything is set up properly, both light and camera have their volumetric components. I just can't seem to get the settings to give me those nice lightshafts with really large lights, which is what I'm looking for.
     
  5. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    Strange. I've always gotten excellent results from this asset. I will try an experiment and see if I can get the effect you are looking for. Is the sun in that scene straight ahead and pointing straight at the camera?
     
  6. Trainwiz

    Trainwiz

    Joined:
    Aug 25, 2015
    Posts:
    20
    The sun is a giant flare with a point light attached (with range anywhere from 200,000 to 400,000) not a directional light.
     
  7. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    I'm not sure you're going to get the effect you're showing in that video. That looks more like a 2D shaft effect where HX is a volume that takes up all the space. Plus the fact that a point light is not directional. However, if you make the light directional and have lots of objects in the space scene such as asteroids then you can see the effect more prominently because those objects will break up the volume and make the shafts more distinct. See image below:
    upload_2018-9-12_11-17-53.png
     
  8. Trainwiz

    Trainwiz

    Joined:
    Aug 25, 2015
    Posts:
    20
    I understand that, but my lights are point lights. The suns in my game are physical objects in space.
     
  9. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    You can have a physical sun and still use a directional light so I'm not sure why there is a problem.
     
  10. Trainwiz

    Trainwiz

    Joined:
    Aug 25, 2015
    Posts:
    20
    Even if the sun sits at the center of the star system and all objects orbit it?
     
  11. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    Hmmm. So, in your game you will have the ability to fly your ship completely around the sun?
     
  12. Trainwiz

    Trainwiz

    Joined:
    Aug 25, 2015
    Posts:
    20
    Yes. The scale is highly inaccurate but the systems are still quite large.
     
  13. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    Well, maybe you can use a point light and also add a directional light that adjusts its rotation based on camera rotation so that it's always facing the camera?
     
  14. greengremline

    greengremline

    Joined:
    Sep 16, 2015
    Posts:
    183
    Good call, that's exactly it - we have a two camera setup. Any idea on how to fix?

    EDIT: Hold on, actually it looks like even deleting the second camera doesn't fix it...gonna keep investigating and report back
     
    Last edited: Sep 13, 2018
  15. Trainwiz

    Trainwiz

    Joined:
    Aug 25, 2015
    Posts:
    20
    Got it to work with some tweaking, looks great.


    But... Unity's default fog (the kind you get with the Post Processing Behavior) doesn't seem to work with it, so distant objects are just popping in instead of nicely fading in.
     
    hopeful and magique like this.
  16. ksam2

    ksam2

    Joined:
    Apr 28, 2012
    Posts:
    1,080
    Why too much keywords? there is keyword limitation inside Unity and it use too much of keywords.
     
  17. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    This plugin only uses a few keywords. Unless you're using a really outdated version of the plugin it shouldn't really be an issue.
     
  18. o-san

    o-san

    Joined:
    Jun 23, 2018
    Posts:
    32
    Great asset, well worth the price. But I find the startup time is quite long (I’m guessing over one minute). Is there any way to speed it up?
     
    Last edited: Sep 18, 2018
  19. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    It needs to compile a lot of shader depending on how many variances you use. Unity should cache them out though, so it should be a one time thing.
     
  20. o-san

    o-san

    Joined:
    Jun 23, 2018
    Posts:
    32
    Thanks for the quick repIy! =)

    I've measured the time it takes to launch the game and it is always around 40 seconds. I've also tried setting the preloaded shaders to the HxUsedShaderVariantCollection without any measurable improvement.

    my project's graphics settings:

     
    Last edited: Sep 18, 2018
  21. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    It wouldn't do anything to load times, only build times. Are you talking about build times?

    While messing around with all the settings you may have made it track every use case. You can clean your project by deleting HXUsedShaders and running the game in the editor. It will re-track all the shaders you actually used and rebuild the hxUsedShaderVariantCollection when you stop the game.

    That should clean up any unsued variants and make the build times faster.
     
    Last edited: Sep 19, 2018
  22. o-san

    o-san

    Joined:
    Jun 23, 2018
    Posts:
    32
    Okay, I am talking about the time it takes from when you press the play button to when the actual game shows in the game window. I’m guessing this is not the build time.

    I will remove the file you mentioned and try again. I’ll post back the results...
     
  23. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    Regarding the slow time to play. I've been using this asset for a long time and I've never experienced any 40 second load time. And I've tried on 5.6, 2017, and 2018.
     
  24. o-san

    o-san

    Joined:
    Jun 23, 2018
    Posts:
    32
    Well, I get the same load times after removing HXUsedShaders and running the game again after an initial run. I tried removing the asset entirely from my project (just to be sure) and that reduced the load time to five seconds. Later tonight I will have more time testing the examples.
     
  25. o-san

    o-san

    Joined:
    Jun 23, 2018
    Posts:
    32
    The example scene with the spinning cages loads up fast. It only takes a second or two... so there must be something up with my particular project. Here's what my HXusedshaders looks like after I deleted the old one:

    The graphics settings says it is currently tracking 22 shaders and 39 total variants. I don't know if these numbers are particularly high or low. My game has pretty much only low poly meshes and uses instancing to spawn most of the game objects at run-time, if that could have any impact...
     
  26. o-san

    o-san

    Joined:
    Jun 23, 2018
    Posts:
    32
    I managed to track down the load time slowdown. It would seem that the problem only occurs when one of my pool controller scripts where in use (a bullet handler) in combination with this asset.

    I reworked the pool controller's Start method to have the instanced objects initially disabled (and not calling any OnCollisionEnter callback) and presto! much faster load times.

    I can't explain why this would be a problem when this asset is imported along side that script... I'm just happy it loads fast again (down to 3-5 seconds load time). =)

    Short clip of the lights in action:


    Thanks for the help everyone!
     
    Last edited: Sep 19, 2018
    glenneroo, Lexie, Shodan0101 and 2 others like this.
  27. dwit_mass_creation

    dwit_mass_creation

    Joined:
    Jun 18, 2015
    Posts:
    74
    Hi,

    We found bug in HxVolumetricLight.cs

    Code (CSharp):
    1.     bool ShaderModel4()
    2.     {
    3.  
    4.        if (SystemInfo.graphicsDeviceType == GraphicsDeviceType.Direct3D9 || SystemInfo.graphicsDeviceType == GraphicsDeviceType.OpenGLES2)
    5.         {
    6.             return false;
    7.  
    8.  
    9.         }
    10.  
    11.         return false;
    12.     }
    It should return true:

    Code (CSharp):
    1.     bool ShaderModel4()
    2.     {
    3.  
    4.        if (SystemInfo.graphicsDeviceType == GraphicsDeviceType.Direct3D9 || SystemInfo.graphicsDeviceType == GraphicsDeviceType.OpenGLES2)
    5.         {
    6.             return false;
    7.  
    8.  
    9.         }
    10.  
    11.         return true;
    12.     }
    [

    Thanks to this fix on GPU "renderLights" is more than 3ms faster (was 3-4ms, now is 0.1ms).

    This bug caused that shader calculated 50 invalid density volumes for each pixel, because scripts were creating data structures for ShaderModel3 but shaders were using data structures from ShaderModel4.
     
    hopeful likes this.
  28. RickF

    RickF

    Joined:
    Sep 12, 2012
    Posts:
    33
    Hi.
    The modified standard shader is not compiling for me (unity 2018.2.6f1). Showing up that pink color and under a 'failed to compile' listing in the shader dropdown. Would appreciate any assistance. thanks.
     
  29. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    Hmm. let me look into that. Thanks for the report. There was a time this function was not playing well with older shader models. Now that unity no longer supports dx9 its probably fine.

    Edit: after testing the shaders are set to shader model 3, its not ever using those 50 volumes, Hence why it returns false in that function. So unless you also changed the target shader level of all the volumetric shaders, that change wouldn't do anything but disable the ability to use density volumes. In my testings i haven't seen any speed difference.


    Will do some testing and get back to you.

    Edit: I have submitted a build with a fix to this issue. Should be live soon.
     
    Last edited: Sep 26, 2018
  30. dwit_mass_creation

    dwit_mass_creation

    Joined:
    Jun 18, 2015
    Posts:
    74
    It was always using 50 volumes. The problem was with function (HxVolumetricLightCore.cginc):

    Code (CSharp):
    1. float GetVolumeDensity(float3 wpos, float volumeDensity)
    It is using:

    Code (CSharp):
    1. #if SHADER_TARGET <= 30
    Actual problem was this line:

    Code (CSharp):
    1. if (hxVolumeSettings[c].y == -1) { return volumeDensity; }
    So scripts updated hxVolumeSettingsOld and not hxVolumeSettings, so it was always default zero, and that's why it always calculated 50 volumes.

    As for performance gain we have scene with many Point and Spot Lights, and that is why we have such gain in performance (4ms vs 0.2ms).


    EDIT: Actual problem was with HxVolumetricPointLight.shader:

    It has #pragma target 3.5 on top of shader and it seems it overrides pragma target 3.0 which are later.

    So there was problem only with point lights (and we are using many of them). So fix is to use #if SHADER_TARGET <= 35 or delete #pragma target 3.5 from shaders
     
    Last edited: Sep 28, 2018
  31. DONNY77

    DONNY77

    Joined:
    Mar 22, 2015
    Posts:
    3
  32. UnityRocksAlt

    UnityRocksAlt

    Joined:
    Dec 28, 2015
    Posts:
    157
    I want to be honest, I am confused between Volumetric Fog & Mist and this. Can anyone including the developer(s) tell me advantages and disadvantages of both.
     
  33. UnityRocksAlt

    UnityRocksAlt

    Joined:
    Dec 28, 2015
    Posts:
    157
    Ok, I bought this
     
  34. E-Cone

    E-Cone

    Joined:
    Jul 4, 2013
    Posts:
    46
    Seems like this plugin doesn't work with shadowmasked lightmaps. Sun casts rays right through any baked roof... Only unbaked objects block this effect right now.

    upload_2018-10-4_4-4-16.png
     
  35. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    I'm not seeing this #pragma target 3.5, Either you have an older build or your shaders have been edited at some point. The whole thing was designed around shader model 3.0, thats why that function still returns false. There was a time i was going to upgrade it to shader model 5.0 but decided against it.
     
  36. Nathan_D

    Nathan_D

    Joined:
    Oct 10, 2013
    Posts:
    31
    Is this asset usable with a orthographic camera? I have a 2.5D game where I'm using 2D sprites in 3D space so that I can use 3D unique effects. Black Future 88' recommended this asset and given they are a 2D game I would hope it would be usable.
     
  37. Pourya-MDP

    Pourya-MDP

    Joined:
    May 18, 2017
    Posts:
    145
    Hi everyone
    Im asking this question from those who used this asset
    Can this asset help to create some atmospheric flashlight effect just like the one used in INSIDE?
    im trying to achieve something like this
    Screenshot_2018-10-08-12-23-17.png
    Screenshot_2018-10-04-20-40-40.png i already achieved the background fog atmospher using ssms from @OCASM
    But looking for some implementation for the flashlight
    Any help will deeply appreciated
     

    Attached Files:

    Last edited: Oct 16, 2018
  38. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    Yes, the method of calculating the volumetric lighting in INSIDE is the same method my plugin is based around.
     
    Pourya-MDP likes this.
  39. Pourya-MDP

    Pourya-MDP

    Joined:
    May 18, 2017
    Posts:
    145
    Hi there and so much thanks for fast response and also great plugin
    I,ll give it a try then
    Doese it support ssms?
    I mean is it usable with ssms?
    Im kindda new to unity and dont know much about shaders and c#
     
  40. AntonQvarfordt

    AntonQvarfordt

    Joined:
    Mar 14, 2013
    Posts:
    27
    Lightweight Rendering Pipeline support?

    Doesn't seem to support HX/vice versa. I'd enjoy it if it did.
     
    punk likes this.
  41. marcos

    marcos

    Joined:
    Oct 18, 2009
    Posts:
    592
    @Lexie Been trying to get this to run on Nintendo Switch, as yet unsuccessfully. Is it supported? If so, do I have to do anything specific to make it work?

    Will keep trying!
     
  42. terrivellmann

    terrivellmann

    Joined:
    Mar 10, 2015
    Posts:
    23
    Hi, I've noticed any unlit materials seem transparent if there isn't anything rendered behind them. Here are some examples:
    Font Cube set to Unlit, Back Cube set to Standard, Hx ON
    https://www.dropbox.com/s/p8j4ek4l7kh94uf/1.png

    Font Cube set to Unlit, Back Cube set to Standard, Hx OFF
    https://www.dropbox.com/s/xz2hakbg55edd0x/2.png

    Both Cubes set to Unlit, Hx ON
    https://www.dropbox.com/s/aw6xhuv2lvyr3w9/3.png

    What am I missing? The docs mention tweaks necessary to get transparency to work but I don't want it to be transparent...
    I'm sure I'm missing something obvious. Thanks!
     
  43. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    Do you have any other image effects enabled that might be causing an issue. It looks as though something is grabbing the screen buffer before the unlit objects are rendered, and then writing that buffer back.

    What render path are you using Forward, deferred, vertex lit.


    Are their any compiler issues on the volumetric shaders when switching the build over to switch?
    If nothing is wrong there, check that you have shadows enabled in the quality settings for switch. Could be an issue with the default quality settings for switch.
     
  44. terrivellmann

    terrivellmann

    Joined:
    Mar 10, 2015
    Posts:
    23
    I've disabled everything else and it seemed to only work right when Hx is disabled. To make sure I created a new project and added just two cubes, one with unlit and the other standard shader, added Hx to the camera and light and the unlit became transparent. It looks the same in forward or deferred.

    Pic: https://www.dropbox.com/s/8hniascv10js8vb/4.png

    Unity version is 2017.4.10f1

    Thanks for the reply!
     
  45. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    Thanks for the info, Ill check out the plugin on that build of unity and see whats happening.
     
  46. terrivellmann

    terrivellmann

    Joined:
    Mar 10, 2015
    Posts:
    23
    Thanks, I updated to 2017.4.13f1 just in case and its the same.
     
  47. emosia

    emosia

    Joined:
    Feb 19, 2013
    Posts:
    11
    Hi, I have been using your asset for some time and it is great. I have a specific problem though. I am using your asset on my scene and I render the scene with Unity's Recorder as a 360 View video. The problem is here. Volumetric light effect is not working (visible) on the parts other than main camera view. I am posting a screenshot to explain better.

    https://www.dropbox.com/s/vkwlkbpk34phe30/HxProblem.png?dl=0

    My question is whether is it about your asset or purely about Unity Recorder. Can you help me with that?
     
  48. Wikzo-DK

    Wikzo-DK

    Joined:
    Sep 6, 2012
    Posts:
    83
    Hi. Does Hx support Nintendo Switch? Seems like TextureFormat 18 is not supported. I get the following errors when trying to build:

    Code (CSharp):
    1. TextureFormat 18 is not supported on this platform
    2. UnityEngine.Texture2D:Internal_CreateImpl(Texture2D, Int32, Int32, GraphicsFormat, TextureCreationFlags, IntPtr)
    3. UnityEngine.Texture2D:Internal_Create(Texture2D, Int32, Int32, GraphicsFormat, TextureCreationFlags, IntPtr)
    4. UnityEngine.Texture2D:.ctor(Int32, Int32, TextureFormat, Boolean, Boolean, IntPtr)
    5. UnityEngine.Texture2D:.ctor(Int32, Int32, TextureFormat, Boolean, Boolean)
    6. HxVolumetricCamera:CreateTileTexture()
    7. HxVolumetricCamera:CreatePIDs()
    8. HxVolumetricCamera:Awake()
    9.  
    10. [.\Runtime/Graphics/Texture2D.cpp line 592]
    11. (Filename: .\Runtime/Graphics/Texture2D.cpp Line: 592)
    12.  
    13. UnityException: Failed to create texture because of invalid parameters.
    14.   at UnityEngine.Texture2D.Internal_Create (UnityEngine.Texture2D mono, System.Int32 w, System.Int32 h, UnityEngine.Experimental.Rendering.GraphicsFormat format, UnityEngine.Experimental.Rendering.TextureCreationFlags flags, System.IntPtr nativeTex) [0x00000] in <00000000000000000000000000000000>:0
    15.   at UnityEngine.Texture2D..ctor (System.Int32 width, System.Int32 height, UnityEngine.TextureFormat textureFormat, System.Boolean mipChain, System.Boolean linear, System.IntPtr nativeTex) [0x00000] in <00000000000000000000000000000000>:0
    16.   at UnityEngine.Texture2D..ctor (System.Int32 width, System.Int32 height, UnityEngine.TextureFormat textureFormat, System.Boolean mipChain, System.Boolean linear) [0x00000] in <00000000000000000000000000000000>:0
    17.   at HxVolumetricCamera.CreateTileTexture () [0x00000] in <00000000000000000000000000000000>:0
    18.   at HxVolumetricCamera.CreatePIDs () [0x00000] in <00000000000000000000000000000000>:0
    19.   at HxVolumetricCamera.Awake () [0x00000] in <00000000000000000000000000000000>:0
     
  49. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646

    If you change the texture format to either r16 or r8 in the CreateTileTexture function in the hxVolumetricCamera.
    Does that solve the issues? That texture doesn't really need to b 32bits, 16 or 8 should be more then fine.

    Pretty sure the switch supports r32 format though... Strange that its failing to create that texture.
     
  50. marcos

    marcos

    Joined:
    Oct 18, 2009
    Posts:
    592
    Changing shadow settings didn't affect anything.

    I hadn't noticed any errors or warnings before (aside from a DX9 warning), so I swapped to PC Mac then back to Switch.

    There are a bunch of warnings similar to these:

    Shader warning in 'Hidden/HxVolumetricPointLight': Fragment info
    -------------
    _shader1089919557(75) : warning C7050: "u_xlati43" might be used before being initialized
    (on switch)

    Compiling Vertex program with SHADOWS_OFF
    Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING UNITY_ENABLE_DETAIL_NORMALMAP UNITY_COLORSPACE_GAMMA UNITY_LIGHTMAP_RGBM_ENCODING



    and


    Shader warning in 'Hidden/HxVolumetricDirectionalLight': Fragment info
    -------------
    _shader693109149(71) : warning C7050: "u_xlati19" might be used before being initialized
    _shader693109149(91) : warning C7050: "u_xlati43" might be used before being initialized
    (on switch)

    Compiling Vertex program with SHADOWS_OFF
    Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING UNITY_ENABLE_DETAIL_NORMALMAP UNITY_COLORSPACE_GAMMA UNITY_LIGHTMAP_RGBM_ENCODING