Search Unity

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

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,369
    It means that shadowmap can now be higher which means less aliasing and artifacts. ;)
     
  2. strich

    strich

    Joined:
    Aug 14, 2012
    Posts:
    375
    Is there currently no good solution for semi-dynamic in default Unity? And when might we expect NGSS 2.0? We need to start getting our lighting situation sorted within the next month or two for our project.
     
  3. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,369
    @arnoob,
    No problem, I will provide some pseudo shader code tomorrow but it's what I've described in my previous message.
     
    arnoob likes this.
  4. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,369
    @strich,
    No there's no current solution for semi-dynamic lights in Unity (where shadows gets computed once for static objects and always for dynamic objects). NGSS 2.0 is planned for this year but no ETA yet.
    Regards,
     
  5. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,369
    @strich,
    When I said "semi-dynamic" I meant baked depthmaps for static objects and dynamic depthmaps for dynamic objects. It has nothing to do with static lighting baked.
     
  6. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,241
    Just got NGSS, looks great, but I'm having this problem -- the editor crashes instantly when I enable the ContactShadows component on the Main Camera in my scene, or when loading your ContactShadow demo scene.

    Log (from my scene) is attached. This is on a 2017 MacBook Pro with AMD 560 GPU.

    And here's the last part of the log when trying to load your demo scene:

    Opening scene 'Assets/Psychose Interactive/NGSS/ShowcaseSceneContactShadows.unity'
    Load scene 'Assets/Psychose Interactive/NGSS/ShowcaseSceneContactShadows.unity' time: 0.013951 ms
    Unloading 45 Unused Serialized files (Serialized files now loaded: 0)
    System memory in use before: 1.23 GB.
    System memory in use after: 1.22 GB.

    Unloading 319 unused Assets to reduce memory usage. Loaded Objects now: 4879.
    Total: 9.283186 ms (FindLiveObjects: 0.737869 ms CreateObjectMapping: 0.131213 ms MarkObjects: 7.226858 ms DeleteObjects: 1.186707 ms)

    [00:00:00] Enlighten: Precompute started.
    [PathTracer] building lightmap data asset.
    -[MTLTextureDescriptorInternal validateWithDevice:]:736: failed assertion `MTLTextureDescriptor has invalid pixelFormat (0).'

    Native stacktrace:

    0 libsystem_kernel.dylib 0x00007fffb76a1d42 __pthread_kill + 10
    1 libsystem_c.dylib 0x00007fffb7607420 abort + 129
    2 libsystem_c.dylib 0x00007fffb75ce893 basename_r + 0
    3 Metal 0x00007fffa56c6e0b MTLReportFailure + 822
    4 Metal 0x00007fffa56a373b -[MTLTextureDescriptorInternal validateWithDevice:] + 946
    5 AMDMTLBronzeDriver 0x00007fff9ce0435f _Z41amdMtlBronze_Stats_DrawIndexPrimsIndirectP32BronzeRenderCmdEncoderMembersRecjjjj + 34143
    6 Unity 0x0000000102cc4e11 _ZL22InitRenderSurfaceMetalR18RenderSurfaceMetal14MTLPixelFormat + 1137
    7 Unity 0x0000000102cc491a _ZN5metal24CreateColorRenderSurfaceEP23ColorRenderSurfaceMetal19RenderTextureFormat + 58
    8 Unity 0x0000000102cb826e _ZN14GfxDeviceMetal32CreateColorRenderSurfacePlatformEP17RenderSurfaceBase19RenderTextureFormat + 14
    9 Unity 0x0000000101a64e50 _ZN15GfxDeviceWorker10RunCommandER20ThreadedStreamBuffer + 1984
    10 Unity 0x0000000102cbb08c GfxDeviceWorkerAutoreleasePoolProxy + 60
    11 Unity 0x0000000101a6e164 _ZN15GfxDeviceWorker3RunEv + 116
    12 Unity 0x0000000101a64581 _ZN15GfxDeviceWorker18RunGfxDeviceWorkerEPv + 81
    13 Unity 0x0000000102241bda _ZN6Thread16RunThreadWrapperEPv + 90
    14 libsystem_pthread.dylib 0x00007fffb778c93b _pthread_body + 180
    15 libsystem_pthread.dylib 0x00007fffb778c887 _pthread_body + 0
    16 libsystem_pthread.dylib 0x00007fffb778c08d thread_start + 13

    Debug info from gdb:


    =================================================================
    Got a SIGABRT while executing native code. This usually indicates
    a fatal error in the mono runtime or one of the native libraries
    used by your application.
    =================================================================

    [0904/191958:FATAL:platform_thread_posix.cc(235)] Check failed: 0 == pthread_join(thread_handle.handle_, __null) (0 vs. 3)
     

    Attached Files:

  7. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,369
    @gecko
    Hi,
    Did you submitted this bug to Unity using the Bug submission guidelines? It's an editor crash produced by Enlighten. To be more precise it looks to be a multithread bug (trying to join a thread that has been previously detached produces an application crash).
    It's a multithread crash cause I recognize the error. ^^
     
    Last edited: Sep 5, 2017
  8. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,241
    I'll submit a bug report -- turns out that it only crashes when Metal Editor is enabled.
     
    tatoforever likes this.
  9. TheAlmightyPixel

    TheAlmightyPixel

    Joined:
    Jun 21, 2014
    Posts:
    263
    Are you planning on adding contact shadow support for spot and point lights? In UE4 contact shadows work on both light types, and I'm asking mainly because you mentioned that your contact shadow technique is similar to what Epic uses.

    Directional contact shadows are nice but in interior scenes you can't exactly use them.
     
    tatoforever likes this.
  10. Sterner

    Sterner

    Joined:
    Nov 11, 2012
    Posts:
    33
  11. redemprez

    redemprez

    Joined:
    Aug 14, 2017
    Posts:
    29
    Hi!
    NGSS is a great addon, thanks! I have a problem in 2017.2 beta 10 with directional light:
    increasing softness in NGSS directional component gives some strange artifact (elipse that alters shadows softness).


    EDIT: My error: I forgot to change settings to "Close Fit" instead of "Stable Fit"!

    .... but now I encountered another error: when I increase PCSS Filter DIr Min and PCSS Filter Dir Max, my mesh becomes darker and triangles are seen despite it is smoothed mesh. Here:



    Ok, another user error - sorry! I just needed to increase my normal bias to 3.
     
    Last edited: Sep 7, 2017
    tatoforever and ekergraphics like this.
  12. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,369
    It's planned for NGSS v2.0. ;)
     
    TheAlmightyPixel likes this.
  13. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,369
    @Sterner
    Beautiful game you got there btw! :)
     
    Sterner likes this.
  14. ekergraphics

    ekergraphics

    Joined:
    Feb 22, 2017
    Posts:
    257
    I just wanted to say thank you for this post, as I also experienced the shadows looking not good at all, and seeing your diagnosis and solution will probably help a lot of people with similar issues. I guess in the developer world, this is called "user error", but since I'm from the design world, I call it "not user friendly". :)

    For me, the shadows still look so bad they're completely unusable, but I guess I've missed something basic, so I'll keep watching this thread for hints.

    My latest import went like this:



    Stable fit, shadow distance 1000, near plane 3.
     
    Last edited: Sep 14, 2017
  15. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,369
    @roberteker
    Tweaking shadows in the developer world is never user friendly and it will never be perfect no matter what you do. There will always be some sort of obvious or not so obvious imperfections you have to live with. And the main reason is that shadows are expensive and hardware is limited.
    PS: Can you upload the image in jpeg format? Unity forums don't display images if they are larger than 5MBs.
    Regards,
     
    buttmatrix, hopeful and Abuthar like this.
  16. redemprez

    redemprez

    Joined:
    Aug 14, 2017
    Posts:
    29
    Hi!

    No problem, glad I could help. As for the settings, they should be slightly different for Unity 2017.1 and Unity 2017.2 beta 10.

    In Unity 2017.1 I think you should use these for directional light, stable fit, very high resolution shadows in quality settings, linear color space in ayer > Other settings.



    of course you can make shadows harder to your taste.

    In Unity 2017.2 beta 10 you should use "close fit" settings and in directional light I made these settings:



    Basically there are three main sliders that control shadow width: Normal Bias, PCSS filter Dir Min and PCSS Filter Dir Max. changing one of them usually requires changing another :)
     

    Attached Files:

    tatoforever likes this.
  17. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,369
    @redemprez
    Small note: Bias Fade can cause shadows to be a bit thicker and skip fine details but it's a good way to hide bias issues (if you experience it on your own setup). :)
    Regards,
     
    thelebaron, buttmatrix and redemprez like this.
  18. redemprez

    redemprez

    Joined:
    Aug 14, 2017
    Posts:
    29
    Yes, I noticed that it is actually nice trick - first I make my shadows thicker then I blur them. The result is absolutely acceptable for me, especially in realtime :)
     
    tatoforever likes this.
  19. mm_sto

    mm_sto

    Joined:
    Aug 28, 2017
    Posts:
    16
    Out of curiosity! Testing on both 2017.2.0b10 and 2017.1.0f3 i can't get the blur to show up in Metal. What's everyone's process on doing it?
     
  20. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,369
    @mm_sto
    There's an Unity bug that prevents custom shadows on mobile if renderpath is set to Forward. Only workaround is to set camera renderpath to Deferred. Till Unity fix it. :\
    What I found so far is that it has something to do with hardcoded filtering tags with directional shadows.
    PS: The importance of having access to Engine sources... I would have fix it really quick. :(
     
    Last edited: Sep 13, 2017
    hopeful likes this.
  21. ekergraphics

    ekergraphics

    Joined:
    Feb 22, 2017
    Posts:
    257
    Managed to reduce the size:



    I'm guessing there's a setting I'm completely missing, or something fundamental that i've misconfigured, because here is what your asset always appears like to me:
    • Unity's standard shadows look as if they are visible under NGSS.
    • NGSS seems to have an extremely close near clipping plane that just cuts them off in a very noticeable way.
    What happens in the above image is that there are pipes closer to the camera casting shadows on an object a bit further away, and when I just move my head a little, that clipping plane makes those shadows appear and disappear.

    Now, NGSS shadows do appear behind that clipping plane, but in such low quality that it really looks worse than Unity's standard shadows. It's like Unity's cascades gone very wrong.

    Again, it's a CAD model that's in 1:1 real world scale for use in VR.

    (This is another confidential client file which I can't send, unfortunately.)
     
    Last edited: Sep 14, 2017
  22. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,686
    Is a shadow distance of 1000 really working for people using NGSS? IIRC, I would get horrible shadows if I tried that with Unity's shadows.
     
  23. ekergraphics

    ekergraphics

    Joined:
    Feb 22, 2017
    Posts:
    257
    I've tried everything from 1000 to 150. I don't see much difference, I have to admit.
     
  24. buttmatrix

    buttmatrix

    Joined:
    Mar 23, 2015
    Posts:
    609
    these settings look good to my eye
     

    Attached Files:

  25. ekergraphics

    ekergraphics

    Joined:
    Feb 22, 2017
    Posts:
    257
    Well. I'd hardly say that a cube on a static screenshots makes for a fair "good to my eye" comparison test when I've posted moving images from rather complicated geometry...

    Anyway, here's actually an interesting test with an empty room, single directional light I just made:



    Notice how a second controller shadow fades in at a certain distance?

    I'm just holding the Vive controller in front of me and moving it slightly closer to the floor.

    Also notice how a large, weird square shadow fades in when my headset gets close to the floor.

    I'm using the standard Valve player prefab from the InteractionSystem demo scene.

    I reduced the shadow distance to 50 here.
     
  26. buttmatrix

    buttmatrix

    Joined:
    Mar 23, 2015
    Posts:
    609
    ...just a suggestion. NGSS doesn't support SPSR, not sure if you have that setting enabled.
     
  27. ekergraphics

    ekergraphics

    Joined:
    Feb 22, 2017
    Posts:
    257
    No, it's set to multi pass.
     
  28. buttmatrix

    buttmatrix

    Joined:
    Mar 23, 2015
    Posts:
    609
    Well I'm definitely curious what is causing that issue, I haven't seen these artifacts in VR before. Looks like a ray width issue, but I really don't know. Probably worth sending a small example project to @tatoforever
     
  29. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,369
    This is ContactShadows normal behavior. The algorithm fails outside the screen (or behind objects) because it doesn't see any depth beyond clipping planes or behind objects. Pretty much like any screen space raymatching algorithm. Contactshadows wasn't made to replace any shadow solution, only to assist current shadowing techniques. To better ground objects, to add small shadow fine details and to covert areas where peter panning is an issue.
     
    Last edited: Sep 14, 2017
    buttmatrix likes this.
  30. ekergraphics

    ekergraphics

    Joined:
    Feb 22, 2017
    Posts:
    257
    Well, that's too bad. I guess we can't use this asset after all then.

    I should not be too surprised, because using Unity for non-gaming applications (like importing complex CAD models) seems to be a new, and still largely unexplored area, as is VR.

    (The doubling of Vive controller shadows, though, might be an issue that others run into as well, even in games.)
     
  31. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,686
    I'm not 100% sure, but it sounds like you could benefit from bringing shadow range very close (under 100m) when viewing objects close up, and/or increasing the size of your shadow map. Both strategies ought to give you more precision on shadows.

    Increasing the size of the shadow map can be done with the Sunshine plugin, which I think was said to work with NGSS earlier in this thread. Also, I think being able to set new shadow map sizes may be coming to Unity in 2017.2 (though I'm not sure).
     
  32. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,369
    @roberteker
    Your contactshadows are way too tick and way too large. Try to reduce its distance and width. If you are working with cad files where close up details are very important you want to reduce the shadowmap distance and increase the shadowmap resolution. Otherwise you are giving way too much importance to far away objects and reduces precision close up a lot.
    I'm always looking into improving shadowing algorithms. NGSS 2.0 will provide new ones that suffer less from standard issues (acne and paning) while being a lot faster to compute. Also I'm researching some ways to create better raymatching shadows that do not suffer from screen space issues. Some sort of object distance buffer would be perfect for raymatching algorithms.
     
    Last edited: Sep 15, 2017
    hopeful likes this.
  33. nbac

    nbac

    Joined:
    Jul 7, 2015
    Posts:
    267
    another showcase
     
  34. Meshtint

    Meshtint

    Joined:
    Jan 11, 2017
    Posts:
    507
    Are there any possible ways to use contact shadows on orthographic camera? Or any workarounds? Would like to achieve something like the image below.

     
  35. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,369
    @MeshTint,
    Hi, ContactShadows currently do not work with Orthographic projection (will do in the future). Also it's not the goal of ContactShadows to replace any existing shadows only to support and mitigate issues with shadows (specially with Peter Paning). You can achieve similar results instead with NGSS PCSS shadows, setting them up with a wide penumbra. They also work with any projection.
     
  36. Meshtint

    Meshtint

    Joined:
    Jan 11, 2017
    Posts:
    507
    Thanks for your reply :)

    I am able to get the blur and soft effect with PCSS on my directional light. But I am trying to get a sharper edge on the shadow that is nearer to the object, and then fade to more blur and soft when it's further.
     
  37. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,369
    @MeshTint,
    That's exactly what PCSS does. Harder/sharper shadows near the caster and blurrier/sorter shadows away from the caster.;)
     
    Meshtint and buttmatrix like this.
  38. Meshtint

    Meshtint

    Joined:
    Jan 11, 2017
    Posts:
    507
    Strange... My shadows seem to be blur only. Shadows are not sharper near the caster. I wonder if i missing something or it has something to do with orthographic camera.
     
  39. buttmatrix

    buttmatrix

    Joined:
    Mar 23, 2015
    Posts:
    609
    If you are using an orthographic camera, you cannot expect NGSS to behave as intended, which is what the author was alluding to above
     
    Meshtint likes this.
  40. Meshtint

    Meshtint

    Joined:
    Jan 11, 2017
    Posts:
    507
    I see. Thanks!
     
  41. Alex3333

    Alex3333

    Joined:
    Dec 29, 2014
    Posts:
    342
    Good afternoon. I have a problem. In the build, I have no shadows. in the editor everything is fine. How it can be fixed. ? in the documentation where I read that this is possible. BUT I did not understand what needs to be done to solve this problem.
     
  42. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,369
    @Alex3333,
    Can you provide more information? What's your target platform, target graphic API? Log errors?
     
  43. NaughtySquirrel

    NaughtySquirrel

    Joined:
    Mar 31, 2017
    Posts:
    8
    I've got exact same problem... no NGSS in built exe. DX11 x86/64..... and this error reoccurring... over and over....

    NullReferenceException
    at (wrapper managed-to-native) UnityEngine.Material:Internal_CreateWithShader (UnityEngine.Material,UnityEngine.Shader)
    at UnityEngine.Material..ctor (UnityEngine.Shader shader) [0x00000] in <filename unknown>:0
    at NGSS_ContactShadows.get_mMaterial () [0x00000] in <filename unknown>:0
    at NGSS_ContactShadows.Init () [0x00000] in <filename unknown>:0
    at NGSS_ContactShadows.OnPreRender () [0x00000] in <filename unknown>:0
     
  44. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,369
    Are you guys instantiating ContactShadows at runtime?
     
  45. alternativevisual

    alternativevisual

    Joined:
    Apr 16, 2015
    Posts:
    75
    Direction light shadows not working on mobile in deferred rendering o_O
    Unity 2017.1.0p4
     

    Attached Files:

    Last edited: Sep 23, 2017
    buttmatrix likes this.
  46. NaughtySquirrel

    NaughtySquirrel

    Joined:
    Mar 31, 2017
    Posts:
    8
    Are you guys instantiating ContactShadows at runtime?

    Not as far as I know. It's on the camera from the very start...
     
  47. NaughtySquirrel

    NaughtySquirrel

    Joined:
    Mar 31, 2017
    Posts:
    8
    Although.... it's just possible... the main directional light de-activates and re-activates... its on the sun light for a Unistorm weather system.
     
  48. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,369
    @N30N47,
    We must ask Unity to fix this bug, it's the same bug as when camera is set to Forward and it looks like Unity also corrupt some platform config files as I go a couple of projects where shadows works in Forward on Mobile and others where it doesn't work at all. :\
     
  49. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,369
    @NaugthySquirrel, @Alex3333
    Make sure the ContactShadows shader property is not null in your Editor also try putting NGSS folder in your plugin folder. Sometimes Shader.Find returns null if the shader isn't in the plugin folder (works in editor but at runtime don't, not sure why thought).
    Try that and let me know if it solves the issue.
    Regards,
     
    hopeful likes this.
  50. NaughtySquirrel

    NaughtySquirrel

    Joined:
    Mar 31, 2017
    Posts:
    8
    Fixed.... and.... I was curious why I couldn't see a Contact Shadows setting... so... I thought... hmm... maybe I'm out of date.... I updated.... went through instructions all again.... and.... working. I feel like an idiot now.

    @Alex3333 - Make sure you are up to date with the latest package.
     
    tatoforever and hopeful like this.