Search Unity

  1. Get the latest news, tutorials and offers directly to your inbox with our newsletters. Sign up now.
    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. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    10,230
    Any progress on directional lights?
     
  2. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,083
    I'm currently experimenting with our Monte Carlo filter on screen space and light space. The Monte Carlo output looks more stable screen space but requires an additional special texture (and setup to the scene) to make it work. Light space directional shadows are easier to filter but the integration within Unity built-in cginc files it's a bit hairy (also requires the user to turn off screen-space directional shadows filter). I kinda want to try both and see which one looks better but also doesn't cause any trouble within users existing shaders/frameworks.
    So far spot and directional shadows won't be able to properly support PCSS (only the approximated variant) and the reason is that it's not possible to force Unity change the texture format for our shadowmaps which prevent me to get access to rawdepthmaps and blocker search algorithms requires raw depthmaps to manually compare distances. Already asked Aras if there's a way to force the renderer to create depthmaps instead of shadowmaps and isn't possible, if the renderer detects the platform doesn't support hardware bi-linear filtering on shadowmaps, it will switch to depthmaps. There's a way to access light shadowmaps by duplicating every lights shadowmaps but this is kinda unusable if you are working within the built-in renderer cginc files because we don't have access to lights indexes plus the fact that it doubles your GPU ram and bandwidth. If I'll be working with the Unity renderer I would have added somewhere an option to force depthmaps. Silly limitation tbh. :\
    Thought, the battle isn't lost yet, point lights shadows have both PCSS and approximation, you still have the approximated variable penumbra size filter for spot/directional shadows, you still be able to tweak softness amount and once Unity switch their renderer to ScriptableRenderLoops it will be possible as all the light indexes and texture formats are exposed on it (I'm already experimenting with). :)

    Upcoming update to NGSS, I'm adding more options to the current filtering quality (in-case you want more shadows quality at the expense of a GPU meltdown) with more bruteforce sampling. I'm also adding a Crysis1 shadowmap filtering, this produces 100% stable kernels at the expenses of visible noise (still better than shadow aliasing and banding tbh). So yeah more shadow filters to all lights and more performance/quality options. :D

    Lastly, I have other crazy ideas in mind such as filter whole scene shadows to a off-screen buffer and do a full screen-space filter on them (using temporal directional/distance buffers to compute penumbra size properly) but so far it won't be possible without access to current Unity renderer source code (same reason), though it's 100% doable with ScriptableRenderLoops but right now it's only on paper. Other than that system: shadowmap atlasing, rendering only movable objects and rendering static objects once are also some heavy optimizations ideas that I'll implement in the future. ^^
     
    Last edited: Feb 5, 2017
    Seith and Lex4art like this.
  3. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,083
    Folks,
    The asset is live! :)
    https://www.assetstore.unity3d.com/#!/content/79454
    If you need any help, I'll be lurking the thread or contact me through email: support [at] psychozinteractive [dot] com.

    PS: And don't forget the documentation, you must read it! :cool:
     
    ikazrima likes this.
  4. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    7,510
    Annnnd bought.
     
    tatoforever likes this.
  5. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,083
    That was quick! ^^
     
  6. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,083
    If you guys can post images or small videos sequences of your games with NGSS shadows. I'm dying to see how it looks on it. :)
     
  7. punk

    punk

    Joined:
    Jun 28, 2013
    Posts:
    390
    Tis pretty

    without.png with.png

    I am noticing an issue tho

    to get the shadows looking nice I'm having to increase my shadow resolution to at least high otherwise I'm getting artifacts, using .2 on the shadow strengh

    eg.

    1.jpg

    notice the vertical lines and below at low resolution

    2.jpg

    and strangely with soft shadows on it's less softer

    3.jpg

    it does blend away a bit when using a higher strengh

    using deferred rendering - 5.5.1f

    any Ideas?
     
    Lex4art and tatoforever like this.
  8. ikazrima

    ikazrima

    Joined:
    Feb 11, 2014
    Posts:
    312
    Going on my wishlist first till I got some spare cash :)
     
    tatoforever likes this.
  9. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,083
    @punk,
    This is a normal shadowmap artifact called shadows acne, try rising the shadow bias value to something close to 0.1 or higher.
     
    Last edited: Feb 7, 2017
  10. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,083
    @punk,
    To make it a bit more clear. With NGSS both shadows mode are soft (Hard and Soft) but on Point lights setting Shadows Type to Soft will enable the PCSS filtering (which auto adjust penumbra size a bit more physically correct).
     
    Last edited: Feb 7, 2017
  11. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,083
    @punk,
    If you don't want to mess too much with your lights setup, try this settings:
    - Set your shadows type to Hard-Mode (with NGSS both modes produces soft-shadows).
    - Set shadows strength (soft-ness) between 0.1 and 0.5
    - Set shadow bias to 0.05 (and rise it till shadows acne disappears)
    - Don't lower shadow near-value too much (specially if your objects will never get too close to that light), otherwise you will lose shadowmap precision at long ranges.

    PS: On point-light shadows try to set Shadows type Soft-Shadows (it will enable PCSS filtering on it).
    PS: Let me know if it's clearer now. Your picks looks amazing btw.
     
    Last edited: Feb 12, 2017
  12. punk

    punk

    Joined:
    Jun 28, 2013
    Posts:
    390
    I'm aware of shadow acne, I should have mentioned it remains regardless of the settings, ie changing the bias does nothing. I just tested it in a clean scene though and it works fine, so its caused by another plugin I'm using, its a big game, so I'll let you know if I get to the bottom of it
     
  13. punk

    punk

    Joined:
    Jun 28, 2013
    Posts:
    390
    Thanks bro, soft shadows penumbra effect looks beautiful!
     
    tatoforever likes this.
  14. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,083
    @punk,
    Let me know if you need any help with. Maybe I could help somehow. :)
     
  15. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,083
    @punk,
    Oh yeah, forgot to mention that the best way to test shadows is within your game final lighting as high frequency details will always help masking shadows artifacts. And post more images of your game with NGSS, it looks really awesome. :)
     
  16. punk

    punk

    Joined:
    Jun 28, 2013
    Posts:
    390
    Thanks I'll do some tests ;)
     
    tatoforever likes this.
  17. punk

    punk

    Joined:
    Jun 28, 2013
    Posts:
    390
    yeah definitely, will post some more pics once I've had more of a play :)
     
  18. punk

    punk

    Joined:
    Jun 28, 2013
    Posts:
    390
    I thought I had it figured out, more testing needed
     
    Last edited: Feb 7, 2017
  19. punk

    punk

    Joined:
    Jun 28, 2013
    Posts:
    390
    @tatoforever OK I've isolated the issue, it gets a load of acne on any object using Toms UBER framework, see left standard shader works fine, middle with UBER = acne and on the right UBER with the shadow bias turned up, acne is still there.

    Now I realize it could be something I need to change in the UBER framework, but I'm not sure what and I wouldn't know what to ask tom. Any ideas? all the other shaders I'm using appear to be working fine so far

    uber.jpg
     
  20. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,083
    @punk,
    It looks like UBER is doing something with the shadows bias internally. I got a copy of UBER framework, if you can email me a copy of that scene with the same models and materials I'll do an investigation and update the thread with any possible solution.
     
    Last edited: Feb 7, 2017
    punk likes this.
  21. CodeBison

    CodeBison

    Joined:
    Feb 1, 2014
    Posts:
    254
    Note: My game is a Vive game. My findings below will only apply to people using this asset in VR applications.

    Just tried this out. It looks great, but initial tests lead me to believe I probably won't be able to use it for performance reasons. Even on hard with lower shadow resolution I'm seeing a significant performance hit when large chunks of the view are affected by point light shadows. The issue is ameliorated significantly if I reduce supersampling, but I imagine lower end hardware would still have significant problems. From what I see, I seem to be hitting a fill rate limit.

    If it were possible to enable/disable this effect at runtime, I'd be able to use this as an "ultra" shadow setting. As is, its usefulness to me will likely be limited unless the performance issues I'm seeing can be addressed.

    My hat's off to you though - it looks great!
     
  22. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,083
    @CodeBison,
    Can you describe the hardware you are using (GPU, CPU, etc) which Unity version, Unity Editor/Player, etc?
    Also, can you describe a little bit the scene you are working on, number of point light shadows? If possible paste few images of your scene? What other effects are you using on your scene/camera?
    Lastly, are your lights being culled properly (how many lights at once cast point-light shadows)?
    PS: Have you tried using the NGSS approximated variant on point-light shadows (set Shadows Type to Hard-Mode)?
     
  23. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,083
    @CodeBison
    Lower-end hardware should not have super-sampling enabled as it requires more memory and bandwidth. In fact, lower-end hardware should have bare-minimum camera effects, specially on VR. Upcoming UnityHDR renderer will support only 3 point light shadows visible at the same time. They are by nature really heavy, one point shadows equals 6 spot shadows. :\
    In the next version of NGSS, I'll provide up to three shadows quality mode so you'll be able to chose lower sampling or higher sampling rates. This however, will be changed globally (in a per-scene basis) instead of per-light basis.
     
  24. CodeBison

    CodeBison

    Joined:
    Feb 1, 2014
    Posts:
    254
    I only user supersampling for higher end video settings. My observations regarding NGSS are that a scene that renders at 1.3x supersampling on my GTX 1080 with a 7ms frame time with stock Unity soft shadows (very high resolution) renders in 15+ms with NGSS soft (full strength, same detail level), and about 9ms with NGSS hard and low shadow detail.

    I want to be clear. I'm not intending to diss NGSS. I'm just reporting on the VR-specific performance I'm seeing relative to stock Unity shadows.

    It should be noted that I haven't tested yet with any of the Unity 5.6 lighting mode changes. I expect the mixed lighting modes in 5.6 might improve things somewhat, but I won't have time to test for a while. My testing thus far has been with full dynamic shadows, with every light a realtime shadow caster. I know this is an unconventional choice, especially in VR, but I have my reasons for making the choices I did, and I've carefully balanced several things in my game to make the fully dynamic lighting work well.

    General observations so far:
    • Hard is more performant than soft, as expected.
    • Lower strength (less softening) reduces performance impact.
    • Large shadowcasters near the camera have a very high performance impact when compared to stock Unity shadows, especially at higher shadow resolutions.
    The quality mode settings you mention might be helpful, if I understand you correctly. I look forward to testing them.

    From your previous posts, I think I remember you saying it wasn't really possible to switch between NGSS and stock Unity shadows at runtime. Is this correct?
     
  25. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,083
    @CodeBison,
    Are you using simplepass rendering with your VR project? If you are rendering the scene twice once per eye then yes, performance will suffer a bit, not only with shadows but with anything that renders on the screen.
    Have you tried turning off super-sampling and try other less heavier AA methods?
    As for quality mode, I'm working on a 4 sample + bilinear filter that should give you some speed for low-end hardware in VR. Keep in mind that low-end hardware for VR is not the same thing as low-end hardware for normal PC gaming. VR requires at minimum 1070GTX or equivalent on any graphically driven game to run at acceptable framerates.
    I already got a working version of NGSS running on 5.6 (there's a video on first page), will probably submit to the asset store before NGSS v1.2.
    PS: If you can post any videos or images of your game with and without NGSS, I'll be happy to see them! :)
     
  26. punk

    punk

    Joined:
    Jun 28, 2013
    Posts:
    390
    tatoforever likes this.
  27. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,083
    @punk,
    I got the package, tomorrow I'll give it a go and will reply here with my findings. :)
     
    punk likes this.
  28. CodeBison

    CodeBison

    Joined:
    Feb 1, 2014
    Posts:
    254
    I use singlepass, yes. I allow the player to choose supersampling, AO, AA, shadow detail size, and a few other things like whether projectile lights cast shadows. The idea is that those with higher end systems can turn on most of the bells and whistles (AO is expensive even on a 1080), and lower end users can choose what kind of visual tradeoff they want. I use my super sampling settings locally to ensure what I design will run on lower end hardware, though. So basically if it works at 1.3x on my 1080, it will probably be okay at 1.0x on lower end hardware due to fill rate differences. So I need to get equivalent performance with NGSS, with all other settings the same, in order to be able to ship with it comfortably (ie I need to be able to ship with NGSS settings that give me the same performance as stock soft Unity shadows).

    While I wish I could assume everyone playing my game will have a 1070 or better, the reality is there will be several with 970 or lower. So I need to have decent looking options that support that (unfortunately :p). It sounds like the new filter you're working on will help though.

    I'll get a few screen shots when I have some more time for testing. It may be a couple days.

    Cheers!
     
  29. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,083
    @CodeBison,
    Yeah I believe if the game runs ok on your 1080GTX it will be slower on low-end hardware no matter what and that's normal tbh. I think it's a bit misleading to run the game at max quality 1.3x and expect to run fine on weaker hardware. Because no matter how powerful your GPU is, you will hit the bandwidth bar going with higher resolutions.
    Supersampling as AA it's extremely heavy, I would suggest to look for other techniques as well for lower-end hardware. We have a mid-range test unit with a 1070 running our current game at around 400-550fps with multiple point-light shadows and spot-light shadows at once but we don't have AO and uses TAA as anti-alias, we can still add more lights with shadows and it will runs ok.
    PS: I'll keep you updated on the upcoming 4sampling feature (email me if you want a pre-release version).
    Regards,
     
    Last edited: Feb 12, 2017
  30. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,083
    @punk
    I debugged UBER shaders and I've discovered where the problem comes and fixed it. As I expected, it was his shadow collector pass, he forgot to add the bias term for point-light shadows collection. Prof or it never existed: ^^



    Here's the solution:
    Open the file "UBER_StandardShadow_Tessellation.cginc" located on "Assets/UBER/Shaders/Includes"

    Look for the line 625:
    Code (CSharp):
    1. return UnityEncodeCubeShadowDepth((length(i.vec)+rayLength) * _LightPositionRange.w);
    And replace it by this one:
    Code (CSharp):
    1. return UnityEncodeCubeShadowDepth((length(i.vec)+rayLength + unity_LightShadowBias.x) * _LightPositionRange.w);
    Then re-import your UBER/Shaders folder.
    PS: I've contacted Tom and informed him of the issue with his shadow collector pass and gave him the fix, here.
    Regards,
     
    Last edited: Feb 8, 2017
    one_one, punk and hopeful like this.
  31. punk

    punk

    Joined:
    Jun 28, 2013
    Posts:
    390
    Thanks bro!
     
    tatoforever likes this.
  32. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,083
    @punk,
    Silly me, I forgot that you have to re-import your UBER/Shaders folder after making modification fix on UBER_StandardShadow_Tessellation.cginc, because is not a shader, it's an include file. ^^
     
    punk likes this.
  33. punk

    punk

    Joined:
    Jun 28, 2013
    Posts:
    390
    Works perfectly
     
    tatoforever likes this.
  34. CodeBison

    CodeBison

    Joined:
    Feb 1, 2014
    Posts:
    254
    Yeah, my scenes run at about 400-700FPS when I'm just rendering to desktop. It's the added fill rate for VR that's the killer.

    Re: 4sampling - sounds good. Thanks!
     
  35. Flurgle

    Flurgle

    Joined:
    May 16, 2016
    Posts:
    389
    Very cool! Solves the "jaggies" issue in Unity.

    Got it working in 5.6.0b7 beta, had to add some functions from the original shadow shader.


    Would it be practical to add blurring like in ambient occlusion shaders? That is probably what would make this perfect. In bright light conditions, you can easy see the pixels in the shadows.
     
    tatoforever likes this.
  36. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,083
    Hi Furgles,
    Filtering shadows it's a complex process, more complex than filtering anything else. For example, with Ambient Occlusion effect, we can easily use a number of hardware filterable textures, once we are done with raymatching the screen depth, it all gets accumulated in that texture which will then be filtered by the hardware upon display. Unfortunately with shadows, filtering is a bit different than than let's say any screen-space effect. Main reason, you are dealing with depth/shadow maps that even if the GPU can filter they are used as distant determination factor (to compare distance between surfaces receiving shadows and surface blocking lights) plus you are also dealing with a different view perspective (light space) vs screen-space.
    Though, I got something on mind that will speed the filtering of all shadows (any number, any type) in one single pass, all done screen-space. It's a sort of deferred shadows but for any number and type of shadows with support for PCSS and contact shadows out of the box. As of now is not possible without access the Unity built-in renderer sources, it's possible with ScriptableRenderLoops though, I've already started experimenting with. :)
     
    Last edited: Feb 9, 2017
    Flurgle likes this.
  37. id0

    id0

    Joined:
    Nov 23, 2012
    Posts:
    404
    Hello. I don't know how the bias work, but is it possible do something like this?
    Bias.jpg
     
  38. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,083
    Hi,
    You want to interpolate bias based on light distance?
     
  39. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,083
    @id0,
    Current methods to mitigate bias issues are normal based, linear and distance based (the one you've described). None of them are perfect and it's hard to say which one will work better under any situation (scene setup). Adjusting bias is a matter of adjusting lighting conditions in your scene. Normal based is the one that works better and Unity is using it with directional shadows (only).
    Right now, NGSS provides a way to control bias a little bit more, you can go closer to no bias at all if you want (sometimes preferable than Peter-Panning with high frequency details on your surfaces). Upcoming version of NGSS will provide more improvements to bias.
     
    id0 and Flurgle like this.
  40. Flurgle

    Flurgle

    Joined:
    May 16, 2016
    Posts:
    389
    @tatoforever very exciting to see where this goes.

    Thank you for the response above, definitely makes sense. ALSO, it would be nice if unity could produce custom GUI handles for shadow shadows in the Light Component. That way you could probably give us a lot of the internals to tweak and create presets for (unless possible already, I haven't seen it).
     
    tatoforever likes this.
  41. id0

    id0

    Joined:
    Nov 23, 2012
    Posts:
    404
    I see, thanks for the answer :)
     
    tatoforever likes this.
  42. Flurgle

    Flurgle

    Joined:
    May 16, 2016
    Posts:
    389
    These shadows are beautiful.

    Last night I created this low poly scene using NGSS (2 spotlights projecting shadows, and 1 point light with no shadows for extra ambiance).

    https://gfycat.com/RaggedBonyBoubou


    (Not really ngss related, but I wish pointlights shadow settings worked the same as spotlights :( They are not as large and soft as spotlight shadows.)

    Here's a closeup:
    https://gfycat.com/CalmAromaticAmericanrobin



    Keep up the good work! Awesome accessible pricing too.
     
    tatoforever likes this.
  43. Flurgle

    Flurgle

    Joined:
    May 16, 2016
    Posts:
    389
    Woops, those gifs must be too big, here we go:

    Full candlelit "romantic" living room scene (Might use this for valentines game jam) all using NGSS, without any noticeable performance hit.
    living room shadows short 2.gif

    Close up of middle chair shadow
    chair shadow short.gif

    Close up of sofa shadow
    sofa shadows short 2.gif
     
    macdude2, ikazrima, punk and 2 others like this.
  44. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,083
    @Flurgle
    Point light settings will always differs because we deal with directions to sample shadowmaps (instead of positions as for directional/spot shadows) and it's a little bit more costly on the GPU to get similar results although I've made them share same internal data as possible to unify them as much as possible. But still, the main reason we must be careful with point light shadows is that one point shadows equals 6 spot shadows. Also by default point-light shadows resolution is always half ress of spot light (and it all depends on your GPU ram), if you have little ram, Unity will reduce shadowmap sizes.
    Upcoming NGSS shadow features will let you chose a higher quality version to add more samplings on your shadows, this will help cover extreme cases where light rays are really sparse and fill more gaps in-between sampled shadows.
    PS: Really nice shadows, love the light flicker btw.
     
    Flurgle likes this.
  45. Flurgle

    Flurgle

    Joined:
    May 16, 2016
    Posts:
    389
    Awesome explanation, and of course that rant above had nothing to do with NGSS just shadows point lights in general are not as "intuitive".

    Thank you, and definitely looking forward to that
     
    tatoforever likes this.
  46. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,083
    @Flurgle,
    Indeed, point-light shadows as cubemap are a bad Idea tbh. First thing is that it creates GPU memory fragmentation due to the fact that other shadows type uses different textures types and it's slower to access. Quite often you don't need to cast shadows from all 6 sides (eg: lights very close to large objects only needs 3 sides). They are also harder to filter (directions instead of uv positions) and less hardware support for it. Nowadays engines are simply creating one very-large depthmap atlas and unfolding all point, spot and directional shadows there. Fortunately, ScriptedRenderLoop will allow us to get into that.
    The system I'm working on, will allow you to selectively enable point-shadows sides. It is safe to say that the hardest part will be connecting this new shadows system with existing shaderframeworks (as NGSS does). Benefits over NGSS are plenty, huge optimizations, shadows atlasing and filtering at once, encoding depth only for objects moving (reusing non-moving ones), etc. :)
    Regards,
     
    Last edited: Feb 9, 2017
  47. Flurgle

    Flurgle

    Joined:
    May 16, 2016
    Posts:
    389
    BTW, if there's anyone using this asset, but wants to keep the old shadows too, here's what I do:

    1) duplicate your unity install folder eg C:\Program Files\Unity 5.6.0b7 and rename the new copy to "Unity 5.6.0b7 with Soft Shadows"
    2) create a new Unity shortcut for this copy (eg located at C:\Program Files\Unity 5.6.0b7 - Soft Shadows\Editor\)

    That way I can load up the soft shadow version or the nasty jaggies version:
     
    tatoforever likes this.
  48. ifreed92

    ifreed92

    Joined:
    Jan 29, 2017
    Posts:
    4
    waiting for directional light to buy)
     
    tatoforever and Flurgle like this.
  49. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,083
    @ifreed92
    I'll have a preliminary version next week. Will post some shots soon. :)
     
    Murgilod, punk, cdmpants and 2 others like this.
  50. RoyaleJoons

    RoyaleJoons

    Joined:
    Jul 28, 2016
    Posts:
    13
    Instant buy when I found it in the store, keep up the good work! Looking forward to the directional light update!
     
    tatoforever, punk and Flurgle like this.
unityunity