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.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    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. brisingre

    brisingre

    Joined:
    Nov 8, 2009
    Posts:
    277
    I have a game full of fishtanks and have been struggling with semi transparent shdadows for like 2 years. This is blowin' my mind.

    Is it possible to handle colored shadows in a similar way?
     
  2. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,337
    @brisingre,
    Yes, colored shadows are also handled with primitive shadows. Shadows properties are handled in a per caster case (instead of per light or per material case). In fact, I didn't show it in the video but I can change the color of the shadows casted by the semi-transparent plane too and it will be displayed correctly.
    We will soon run some private early tests with some users on mobile hardware to showcase the power of primitive shadows coming in v2.0. We will then tweak a couple of things based on feedback (integration, usability, setup, etc) and then it should be ready for public release.
    I'm also working on other raytraced-like shadowing techniques (not really related to distance fields though) for high end hardware. It will allow users to have super accurate directional shadows on the whole view and will put Cascaded Shadows into shame. :)

    @Abuthar
    This is a common artifact of PCSS shadows but don't worry, it can be mitigated. What you are reaching is the boundaries of the blockersearch which once it fails it returns 1 (no shadows). Did you tried tweaking the shadow bias and soft-ness?

    PS: Looks like that character needs some ultra realistic distance field shadows. ;)
     
    Abuthar and brisingre like this.
  3. Abuthar

    Abuthar

    Joined:
    Jul 12, 2014
    Posts:
    92
    Hey thanks for the response. So tweaking shadow bias helps - The problem is that i need my shadows to be as accurate as possible, so peterpanning is a no-go for me. On the other hand i need my shadow strength to be at 100% because shadow strength affects volumetric light cast shadows. So if i could tweak shadow softness another way that might work for me... for now.
     
  4. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,337
    @Abuthar,
    Sure, close your project and open the NGSS UnityShadowLibrary.cginc file (the one you installed in your Unity CGIncludes folder). Then rise diskRadius value at line 448. For point lights, edit the diskRadius value at line 612. Don't forget to delete your ShaderCache folder after you finish.
    Keep in mind that If you make shadows softer than current max, you will get more artifacts. The ideal solution will be having more samplers but is not possible in v1.x (not without slowing down the algorithm a lot more). In version 2.0 you'll have ~4x speedups so having more samplers in shadowmaps won't be a problem. With more samplers kernels can be a lot wider and shadows more softer.
     
    Last edited: Feb 18, 2018
  5. Benjamin_Overgaard

    Benjamin_Overgaard

    Joined:
    Jul 20, 2015
    Posts:
    17
    Sorry for the late reply, but do you have an idea about how to get higher resolution shadowmaps? On Very High quality settings, the resolution is still pretty low.

    Thanks!
     
  6. Abuthar

    Abuthar

    Joined:
    Jul 12, 2014
    Posts:
    92
    That'll work for now, thank you! :)
     
    tatoforever likes this.
  7. Seneral

    Seneral

    Joined:
    Jun 2, 2014
    Posts:
    1,206
    If you can allow, decrease shadow range. Basically the same shadow map can now be applied to less space, resulting in more dense/detailed shadows.
     
    tatoforever likes this.
  8. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    5,996
    tatoforever likes this.
  9. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,337
    There's a way to override the shadowmap Max ress through scripting but I can't remember the API for it. Try to do a search on Unity Documentation.
    Someone already did and posted the code in this thread and it's something like 1-2 lines of code, try look for it.
     
  10. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,337
    @laurentlavigne
    I saw that yes and it's a clever way to skip empty spaces within each DF volume.
    On my side I already got a crude CPU implementation which is kinda slow to generate but I'm working on a computeshader version to generate the volumes really fast (around 100x+ faster). Next-up would be dispatching that data efficiently to the GPU to compute the realistic shadows (which is already handled). And lastly optimizations to volumes and what not. :)
    I'm also researching ways to generate and handle spacial scene data super fast. Octree Voxels might be a good candidate. I need to research it more cause it's currently limited by voxel resolutions which is kinda bad for hard accurate shadows.
     
    Seneral and hopeful like this.
  11. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    5,996
    You've seen what Lexie Dostal is working on?
     
  12. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,337
    I think he's also working on Voxels Octres yes. But yeah, for hard accurate shadows is just not good enough. Realistic shadows requires both, super accurate hard shadows and super soft shadows for penumbra.
     
  13. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,337
    What I'll probably end up with is a combination of Octrees and SDF volumes/primitives. Probably not voxels.
     
  14. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    5,996
    Oh you're trying to solve both types of shadows with SDF, I didn't realize that. EDIT: just read your new message on the combination.
    On another topic, can your shadows have a different color than ambient?
     
    buttmatrix likes this.
  15. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,337
    Yes,
    Realistic shadows requires hard shadows on short caster distances and soft shadows at far caster distances. SDF is kinda interesting cause it allows to shade pixels very similary to raytracing and that's the reason why it produces super accurate and realistic shadows.
    DF shadows coming in NGSS 2.0 can have both color and opacity in a per caster basis, independently from ambient or other lighting sources.
     
    hopeful likes this.
  16. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    5,996
    That's how you do glass shadow, nice. And the current NGSS? Or maybe it's on the surface shader level that I set the shadow color...
     
  17. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,337
    Current NGSS is not possible unless you do a custom shader that does colored shadows only. This is somewhat limited to only shadows and meshes mush be cloned to act as casters-only. Kinda paintfull setup. ^^
    But heck, depends on your needs, I did something like this for a client and he was happy. :)
     
    laurentlavigne likes this.
  18. buttmatrix

    buttmatrix

    Joined:
    Mar 23, 2015
    Posts:
    609
    This is the only transmissive shader that I have found to support colored shadows, however, only for static transmissive surfaces, and the lighting must be baked; not mixed or realtime. How might NGSS 2.x address this issue, or is that outside the scope of this asset?
     
  19. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,337
    @buttmatrix
    SDF shadows in NGSS 2.0 are volumes (primitives or 3D textures) with a transform matrix and a RGBA color. For every fragment we cycle through all visible volumes within lights frustrums and compute shadows individually on the fly (without any shadowmap pre-process) using the volume transform and then apply color/transparency once computed.
    There is of course more steps, computation and optimizations involved, that is just the basic idea of the process.
    And that's how you have raytraced-like colored semi-transparent shadows in NGSS 2.0. :cool:

    Btw, what I did for my client was a custom shader that does only colored shadows for casters on real-time lights. It has nothing to do with NGSS/SDF shadows.
     
    Last edited: Feb 20, 2018
    laurentlavigne likes this.
  20. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    5,996
    Do directional light cast shadows that are crisp near the contact point and go fuzzier as distance to the receiving surface increases?
     
  21. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,337
    @laurentlavigne
    For NGSS 1.x? Yes, thats PCSS algorithm and requires SM3.5 higher (if SM3 is detected PCF is the only filtering available).
    For NGSS 2.x? Sames as 1.x plus all SDF casters properly cast realistic shadows. There's also other raytraced like techniques coming in v2.x.

    Decimating objects using billboard/lods can increase shadowmap rendering but only if used in a large number (such as large open world with huge amount of caster istances). If you are using small amount of casters you won't notice any performance improvement.
     
  22. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    5,996
    will you charge an upgrade $ for 1.x -> 2.x?
     
  23. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,337
    Yes,
    The new product will cost 30$ but will have 10-15$ discount to all existing NGSS users.
     
    Invertex likes this.
  24. zmaxz

    zmaxz

    Joined:
    Sep 26, 2012
    Posts:
    143
    When will NGSS2.0 become available for purchase ?
     
  25. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,337
    We are targetting public release sometime this summer and alpha/beta early access before that.
     
    brisingre and Abuthar like this.
  26. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,337
    You can also edit the volumetric lighting shader and change it's _LightShadowData.r value (to 0 or 1) so it will always set the opacity to some predefined static value.
    It's a better solution than closing Unity, changing UnityShadowLibrary.cginc values, delete your ShaderCache and open Unity, etc. ^^
     
  27. wetcircuit

    wetcircuit

    Joined:
    Jul 17, 2012
    Posts:
    1,409
    Are there any issues using NGSS on webGL?
     
  28. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,337
    @wetcircuit
    I never tried NGSS on webGL but if Unity supports real-time shadows and at least SM3.0 on WebGL, it should work.
     
    wetcircuit likes this.
  29. wetcircuit

    wetcircuit

    Joined:
    Jul 17, 2012
    Posts:
    1,409
    thank you. I'm not an expert with webGL, but I think that means webGL 2.0 only... My tests suggest shadows can look good on the browsers that do webGL 2.0 (the shallower the camera depth the less chunky the shadows look). But the screen space shadows didn't work for me, and webGL 1.0 shadows always look bad….

    Maybe others have a different experience.
     
  30. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,337
    Yeah,
    I'll do some tests with screen space shadows on webGL see how it goes. It should normally work as the rest of shadow features unless Unity is doing something funny. NGSS contact shadows requirement is similar to a low quality/standard SSAO effect.
     
  31. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,369
    Will NGSS be compatible with both the high end and low end SRP at some point or only the high end SRP?
     
  32. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,337
    @Elecman
    NGSS 2.0 yes. I'll add the ability to have point light soft-shadows in LW pipeline too (by default point lights won't have any shadows on LW pipeline). I will also add the concept of omni directional shadows in LW pipeline using only one shadowmap for 180 degrees angle (half a point light).
    This will give you the ability to use LW on low end platforms (mobile, VR, etc) and will remains similar to what we have today but a lot faster to render as all that is done in the same pass.
     
    Last edited: Mar 7, 2018
  33. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,337
    Tim from the SRP team said that LW pipeline will shape in terms of lighting quality very close to what we have today in Forward renderer. With some minor quality differences such as: diffusion of light, specular GGX etc. It also wont have depth pre-pass and limited amount of lights number, basic shadows filtering (problably only hardware bilinear filtering), only spot and directional shadows (no point shadows) but all rendered in one single pass. With the addition of omni directional point shadows and distance field shadows to LW renderer, NGSS will be an interesting product for such renderer which targets extreme performance but limited functionality/quality.
    NGSS on HD pipeline will have all high end shadowing features with no limitations (except by your own hardware). Raytraced like shadows, SAT shadows and 4x hardware intrinsict functions speed ups.
    I will probably split NGSS into two products as it was clearly stated that LW and HD pipelines differs quite a lot and they are not compatible and the rendering additions I'm doing is also very different on both renderers.
     
    Last edited: Mar 7, 2018
  34. Lex4art

    Lex4art

    Joined:
    Nov 17, 2012
    Posts:
    445
    Yeah, soon there will be two worlds for LW and HD pipelines... does anybody knows how long will last standard rendering pipeline?
     
    Flurgle likes this.
  35. ceebeee

    ceebeee

    Joined:
    Mar 7, 2017
    Posts:
    395
    It's my understanding the standard pipeline will still be there. But to use some of the newer features of 2018, you'll need to move to the LW or HD pipeline.
     
    Lex4art likes this.
  36. chiapet1021

    chiapet1021

    Joined:
    Jun 5, 2013
    Posts:
    605
    From reading other Unity dev posts about how long they are keeping the current rendering pipeline, my sense is that they do not intend to retire it anytime soon and that they will provide a lot of advance notice and a lengthy timeframe before any plans to deprecate/remove.
     
  37. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,337
    At the same time I will try to follow closely the adoption of both pipelines so NGSS 2.0 can be on time and not quite premature or late.
     
    Last edited: Mar 7, 2018
    laurentlavigne likes this.
  38. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,369
    Why doesn't Unity hire you?
     
  39. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,337
    @Elecman
    I've already got an offer and I like the idea but that won't be possible right now, I'm in the middle of two projects (a console game and NGSS 2.0). But it's something I will reconsider in the future yes.
     
    Abuthar, chiapet1021 and Elecman like this.
  40. churi24

    churi24

    Joined:
    Sep 17, 2013
    Posts:
    93
    Our game Project Nightmares with your shadows
     
    magique, nbac, Flurgle and 7 others like this.
  41. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,496
    Just some notes for 2018 compatibility.

    NGSS_Directional.cs & ContactShadows.cs:
    -change #if UNITY_2017_3 to: #if UNITY_2017_3_OR_NEWER
    -Remove || SystemInfo.graphicsDeviceType == GraphicsDeviceType.PlayStationMobile for that branch, it's unsupported.
     
    tatoforever likes this.
  42. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,337
    @Invertex
    Yes, it was added to NGSS v1.8.5 coming this week.
     
    Invertex likes this.
  43. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,337
    @churi24
    Nice use of light and shadows. :)
     
  44. arnoob

    arnoob

    Joined:
    May 16, 2014
    Posts:
    155
    It looks really great! Congratulation!

    Just a little question, what technique did you use for volumetric lights (the rays of light we can see from light sources) ?
     
    tatoforever likes this.
  45. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,337
    @arnoob
    There's a couple of Volumetric Lighting assets on the Asset Store (and one outside which is free btw). All of them works out of the box with NGSS except one (can't remember which one) that requires 1 line code change to their sources to avoid volume leaking when shadows strength is lower than 1 if you are using NGSS local shadows.
     
    arnoob likes this.
  46. arnoob

    arnoob

    Joined:
    May 16, 2014
    Posts:
    155
    Oh that's good to know! Sorry for being slightly off topic, but which one would you recommend? Is Aura compatible with NGSS?

    Also, I was wondering something else. Considering that light sources use a depth texture to store shadows, is there a way to have access to these textures? And do you think it would be possible to make the light calculate the shadows only once and then keep the calculated shadow texture (like sort of baked shadows) in order to gain performance in lower en devices?
     
  47. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,337
    @arnoob,
    Right off the bat, Hx Volumetric Lighting from Hitbox Team. They all work fine with NGSS (and if they don't, then it's just one line of code away). ;)
    Rule of thumb, if shaders/effects works with Unity default shadows they should work with NGSS.
    Never heard of Aura. Need to check it out.

    As for shadows depthmap pre-bake. It's possible yes and I have plans for it in the future (with both HD/LW pipelines). Basically, a shadowmap atlas that holds both the static part and dynamic part of the scene. It will update once for static objects and always for dynamic objects (the static/dynamic rendering selection needs to be sorted out with the culling system btw). Furthermore, using the dynamic part to update the static part which is the one that will get sampled on the scene.

    PS: Anything regarding shadows is never offtopic. ;)
     
    arnoob and punk like this.
  48. ceebeee

    ceebeee

    Joined:
    Mar 7, 2017
    Posts:
    395
    I did some testing with Aura, from what I could see it works with NGSS fine.

    https://www.assetstore.unity3d.com/en/#!/content/111664

    It's fairly new but pretty impressive.
     
    arnoob and tatoforever like this.
  49. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,337
    @ceebeee
    Yeah, NGSS will work with anything that already works with Unity shadows as it replaces Unity shadows entirely.
     
    arnoob likes this.
  50. arnoob

    arnoob

    Joined:
    May 16, 2014
    Posts:
    155
    Thank you, I never heard of Hx Volumetric Lighting, and it looks great!

    About the handling of shadows that's exactly what I was thinking about! :-D By the way is it possible already to access the shadow map texture itself?