Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

[Next-Gen Soft-Shadows 2] Sophisticated dynamic penumbra Shadows for Unity

Discussion in 'Assets and Asset Store' started by tatoforever, Nov 8, 2016.

?

Would you like to buy this on the Asset Store? If so, how much?

Poll closed Jul 10, 2017.
  1. I like it to be priced between 20 to 10$.

    56.8%
  2. I like it to be priced between 10 to 5$.

    39.0%
  3. Zero $, I'm not interested, I love my Unity's default aliased, pixelated horrid-shadows.

    4.2%
  1. Bzuco

    Bzuco

    Joined:
    Sep 6, 2015
    Posts:
    43
  2. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    780
    What am I doing wrong if frustum shadows completely disappear at exactly the shadow distance limit for me? It's like they can't be displayed anywhere but over distance range shadowmaps are already cover, which doesn't seem to be the intended behaviour.
     
  3. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    3,888
    @bac9-flcl,
    It means you are using ContactShadows instead of FrustumShadows. :D
    What NGSS version are you on? Last one is 2.2.4 (2.2.5 is being reviewed).
     
  4. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    780
    I'm attaching frustum shadows component to the camera - however, it previously had the contact shadows component attached. Should I remove or disable the contact shadows component?
     
  5. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    3,888
    @bac9-flcl,
    On top of infinite shadows FrustumShadows can do what ContactShadows do faster and better so yes remove it, you won't need it anymore.
     
  6. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    780
    Thanks, that makes sense! It would perhaps be useful to update the documentation to indicate that (and perhaps also do a gameObject.GetComponent on initialization of frustum shadows to post a log warning if two components are present). :)
     
  7. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    780
    I have removed Contact Shadows component from my camera and I still don't see frustum shadows anywhere but as a tiny change making shadows thicker within the traditional shadow mapping radius. What else might be preventing them from working properly, extending from shadowmap limit out into the distance?
     
  8. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    3,888
    @bac9-flcl,
    Are you using deferred or forward? FrustumShadows only work on deferred (I'm adding support to forward now).
    Do you have a picture of your scene with frustumshadows?
     
  9. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    780
    Yes, I'm using deferred. The scene looks like this: no change outside of standard shadow mapping radius:

     
  10. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    3,888
    @bac9-flcl,
    Show me your NGSS_FrustumShadows settings?
    PS: Did you installed the latest NGSS libraries?
     
  11. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    3,888
    Folks,
    NGSS v2.2.5 is out. It fixes a FrustumShadows near plane fade-in bug. If you where on v2.2.4 I suggest to upgrade to v2.2.5. You don't have to re-install the libraries, only download the package to your project.
     
    Bartolomeus755 likes this.
  12. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    780
    I updated to 2.2.5. Libraries are updated, full reimport was done after clearing all shadow cache. The issue still persists. To be absolutely sure, I loaded your own sample scene, and it shows exact same behaviour - no visible frustum shadows, only traditional shadow maps are noticeable and they fade at a standard distance:

    Here is the GIF of it

    Here are the settings from your scene:



    Here are my project settings, pretty standard stuff there:



    We're using DX11/linear. If that's relevant, we're using Unity 2019.2f1 - maybe there was some change vs. 2019.1 that breaks your frustum rendering?
     
  13. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    3,888
    @bac9-flcl,
    Do you have multiple Unity installs? I'm pretty sure you installed the NGSS libraries in the wrong Unity (thus wrong directory). FrustumShadows and NGSS shadows works fine on all Unity versions (up to the latest 2019).
     
  14. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    780
    Yes, I am absolutely sure everything is installed correctly because everything else like PCSS works perfectly and because I never manually navigate to Unity installs, I use Unity Hub to directly jump to install directories.

     
  15. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    3,888
    Go to your program files and look for the Unity 2019 directory (or the path where you installed Unity). Navigate to Editor/Data/CGIncludes/ and compare the three libraries files (UnityShadowLibrary, AutoLight and UnityDeferredLibrary) to the ones provided by NGSS, if they are different then yes it means you installed NGSS in a different Unity version.
    You can always install the NGSS libraries manually by replacing the CGInclude files in Unity Editor/Data/CGIncludes/ directory with the ones provided by NGSS then delete your project Library/ShaderCache folder and restart the Editor.
     
  16. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    780
    Just put them into a diff checker to be sure and they are identical. There is "NGSS FRUSTUM SHADOWS" section inside UnityDeferredLibrary.cginc and everything else is in place.



    I always install libraries by closing the editor, removing all shader cache files from the library and manually copying the 3 libraries because making Unity launch in administrator mode to make install buttons work is a pain when you use the Hub. Trust me, the install is solid, we're constantly migrating to new Unity releases and I work on several machines, so I've done this dozens of times before. The problem is with something else.
     
    Last edited: Aug 2, 2019
  17. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    3,888
    Can you show me the line 93 of your UnityDeferredLibrary.cginc file? The one installed in the Unity/Editor/Data/CGIncludes directory.
     
  18. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    780
     
  19. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    3,888
    Open NGSS_FrustumShadows.cs and comment line 323 and see if it works now?
    If nothing works, can you please provide me a small repro project with Unity 2019.2 and send it to support? I will take a look at.
     
  20. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    780
    It doesn't seem to change anything. Looking at isolating the repro project.
     
    tatoforever likes this.
  21. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    780
    I figured out what it was - I totally missed the fact that our project settings had deferred shader replacement. In our case, the project is using Advanced Foliage Shader that gives us modified deferred pipeline with wrap shading and translucency for vegetation.

    upload_2019-8-2_14-47-8.png

    I'll look at merging AFS stuff into your deferred library since AFS doesn't seem to modify much. Interesting how I never noticed it, since all other functionality seemed to work well before. :)
     
    tatoforever likes this.
  22. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    780
    Wait, if this library can be replaced in project settings, couldn't this part of NGSS be installed by just linking a file in project settings instead of replacing the deferred library in Unity install? I suppose you didn't do that because you didn't want to also replace the deferred .shader file itself (project settings don't give you an option to just replace the UnityDeferredLibrary.cginc)?

    And on another note, if it's not too much trouble, could you wrap all modifications to UnityDeferredLibrary.cginc into "// NGSS" comments to make it easier to merge multiple deferred modifications?
     
  23. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    3,888
    We don't do any change to that file (Internal-DeferredShading.shader). The one we change in the CGIncludes folder is deferred shadows, the one you are changing is lighting. xD
    Maybe your custom shaders uses a custom UnityDeferredLibrary.cginc file.
    Can you try a switching back and fort with a default standard shader and see if it shows the FrustumShadows?
     
  24. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    780
    Nah, that's the thing - the AFS includes a copy of this exact .cginc library, but it doesn't require replacing it in the Unity install because the #include clause in the shader points to in-project file instead of a built-in one. This makes built-in deferred library .cginc completely ignored by all compiled shaders - only the in-project version is actually referenced.

    Now that I notice it, that's a neat trick - although it's probably not appropriate for NGSS since NGSS has no need to modify anything in the core deferred shader.

    upload_2019-8-2_15-5-51.png
     
  25. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    3,888
    Switch to a built-in Standard shader and If FrustumShadows shows it means your custom shader is using an other UnityDeferredLibrary.cginc (instead of the default one located at Unity path/Editor/Data/CGIncludes which is replaced with NGSS libraries).
     
  26. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    780
    Yep, that's exactly what I observed - frustum shadows started working immediately after the switch in project setttings. Which led me to hunting how the deferred shader can affect the include, which led to discovering that in-project copy of deferred library include file, which led me to currently merging it with NGSS one to get functionality from both assets. :)

    I've asked Lars to comment on what specific lines AFS needs modified to be completely sure I'm moving everything to NGSS version of the library, but the changes seem simple so far.

    Edit: Merged everything, AFS just relied on an additional out parameter in
    UnityDeferredCalculateLightParams that contained shadow strength (I suppose it's useful for masking translucency from backlighting?). Yay!
     
    Last edited: Aug 2, 2019
    tatoforever likes this.
  27. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    3,888
    @bac9-flcl,
    Let me know how it ends (and how it looks in your game)! :D
     
  28. Rich_A

    Rich_A

    Joined:
    Nov 22, 2016
    Posts:
    192
    Next-Gen Soft Shadows used in Frontline Zed:

    https://store.steampowered.com/app/915490/Frontline_Zed/

    The default Unity contact shadows were very poor - with a large gap between eg. moving characters and the environment. As soon as I installed NGSS, the realism level increased dramatically. There was a small performance improvement as well.

    Until HDRP is fully ready, NGSS is still an essential component for any realistic 3D game using the default renderer.

    I would suggest having the global light settings adjusted via an Editor Window UI, instead of attached to a gameobject though. I missed a shadow distance master override attached to a single light, and I was struggling to figure it out for a while...
     
    Last edited: Aug 4, 2019
    OCASM, jcarpay and tatoforever like this.
  29. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    3,888
    @Rich_A,
    Beautiful rendering, specially the lighting and shadows, smooth and crisp! Kudos! :)
     
    Rich_A and jcarpay like this.
  30. Vagabond_

    Vagabond_

    Joined:
    Aug 26, 2014
    Posts:
    917
    Hi @tatoforever ,

    i think you answered me similar question some time ago, but let me ask this now just to be sure.

    I care mostly about shadows distances and may be performance compared to Unity shadow maps.
    I would want to eventually use NGSS for 25 square km ( 5 x 5 km ) terrain populated with vegetation using Vegetation Studio Pro.
    I saw you have done some amazing work on shadows in distance but can i expect to have vegetation shadowed i far distances in my case. Is there some limit to your system. May be not the whole 5x5 km terrains distance but let's say 1 km may be good distance. Am i going to be able to have shadows that far ?

    P.S. - of course the "soft" part of the system will be a bonus in my case !

    Thanks !
     
  31. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    780
    The frustum shadows work off of screen-space information, so they have no concrete distance limit. Whether something is a mountain 5km away or a boulder 100m away makes almost no difference to the algorithm, which is awesome! :)

    Speaking of which, I'd love an option to configure maximum distance similarly to minimum distance. The reason for that is that I'm sometimes using objects with depth-writing materials positioned right under my sky dome, very close to the maximum render distance. Those objects are similar to what's done in Destiny skyboxes and consist of flat distant mountains, megastructures etc., and having frustum shadows on those is very undesirable since they don't produce meaningful results on flat distant geometry like that and just add noise and stripe artifacts there.
     
    tatoforever likes this.
  32. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    3,888
    @ Vagabond_
    As bac9 said, there's no limitation with FrustumShadows (hence the name), anything that is in view will cast shadows, no matter how far it is. And your drawcalls won't add up as is not scene dependant, it only needs camera depth to compute shadow rays.
    @bac9-flcl,
    I'll add an option for max FrustumShadows distance in v2.3. So min and max. :V
     
    Last edited: Aug 5, 2019
  33. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    780
    Thanks a lot! Really happy with the system overall!
    I'll get proper screenshots soon, just got to fix a few regressions in our game preventing it from looking its best :D
     
    tatoforever likes this.
  34. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    3,888
    I'm leaving tomorrow for vacations, will be back August the 15th. So no work or support email before the 15th but I'll try to read your messages and reply in the forums with a 48h buffer. :D
     
    Bzuco and Rich_A like this.
  35. Vagabond_

    Vagabond_

    Joined:
    Aug 26, 2014
    Posts:
    917
    Hi @tatoforever , wish you a great vacation !

    Meanwhile if you can read this and find the time to answer will be great.
    I am looking into buying this asset - Tropical Forest Pack, but it also requires some custom deferred shaders. I also asked on the other thread if both NGSS and the tropical packs could be somehow combined. Any input on this is really much appreciated ! Thanks !
     
    tatoforever likes this.
  36. HdG_S

    HdG_S

    Joined:
    Jan 20, 2016
    Posts:
    4
    Hi!
    In our project we use UBER - Standard Shader Ultra. Unfortunately, Frustum Shadows does not work if Uber is selected as custom deferred shader. Maybe somebody has an idea how to solve this. Thanks! :)
     
    hopeful likes this.
  37. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    780
    It looks like the asset was built for compatibility with AFS - if you are using that, you will need a custom merged version of deferred library .cginc file, like one I had to make. Not sure about built-in replacement shaders the asset includes out of the box, but they work in a similar way since there aren't that many different ways to implement vegetation specific deferred changes like translucency.

    I don't think there is a way to merge these kinds of assets without going into the shader files and combining them.
     
    Vagabond_ likes this.
  38. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    3,888
    If your project uses a custom deferred library you need to manually add 4 lines of code in order for Frustum shadows to work:
    Code (CSharp):
    1.  
    2. //Add these uniforms before the UnityDeferredCalculateLightParams function
    3. uniform float NGSS_FRUSTUM_SHADOWS_ENABLED = 0;
    4. uniform float NGSS_FRUSTUM_SHADOWS_OPACITY = 0;
    5. uniform sampler2D NGSS_FrustumShadowsTexture;
    Code (CSharp):
    1.  
    2. //Add this line inside the UnityDeferredCalculateLightParams function after computing all lights attenuations
    3. atten = NGSS_FRUSTUM_SHADOWS_ENABLED > 0.0 ? min(atten, saturate(tex2D(NGSS_FrustumShadowsTexture, uv).r + NGSS_FRUSTUM_SHADOWS_OPACITY)) : atten;
    For AFS I can provide a custom DeferredLibraray that already have these changes + the denoiser code and will work out of the box.
     
    Last edited: Aug 6, 2019
    HdG_S, nirvanajie, Vagabond_ and 2 others like this.
  39. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    780
    Couple of comparison GIFs showing the frustum shadows. It's incredible how much they allow us to turn down the rendering distance of traditional shadow maps - I'm sure we can get away with something even more conservative, like 80 meters, and even make this a great adjustable quality setting.



     
    OCASM, ceebeee, Lex4art and 3 others like this.
  40. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    3,888
    @bac9-flcl
    Beautiful lighting and shadows.
    Indeed, FrustumShadows allows us to turn off completely Cascaded Shadows and set the Directional shadows distance to about 70. The massive drawcall reduction and the basic directional shadows drastically improved performance a ton. Probably like ~50%.
     
    hopeful likes this.
  41. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    780
    With a distance like that, is there any point in using cascades if the camera never gets into a first-person perspective? I feel that the transition zones between cascades and objects crossing multiple cascades cause a disproportional number of drawcalls that could be avoided.
     
    Last edited: Aug 7, 2019
    tatoforever likes this.
  42. HdG_S

    HdG_S

    Joined:
    Jan 20, 2016
    Posts:
    4

    Great, It works with Uber. Thank you very much! :)
     
    tatoforever likes this.
  43. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    486
    I just installed the new NGSS but I get this error : Assets/Psychose Interactive/NGSS/Scripts/NGSS_FrustumShadows.cs(43,6): error CS0246: The type or namespace name `Min' could not be found. Are you missing an assembly reference?

    I copied the files in NGSS/libraries into my Editor\Data\CGIncludes, closed and reopened Unity as it recompiled some shaders but I still get the error.
     
  44. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    486
    Can I please get a response to this? All the shadows in every scene have dissapeared and I can't view my scenes now.
     
  45. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    780
    What version of Unity are you using? The error simply states that NGSS fails to compile because an attribute called Min could not be found - but NGSS is not responsible fothat's not a custom functionality added by NGSS, that's a built-in Unity attribute. It should be present in any relatively recent Unity release. Either you have a Unity release without it or something else preventing compilation, I'd wager.

    Edit: It looks like the docs only added a page for that attribute in 2018.3, so fixing it is a matter of wrapping that Min attribute in an appropriate precompiler directive. Alternatively, just comment it out for now and simply not set that value below 0 - it should compile fine.
     
  46. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    486
    Thank you, commenting out the "min" line solved the compiling issue temporarily, atleast I have the shadows back.

    Btw when you used the frustum shadows in the scene you posted above, did you lose the translucency of the tree leaves?
     
  47. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    780
    I do not lose translucency, but my setup might be different from yours - I'm using a modified version of AFS where the deferred library is swapped for one from NGSS, but still contains a new out argument AFS deferred shader relies on for translucency masking.

    upload_2019-8-10_12-47-37.png
     
  48. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    486
    After playing around with Shader forge and NGSS a little, I got them to work. Frustum shadows are also a big help.
    Water Hazard 01.png
     
    tatoforever likes this.
  49. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    3,888
    Sorry for the late reply folks I'm still on vacations till August the 16th.

    @Cactus_on_Fire
    You can push the frustum shadows start distance so nearby vegetation still displays it's default translucency or reduce the backface opacity (fragments facing away from lights) with frustum shadows.
    You can also integrate frustum shadows into your own custom rendering using the 4 lines of code I posted above.
    Let me know if everything is OK? :)
    PS: About the error, not sure why the shader compiler says 'Min', it's 'min' and that's probably a Unity bogus misspelling. I'll investigate more when I get back this week.
     
    Last edited: Aug 12, 2019
  50. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    486
    Frustum shadows also creates artifacts when using multiple directional lights. I tried playing around with deferred backface options and all but no luck.
    ngss issue.jpg