Search Unity

[Released] Analytic Soft Shadows for Unity

Discussion in 'Assets and Asset Store' started by JollyTheory, Mar 2, 2021.

  1. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    156

    Analytic Soft Shadows is a real-time soft shadowing solution with shadows defined by Spheres, Capsules and Boxes.

    Asset StoreWindows Demo • ✅ Built-In (2021+) • ✅ URP (2021+)

    It has bothered me for a long time how unrealistically sharp shadow maps are, even with tricks like percentage closest filtering, they just don't get soft enough to feel realistic. I came across this Analytic Shadows technique and knew I had to implement it in Unity.



    Features:
    Insane Performance: Due to tiled-culling and depth-aware-upsampling in a lot of cases the performance can be better than Unity's shadowmapping! (Best case: Approximating high-poly models with few soft shadow shapes. Medium case: Approximating models with hundreds of small soft shadow shapes.)
    New feature! Colored Shadows: Each shadowcaster can now cast a unique shadow color instead of black. Example.
    • Famous Capsule Shadows algorithm used in many AAA games (TLoU2, CS2, Warframe).
    • Real-time adjustable shadow softness all the way from super hard to super soft.
    • An additional algorithm option that provides soft shadows that do not fade with distance, if that's what you want, similar to "Signed Distance Field shadows".
    • Blends with Unity's shadows nicely so you can mix and match them interchangeably.
    • Practically infinite shadow resolution, zoom in as close and as far away as you like.
    • Full source code included for maximum configurability.

    Limitations:
    • Built-in: Deferred rendering path only, URP: Forward rendering path only.
    • Mobile, WebGL not officially supported. A platform with compute shader support is required.

    Enjoy!
     
    Last edited: Dec 22, 2023
  2. firstuser

    firstuser

    Joined:
    May 5, 2016
    Posts:
    147
    Looks great!

    This was really easy to set up, I've tried other lighting/shadow assets and this was probably the easiest. Thanks for that!

    Do you think (official) mobile support will ever be possible?
     
  3. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    156
    Not sure, perhaps in the future. For now I'm focused on research into adding URP and HDRP support
     
    NeatWolf and firstuser like this.
  4. Pode

    Pode

    Joined:
    Nov 13, 2013
    Posts:
    145
    @JollyTheory "WebGL not officially supported" <- does that means that the asset will work, but with decreased performances?
     
  5. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    156
    WebGL does not support Compute Shaders so it will not work at all, unfortunately.
     
  6. Pode

    Pode

    Joined:
    Nov 13, 2013
    Posts:
    145
  7. Passeridae

    Passeridae

    Joined:
    Jun 16, 2019
    Posts:
    395
    Would be really cool to see HDRP support. I've been checking Asset Store for the last month only to see if someone has finally made sdf shadows. Though capsule shadows are not exactly that, I'm still excited to see your work! I hope one day you'll add HDRP support. Would buy it straight away.
     
  8. Alterego-Games

    Alterego-Games

    Joined:
    Jul 13, 2015
    Posts:
    354
    Do you think (or know) if this also works on xbox and playstation?
     
  9. Pode

    Pode

    Joined:
    Nov 13, 2013
    Posts:
    145
    @JollyTheory another question : after the compute shader has created the primitive approximation for the 3D model, is it possible to save that approximation to a file in one way or another ?
     
  10. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    156
    There is no approximations being created, you may be confusing this with SDF 3d texture shadows. Analytic shadows are defined by Sphere, Capsule & Box shadow caster shape components placed on game objects, like physics colliders.
     
  11. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    156
    Not sure, don't have those consoles to test on unfortunately.
     
  12. Passeridae

    Passeridae

    Joined:
    Jun 16, 2019
    Posts:
    395
    Are there any plans to extend it to SDF shadows?
     
  13. Pode

    Pode

    Joined:
    Nov 13, 2013
    Posts:
    145
    Aaah I was confused: in my understanding you were generating the primitives (therefore 'approximating' the mesh) automatically. Now I understand the artist must position them. Thanks for the clarification.
     
  14. nrorn

    nrorn

    Joined:
    Sep 23, 2016
    Posts:
    7
    Hi,
    I'm really interested in your plugin to use in an AR project (mobile+URP). When do you expect to have the URP supported? Thanks and congrats on creating this much needed add-on.
     
    SolidAlloy likes this.
  15. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,241
    Interested in this if there's potential for substantial performance improvement over Unity shadows. I tried the demo but it looks like vsync is on? FPS was always 60, even disabling the shadows. And would you mind sharing the documentation so I can see what's involved in the setup, to better judge if it's usable in our projects?

    thanks!
     
    Last edited: Apr 10, 2021
  16. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    156
    Hi, sorry for the vsync mishap with the demo, running it on the 'Fastest' graphics quality should fix the issue. I also did some performance comparisons in this tweet: https://twitter.com/cowsaremen/status/1367575678787477511
    And here's the entire setup process:
     
  17. drbatuira

    drbatuira

    Joined:
    May 4, 2020
    Posts:
    23
    Hi, I saw you were studying the URP, is it going to be inserted? I only work with URP :(
     
  18. dock

    dock

    Joined:
    Jan 2, 2008
    Posts:
    605
    Hi. I just bought this and I'm really impressed with the results, but I'm having a lot of trouble implementing them into my scenes without objects casting shadows on themselves in weird ways. Is it possible to control which objects cast shadows on each other?

    I realise my light angle is narrow here. That's mostly to emphasise the problem, but it's a major issue with wider angles too.

    upload_2021-6-2_11-51-11.png
     

    Attached Files:

  19. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    156
    Try increasing the bias parameter, also try putting multiple smaller capsule casters on the tree and the thin object on the right instead of one big one, that should help.
    Also for capsules the Indirect algorithm has less self shadowing, try switching to it if you're using the Direct one.
    For the box on the other hand the it would help to decrease the bias, so the shadow sits closer to the box, did you increase it, or perhaps is the shadow caster size itself smaller than the box?
     
    Last edited: Jun 2, 2021
  20. dock

    dock

    Joined:
    Jan 2, 2008
    Posts:
    605
    I increased the bias on the box to exaggerate the problem, but in general I'd like to choose which objects are unaffected by shadows.

    The only option seems to be to use a shader that's unable to receive shadows, but that seems like a terrible solution. I'll just have to bear that in mind and limit my application of it to the things it does well. In the future it would be great if layergroups could be used to control shadow casting relationships.
     
  21. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,241
    Hmm, somehow missed your reply. So I downloaded the demo again, selected Fastest -- and now it looks like Unity shadows are disabled entirely, so I get 3.8ms without UASS and 4.4ms with UASS....is it possible to compare performance of Unity shadows and UASS in the demo?

    Also, is there any chance of making this work on Forward rendering?

    thanks
    Dave
     
  22. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    156
    Hi,
    I'll make a better demo with a direct comparison for you some time soon.

    Don't think Forward support will be coming any time soon unfortunately, I tried really hard to make it work, but every way to inject stuff into Unity's shadowmap with Forward has massive drawbacks, and directly multiplying the colors looks really ugly and introduces it's own problems. :( So it's Deferred only for now.
     
    dock, firstuser and gecko like this.
  23. Necka_

    Necka_

    Joined:
    Jan 22, 2018
    Posts:
    488
    Hi,
    I saw this asset on the store and didn't find any link to a documentation or video tutorial.
    When reading how it works I have the strange feeling that I should manually set capsules or components on each and every single object I want that cast a shadow.
    For large and complex scenes this seem like a very tedious thing to do.
    Did I understand it right or is there something else?
     
  24. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    156
    Hi,
    Please find the documentation attached to this post. (README.txt)

    You will indeed have to approximate your geometry with 3 shapes: Spheres, Capsules and Boxes, that is the theory behind the analytic shadows algorithm. There are some helpers in Tools/UASS/* that can add appropriate shadowcaster shapes based on [Sphere/Capsule/Box]Collider components on your game objects.

    The technique is similar to UE4's Capsule Shadows and Warframe's Capsule Shadows.
     

    Attached Files:

  25. Necka_

    Necka_

    Joined:
    Jan 22, 2018
    Posts:
    488
    Thanks for the fast answer, I'll have a look :)
     
  26. JohnPet

    JohnPet

    Joined:
    Aug 19, 2012
    Posts:
    85
    Does it support spot and point lights? It's not defined in the asset store page.
     
  27. Eltharis

    Eltharis

    Joined:
    Aug 30, 2018
    Posts:
    17
    Hi!

    I'm looking for really far distance shadows that could be cast from big spheres (like, 20-300k unit radius) on other such spheres. Currently the problem is that camera must get close to those objects to render the shadows and I need them to work from any distance - it's ok for those to be simple blob shadows that just cover big elliptical area.
    It's to simulate eclipses from planets on other ones dynamically, relative to directional light source.
    Would your solution work for that out of the box or could you maybe implement such feature? I'd surely buy it.
     
  28. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    156
    Hi, here's a screenshot of a 99999unit sphere casting a shadow on another 99999unit sphere, so it should work (and be performant too, since it's a screenspace effect, so you pay in perf only for what you see).

    Make sure to use the Indirect algorithm and make sure that your planet shaders are fully Deferred and write to the G-Buffer if you have custom planet shaders. But you probably shouldn't use units that large as it breaks Unity in a lot of different ways (for example i can't even select these 99999unit spheres in the editor when they have such scale on unity2019).

     
    Eltharis likes this.
  29. JudahMantell

    JudahMantell

    Joined:
    Feb 28, 2017
    Posts:
    476
    Hey, this looks great! Any update on URP support? Thanks!
     
    SolidAlloy likes this.
  30. JudahMantell

    JudahMantell

    Joined:
    Feb 28, 2017
    Posts:
    476
    @JollyTheory I hope the asset is still being updated! I know myself and many others would love URP support if it's possible!
     
    SolidAlloy and DragonmoN like this.
  31. jeonsc

    jeonsc

    Joined:
    Jan 5, 2021
    Posts:
    1
    I bought yesterday. A question about how to use it.

    1. Are only shadows in the form of spheres, capsules, and boxes supported?
    2. How do I make the shadow of a human figure appear like the demo?
    3. Please provide a demo scene for reference.
     
  32. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    156
    Replied to your e-mail.
     
  33. daville

    daville

    Joined:
    Aug 5, 2012
    Posts:
    303
    Radivarig, DragonCoder and SolidAlloy like this.
  34. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    156
  35. Howard-Day

    Howard-Day

    Joined:
    Oct 25, 2013
    Posts:
    137
    Any chance of extending this to support distance field shadows? Fantastic asset!
     
  36. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    156
    I've researched that earlier and gotta say that it's not really a possibility, the amount of complexity would make it a different asset altogether, there would need to be global distance fields maintained and a robust SDF baker. That'd be a full-time job for a year to implement properly. The UE4's paper on their SDF ambient occlusion is one of the largest computer graphics papers out there for example.
     
  37. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    156
    Good news everyone: Just submitted an update that adds support for URP (10.0+). Should be live when the assetstore team approves it.
     
    Radivarig and VermilionGames like this.
  38. Migueljb

    Migueljb

    Joined:
    Feb 27, 2008
    Posts:
    562
    Working with Unity 2020.3.35 URP for quest 2 on android. Anyway this works there?
     
  39. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    156
    Hi, VR/mobile is not officially supported unfortunately
     
  40. adslitw

    adslitw

    Joined:
    Aug 23, 2012
    Posts:
    275
    Hey, this looks awesome!

    I see the URP version is Forward only - does that mean it now works on mobile? Or if not, what's the issue that stops mobile being supported? I guess things like Switch are also not officially supported either?

    Second question - is it possible to provide an Amplify node, so that custom shaders can still be created?
     
  41. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    156
    Hi, the main issue with mobile support is compute shaders, I've tested the asset on one higher-end phone, it worked perfectly, can't vouch for other models. Switch should probably work.

    Don't need a custom Amplify node, just sample a global "_UASSTexture" with object's screen uv's, .x component will have your shadow, you can use it however you want from there
     
    adslitw likes this.
  42. DragonCoder

    DragonCoder

    Joined:
    Jul 3, 2015
    Posts:
    1,698
    This looks really cool!
    Quick question, is any form of baking required using the built-in renderer?
    Or can I expect the shadows to be projected onto meshes (not Unity terrain) that are generated at runtime?
     
  43. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    156
    Hi, everything's realtime, no baking required.
     
    DragonCoder likes this.
  44. adslitw

    adslitw

    Joined:
    Aug 23, 2012
    Posts:
    275
    Sorry @JollyTheory couple more quick questions - does self-shadowing work (edit: I see above it does, with mixed results!), and do the shadows play nicely with mixed lighting / lightmapping (shadowmask / subtractive)?
     
  45. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    156
    Hi,
    It should work with that.
     
    adslitw likes this.
  46. Agoxandr

    Agoxandr

    Joined:
    Aug 16, 2014
    Posts:
    52
    Hi, as it is right now the URP version GC allocates about 2kb every frame. I wrote a version that doesn't do that. However it has it's own issues with the scene view and maybe multiple cameras (haven't tested it).
    I would also like to detach it from the camera and make every UASS component work on lights.

    Are any feature updates planned?
    Or is this asset in maintenance only.
    @JollyTheory I can send you a copy of what I have right now if you are interested.
     
  47. MrPifo

    MrPifo

    Joined:
    Sep 11, 2017
    Posts:
    2
    Hey, I'm very interested in buying this asset for my game. But I'm not sure if I will be able to run it, since every asset in my game uses a custom Shader made with ShaderGraph and as you mentioned you would need to modify your Shader to receive the shadows. I'm not really experienced with Shaders and use ShaderGraph for that reason.
    Would it be hard/possible to make custom Shaders receive the shadows or could you describe what steps would be needed to do that?

    Thx in advance!
     
  48. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    156
    Name the texture "_UASSTexture" and toggle off "Exposed"
    R component will have shadows.
     
  49. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
    It seems like there's an issue with point lights in URP (havent tested in standard/legacy render) where their light contribution gets completely removed if there's a shadow where they're supposed to shine here.

    In the screenshot there's a single UASS component for the directional light, i also tried adding a UASS component for the pointlight itself - doesnt change anything just makes the shadows get cast from the light also ofc.

    As you can see there should be some red light shining where the shadow is.. but there's not, it gets completely removed by the shadow
     

    Attached Files:

  50. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
    here's a gif with an exaggerated light of the issue from the post above
     

    Attached Files: