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.

[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. brisingre

    brisingre

    Joined:
    Nov 8, 2009
    Posts:
    277
    That looks incredible!

    Always exciting to hear more about 2.0, too.
     
    tatoforever likes this.
  2. ThisGuyThatsHere

    ThisGuyThatsHere

    Joined:
    May 4, 2016
    Posts:
    11
    Ive got a little (?) question... How would I implement these shadows in a vertex-fragment shader? Becouse I dont want to use a surface shader, since I wont use the PBR aspect of it.

    Btw 1.7 looks promising ;)
     
    tatoforever likes this.
  3. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,353
    @ThisGuyThatsHere
    NGSS replaces Unity shadows and anything that references internally Unity shadows = gets NGSS shadows. So you can use NGSS shadows with any custom vertex-frag program. It works exactly the same as trying to add shadows to a custom shader. Just need to use the Unity built-in shadows macros provided in AutoLight.cginc and you are good to go, magic happens afterwards. :cool:
    Note: You don't need to reference NGSS AutoLight.cginc path in your shader, you just add #include AutoLight.cginc in your shader as you would normally after setting up NGSS.
     
    Last edited: Jan 14, 2018
  4. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,353
    More on update 1.7.
    This version features a new robust Bias_Fade algorithm for all shadow types, demonstration on directional lights (can be seen at the end of the video):

    Also, Directional shadows are slightly faster and prettier than before. No more directional depth duplication and copy, etc. Shadows can now be a lot softer without breaking the Early_Bailing_Out algorithm. Macro artifacts are 99% gone, even on super wide soft-shadows.

    Still working out the cascade issue in Unity 2017, I'm trying to find a solution for proper cascade blending with StableFit projection. On top of that there's a new issue introduced in 2017.3 for point light projection matrix, where near plane value is always hardcoded to 0.1, this causes some minor artifacts if shadow bias is very low (can be avoided by tweaking the bias properly though).
    Will probably ship v1.7 like this and workaround these in v1.8+.
    [EDIT]
    Got a confirmation from Unity folks about the intrinsic hardware optimization for NGSS 2.0 and it's in! So that's a mega huge news! :)
     
    Last edited: Jan 14, 2018
  5. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,353
    Aggressive early bailing out algorithms demonstration v1.7:


    - The noisy dark region around the penumbra area are fragment discarded
    - The noisy white spots inside shadows are fragments being discarded
    - The white squares around dark squares are point light faces being culled

    Notice only the penumbra area is computed, fragments fully lit or fully shadowed are totally discarded using dynamic branching. This saves filtering and improves performance by around 2-3 even 4 times fold (depending on hardware).
    Submission to Asset Store (tonight/tomorrow). :)
     
  6. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,353
    Folks,
    Version 1.7 have been submitted to the Store. If you want to get your hands today on it, email support. :)
    Regards,
     
    No0B25, EvilFox, zmaxz and 3 others like this.
  7. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,353
    Guys,
    Version 1.7 is live on the store. A couple of things about it.
    Since version 1.7, you only need to replace UnityShadowLibrary.cginc, Mobile directional shadows and desktop directional shadows are all independent installs.
    Known issue (discovered today): If you are running Unity 2017.1 and update to NGSS 1.7, you may notice some artifacts with PCSS algorithm (Soft-Shadows option) when the penumbra is really big. I forgot that point light depth buffers where inverted in 2017.3 and left the previous version of the algorithm with buffers reverted this the PCSS fails out with dark shadows at the wrong place.
    I've already submitted v1.7.1 that fixes the issue and don't worry, it looks exactly the same as in the preview video for all Unity versions. Sorry for the inconvenience. :)
    PS: Version 1.7.1 should be live on the Store sometime tomorrow or Friday.
    [EDIT] You can email support right now if you need v1.7.1.
     
    Last edited: Jan 17, 2018
    Baraff and brisingre like this.
  8. zmaxz

    zmaxz

    Joined:
    Sep 26, 2012
    Posts:
    143
    Unity5.65 NGSS1.7
    Get this error :
    Shader error in 'Hidden/NGSS_Directional': Fragment program 'frag_ngss': sampler 'my_point_clamp_smp2' has no matching texture and will be undefined.
    (on d3d11)

    Compiling Fragment program with SHADOWS_SPLIT_SPHERES NGSS_PCSS_FILTER_DIR DIR_POISSON_32 NGSS_USE_EARLY_BAILOUT_OPTIMIZATION_DIR NGSS_USE_BIAS_FADE_DIR
    Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING SHADER_API_DESKTOP UNITY_HARDWARE_TIER3
     
  9. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,353
    @zmaxz
    NGSS 1.7 is not compatible with Unity 5.6. You can keep using NGSS 1.6.x in 5.6 though. The reason is that there's no inline sampling support in Unity 5, It was introduced in 2017 and all NGSS shadows (not required for Mobile shadows) now requires inline sampling, for better performance, quality and proper filtering.
    You can also notice that the package was uploaded using Unity 2017.1, for that same reason.
    PS: You can email support to grab any older version though.
     
    Last edited: Jan 17, 2018
  10. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,502
    I noticed in 2017.1 release notes it says Vulkan does not support inline samplers yet, do you know if they added Vulkan support for it in 2017.2 or .3 ? Didn't see it mentioned in their release notes. Otherwise I guess that means can't use this for builds relying on Vulkan either.
     
  11. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,353
    @Invertex
    Inline Samplers requires SM3.5 feature level:
    https://docs.unity3d.com/Manual/SL-ShaderCompileTargets.html
    If I'm not mistaken it's already in 2017.3. Not sure about 2017.2 though.

    [EDIT] Just saw an email from Unity renderer guys, they said support for Inline Samplers in OpenGL and Vulkan API's are planned for Unity 2018 and NGSS already works with Unity 2018 (default renderer).
    If you are targeting Vulkan right now you can fall back to PCF sampling in NGSS.
     
    Last edited: Jan 17, 2018
    alternativevisual and Invertex like this.
  12. ceebeee

    ceebeee

    Joined:
    Mar 7, 2017
    Posts:
    395
    I upgraded to 1.7, but I notice the NGSS_NoiseTexture.cs file is missing. Is that depreciated with the new system?
     
    tatoforever likes this.
  13. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,353
    @ceebeee
    Yes,
    NGSS stared using an internal noise texture which is generated by Unity on the fly a couple of major versions back. Not needed anymore. ;)
    Btw, ask support for the new NGSS 1.7.1. There's a small issue fixed with point light shadows if you have Unity 2017.2.x or Unity 2017.1.x
     
    Last edited: Jan 17, 2018
    ceebeee likes this.
  14. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,353
    Some info about Unity 2017.3 (and 2018 beta):
    In version 2017.3 Unity changed the way point light shadows are encoded/decoded. It's no more a cubemap, instead a depth_cubemap (which provides a RF32 single precision channel RT). Also this buffer is reversed and needs to be decoded in light space (instead of world space as before). This is actually very good for better point light shadows, more precision for the same amount of memory (RF32 > R8G8B8A8) for depth maps.
    The bad thing, I discovered a point light projection bug in this new version (Unity 2017.3). It seems they hardcode a clipping value that interfere with bias (probably in the projection plane) when encoding shadows into the depth_cubemap.
    The results of this: you will probably notice a higher bias.
    As you know, NGSS 1.x uses default renderer data (matrix, buffers, arrays, constants, defines, etc) and there's nothing i can do about it as I don't have access to how this data is created (default renderer is a black box).
    I've already submitted a bug case showing the issue. Hopefully they will get back to me asap.
     
    alternativevisual likes this.
  15. danix

    danix

    Joined:
    Nov 15, 2013
    Posts:
    29
    Hey,

    I've updated to the latest version and the noise is back. In the previous version I've used #define NGSS_USE_STATIC_NOISE to make less noisy shadows, but now its not working, also banding noise value and bias fade value doesn't seem to be working on mobile. Any advice?

    Thanks!

    Capture.JPG
     
  16. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,353
    @danix
    Comment the #define NGSS_USE_POISSON_SAMPLING_MOBILE at line 26 (AutoLight.cginc).
    It will give you the same exact behavior as the old NGSS_USE_STATIC_NOISE
     
  17. danix

    danix

    Joined:
    Nov 15, 2013
    Posts:
    29
    This is with disabled #define NGSS_USE_POISSON_SAMPLING_MOBILE

    PS: It was softer in the previous version, using the static noise option.
    Capture.JPG
     
    Last edited: Jan 17, 2018
  18. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,353
    @danix,
    Sorry, that won't do anything, now that I remember NGSS_USE_STATIC_NOISE was sampling the noise texture which was an overhead on Mobile that's why I removed it. But if you want that behavior back, I will re-add it in next version.
    Send an email to support, I will give you the modified file now.
     
  19. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,353
    @danix
    I just tried without the poisson sampling and I have exactly the same behavior as before.
    With NGSS_USE_POISSON_SAMPLING_MOBILE undefined (same as NGSS_USE_STATIC_NOISE):


    Now with NGSS_USE_POISSON_SAMPLING_MOBILE defined:


    You need to lower your shadowmap resolution to get the same results. If your shadow map resolution is too high then you better enable NGSS_USE_POISSON_SAMPLING_MOBILE (enabled by default).
     
  20. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,353
    @danix
    I see what your problem is, this is not NGSS shadows, this is Unity baked shadows:


    NGSS shadows and baked shadows have different filtering and Unity baked shadows uses very basic and ugly shadows filtering.
     
  21. danix

    danix

    Joined:
    Nov 15, 2013
    Posts:
    29
    No baked shadows its all dynamic shadows

    Shadows.JPG
     
  22. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,353
  23. danix

    danix

    Joined:
    Nov 15, 2013
    Posts:
    29
    No problems with NGSS on a PC platform, my project is for Mobile build, I'll send it to you in a minute.
     
    tatoforever likes this.
  24. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,353
    @danix
    I'm gonna add back the static noise mobile behavior but first I'm gonna make sure we both have the same shadows (behavior/visuals) on both ends.
    PS: Yes, send me the project through support email, I'll test with that (I got Android and iOS modules installed).
     
    danix likes this.
  25. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,353
    Version 1.7.2 submitted to the store.
    Features and changes:
    - Added Static Noise filtering to Mobile shadows
    - Fixed a portability issue with Mobile Shadows library
    - Mobile Shadows works again on SM2.0* hardware
    Note: SM2.0 only supported on Mobile Directional Shadows with Cascaded Shadows turned off. Plus, shaders must be simple (not too many instructions) or you will get shader limits errors. For that reason, we recommend SM3.0+ on Mobile.
     
    osss and danix like this.
  26. kurzemnieks

    kurzemnieks

    Joined:
    Nov 22, 2012
    Posts:
    16
    I'm getting shader compilation errors after update:
    syntax error, unexpected ';' at token ";" type name expected at token ";" at /UnityShadowLibrary.cginc(44) (on d3d9)
    And warnings:
    unrecognized profile specifier "my_point_clamp_smp" unrecognized profile specifier "SamplerState" at /UnityShadowLibrary.cginc(44) (on d3d9)

    what might be wrong?
     
  27. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,353
    Since v1.7, NGSS requires inline sampling support which is only available in Unity 2017/2018 with SM3.5 and up. DX9 does not support neither of those. Remove DX9 from your target API (Player settings) and it will work fine.
    APIs that support SM3.5:
    https://docs.unity3d.com/Manual/SL-ShaderCompileTargets.html
     
  28. kurzemnieks

    kurzemnieks

    Joined:
    Nov 22, 2012
    Posts:
    16
    Tried everything, - set API manually to DX11.. Shader target to 5.0 in my shaders - still got error compiling all shaders :/
    Downgraded to old version.
     
  29. kurzemnieks

    kurzemnieks

    Joined:
    Nov 22, 2012
    Posts:
    16
    And I'm using 2017.3 where Dx9 is deprecated anyway (not even available in Player settings menu)
     
  30. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,353
    Some of your shaders are DX9, otherwise you wouldn't had that error. You have to edit them and set them to something higher than SM3 or you will get compile errors because there's no inline sampling support neither DX9 support in Unity 2017.
    Did you deleted your ShaderCache folder after editing your shaders?
     
    Last edited: Jan 19, 2018
  31. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,353
    @kurzemnieks
    Create an empty project in 2017.3 and import NGSS on it. You should not get any error.
     
    Last edited: Jan 19, 2018
  32. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,353
    NGSS - Directional Shadows StableFit Projection aka (Sphere Split) CascadeBlending (Update coming very soon):

    Can optionally be enabled and tweaked within NGSS_Directional component.
     
  33. N00MKRAD

    N00MKRAD

    Joined:
    Dec 31, 2013
    Posts:
    210
    Oh man, I just wanted to request a feature; blending the cascades smoothly, then I realized you already implemented that.

    Amazing job, cascades are good but look S***ty without fading/blending.
     
    Flurgle and tatoforever like this.
  34. kurzemnieks

    kurzemnieks

    Joined:
    Nov 22, 2012
    Posts:
    16
    Well, I can edit my shaders, but what about different assets and effects we are using from Asset Store?
     
  35. buttmatrix

    buttmatrix

    Joined:
    Mar 23, 2015
    Posts:
    609
    I already own this asset, but I would re-purchase for this feature alone. Thank you x10
     
    Flurgle and tatoforever like this.
  36. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,353
    @kurzemnieks
    Normally you only have to edit shaders that are explicitly marked as "#pragma target 2.0/3.0", the rest will work, even without the explicit pragma target as it compiles automatically to your chosen API. I can do it for you if you pack me all your shaders in a package or a project.
     
    Last edited: Jan 19, 2018
  37. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,353
    Folks,
    I'm adding some modifications that skips inline sampling in NGSS and adds SM3 support. If your platform only support SM3 you lose the PCSS filtering (Area-like soft-shadows) as it requires inline sampling which is only available starting on SM3.5. Only PCF filter (uniformly soft-shadows) will be available until you force all your shaders to be #pragma target (at least 3.5 or higher) shader level.
    For more info about SM3.5 support on platforms:
    https://docs.unity3d.com/Manual/SL-ShaderCompileTargets.html

    Note: Unity 2017 still a requirement since v1.7. If you need older versions compatible with Unity 5, please email support.

    I also removed all multi_compile shader variants in NGSS code as they aren't really needed. It will make all your shader variants extreme small and compile faster. ;)
    Added a couple of new optimizations in Directional Shadows when PCSS is off.
    I'm doing some small touch ups to the CascadeBlending and looking the point shadows projection issue introduced in 2017.3 with Unity folks.
    After that it should be good to ship the Update.
     
    Last edited: Jan 20, 2018
    alternativevisual likes this.
  38. ceebeee

    ceebeee

    Joined:
    Mar 7, 2017
    Posts:
    395
    I'm starting to have this shader compile issue a lot as well. But changing the #pragma target doesn't help at all. Is there something else that must be done? The error message isn't very clear at all. (same as what kurzemnieks reported)

    I'm using Unity 2017.3.0p2 and of course it's impossible D3D9 is enabled as it's not supported.
     
  39. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,353
    @ceebeee
    Looks like Unity still have the d3d9 compiler in 2017.3, they just removed the option from the Player settings but indeed they does have it and obviously it will fail compile.
    I added in the next version some compiler directives workarounds to avoid Unity compile to d3d9 or any other unsupported platfom. Email support if you need it.
     
  40. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,353
    Folks,
    On top of Cascade Blending, full Cascade Shadow Map support on Mobile is coming to the next NGSS version.
    Metal simulator (PCSS filter):


    GLES 3.0 (PCSS filter):


    Also, no more need to install AutoLight.cginc as NGSS_Directional works on all platforms now, including support for PCSS (on Mobile requires GLES3.0, Metal or Vulkan).
    Requires Cascaded Shadows enabled in Graphics settings.
     
    Last edited: Jan 20, 2018
    toto2003, danix and brisingre like this.
  41. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,353
    NGSS Cube shadows bias improvements also landing in the next version. To demonstrate the technique shadow bias was set to zero and shadows strength (softness) is zero (notice the absence of z fighting in shadow receivers):
     
  42. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,353
    Version 1.8 is almost ready.
    - Full support for shadows Mobile (No more need to install AutoLight.cginc works as in Desktop)
    - Cascade Blending for all shadows projections (Stable and CloseFit)
    - Improved Directional noise filtering, static noise filtering now public (see video below)
    - Improvements to point light shadow bias
    - Added compatibility to SM3 APIs on supported platforms. If your GPU can't support inline sampling, it will chose the SM3 path automatically. This means only PCF filtering as inline sampling is required for PCSS filtering
    - Contact Shadows opacity improved (both contact shadows and directional shadows match opacity perfectly)
    - Refactored/Optimized all shadow code (Also added a couple of fallbacks for old APIs/Platforms where NGSS can't run properly)

    Improvement to noise filtering in v1.8:


    PS: Submission will happen tomorrow night.
     
    Last edited: Jan 21, 2018
    hopeful, No0B25, Lex4art and 4 others like this.
  43. GreenHatJohn

    GreenHatJohn

    Joined:
    Nov 27, 2014
    Posts:
    8
    Hello,
    My team's project has been using this plugin for point/spot lights and it's been working great so far. Just updated to 1.7.2 and getting the following runtime error:

    Code (CSharp):
    1. Shader error in 'Hidden/Internal-DeferredShading': undeclared identifier '_LightProjectionParams' at /Program Files/Unity5/Editor/Data/CGIncludes/UnityShadowLibrary.cginc(534) (on d3d11)
    2.  
    3. Compiling Vertex program with POINT SHADOWS_CUBE
    4. 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 SHADER_API_DESKTOP UNITY_COLORSPACE_GAMMA UNITY_LIGHT_PROBE_PROXY_VOLUME
    Our Unity version is 2017.2.0f3
    I closed the editor, re-imported the most recent UnityShadowLibrary.cginc file and deleted my project's shadercache folder before relaunching the engine.
     
  44. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,353
    @GreenHatJohn
    Close Unity, comment that same line (534) in UnityShadowLibrary.cginc and delete your ShaderCache folder. It should work afterwards.
    This have been fixed in the next version already.
     
  45. GreenHatJohn

    GreenHatJohn

    Joined:
    Nov 27, 2014
    Posts:
    8
    Thank you I'll try that! I'll also just download the new one if it doesn't work.
     
    tatoforever likes this.
  46. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,353
    @TheSpecialDuckling
    That is kinda expected as I've not yet finished porting NGSS 1.x to 2018 but just in case, are you using NGSS 1.7.2 from the store? Did you deleted your project ShaderCache folder after installing NGSS?
    What happen if you just replace UnityShadowLibrary.cginc and not AutoLight.cginc, does it work?
     
  47. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,353
    @TheSpecialDuckling
    I just re-tested v1.7.2 and no it doesn't work properly in Unity 2018 but NGSS 1.8 coming next week already support Unity 2018.
     
    buttmatrix likes this.
  48. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,353
    Folks,
    Can't remember exactly who requested it but I also fixed an opacity discrepancy between ContactShadows and Directional shadows. It happens when you where tweaking Directional Shadows strength, it's fixed in 1.8. :)
    PS: I wrapping up final touches on Spherical blending and we should be good to submit.
     
    hopeful and Baraff like this.
  49. nbac

    nbac

    Joined:
    Jul 7, 2015
    Posts:
    267
    capsule shadows *cough* *when*
     
    buttmatrix likes this.
  50. Lex4art

    Lex4art

    Joined:
    Nov 17, 2012
    Posts:
    445
    PCSS (then smoothness maxed out) can emulate this nicely i guess, did you test it?