Search Unity

Resolved URP Cached shadows

Discussion in 'SRP Dev Blitz Day 2022 - Q&A' started by sabojako, Sep 29, 2022.

  1. sabojako

    sabojako

    Joined:
    Jul 7, 2017
    Posts:
    48
    I know a lot of folks who would love to have Cached Shadows in URP. This feature is in HDRP, but is not on the URP public roadmap and I have not heard of this in a while. Is it planned?

    We ourselves implemented it and the gains from it are truly non-negligible.
    The additions of Renderer.staticShadowCaster and ShadowObjectsFilter.StaticOnly/DynamicOnly in 2021.1 make it even more worthwhile to have dynamic + static shadows on the same light.
     
    Last edited: Sep 29, 2022
    glenneroo, CameronE1, MaxEden and 6 others like this.
  2. joshuacwilde

    joshuacwilde

    Joined:
    Feb 4, 2018
    Posts:
    731
    Also want to say that we have had this in a couple years now in built in RP because we wrote our own system for it. It's a total deal breaker on mobile without it. So definitely would love to see this come to URP also. But it's gotta be a performant solution with adjustable settings, not some "one size fits all".
     
    glenneroo, Elvar_Orn and joshcamas like this.
  3. Elvar_Orn

    Elvar_Orn

    Unity Technologies

    Joined:
    Dec 9, 2019
    Posts:
    162
    Heyhey!
    I've recently been working on collecting and prioritizing feedback/requests for Shadow improvements in URP, and adding Cached Shadows are high on my list. Both for the benefits as well to get parity with HDRP.

    Getting comments like these help me place it even higher, so thank you!
     
  4. sabojako

    sabojako

    Joined:
    Jul 7, 2017
    Posts:
    48
    Hi @Elvar_Orn
    Also, is there any plan to support shadow rendering that can be shared between cameras in general SRP? Like a ShadowManager that collects every camera's shadow requests and process them so that no shadow view is rendered twice?
    The biggest example of this would be multiplayer splitscreen where sometimes punctual shadowmap from the same light are needed.
     
  5. Elvar_Orn

    Elvar_Orn

    Unity Technologies

    Joined:
    Dec 9, 2019
    Posts:
    162
    Hmm... no, that was not on my list. That's a really good request.
    I've now added that and will take a close look to see what can be done.

    Thanks for this!
     
  6. Khang_Pham

    Khang_Pham

    Joined:
    Feb 28, 2021
    Posts:
    13
    Hi Elvar are you able to share if that is planned for the near future yet?

    Thanks!
     
  7. zalogic

    zalogic

    Joined:
    Oct 6, 2010
    Posts:
    273
    Hi @Elvar_Orn ! I couldn't find this feature on the Unity URP rendering roadmap. Are cached shadow maps still on your priority list?
    In Unity 2022.2.x there is a Static Shadow Caster toggle on mesh renderers in URP but apparently it doesn't do anything at the moment.
     
    Khang_Pham likes this.
  8. Elvar_Orn

    Elvar_Orn

    Unity Technologies

    Joined:
    Dec 9, 2019
    Posts:
    162
    Heyhey!
    I'm still working on wrapping up some Shader Stripping and Prefiltering improvements so I haven't been able to start on any shadow improvements yet. I'm hoping to being able to wrap my current tasks in the next few weeks. After that I hope to get started on some Shadow tasks. Where this will be positioned is difficult to say before estimations and prioritizations have been made but I'm confident (without promising) that this will be placed high on my list.

    I will at least push for this, especially after getting this feedback from you all :)
     
    Khang_Pham, DevDunk, zalogic and 2 others like this.
  9. zalogic

    zalogic

    Joined:
    Oct 6, 2010
    Posts:
    273
    Really appreciate the feedback @Elvar_Orn! Sounds like a great plan! Thank you! ✌
     
    Elvar_Orn likes this.
  10. ViCoX

    ViCoX

    Joined:
    Nov 22, 2013
    Posts:
    37
    Any updates to share? :' )
     
  11. Elvar_Orn

    Elvar_Orn

    Unity Technologies

    Joined:
    Dec 9, 2019
    Posts:
    162
    No unfortunately not.
    My work for Shader Prefiltering & Stripping improvements is now 95% complete for 2023.2 and 2023.1 (One PR to land in both versions). After then I need to create backports to 2022.2 and 2021.3, verify that everything works and fixes the bugs I've resolved in the newer versions.

    After that we will prioritize and come up with a plan.
    I have already mention this to my team that is a highly requested feature so I'm hopeful.

    I'll create a reminder to myself to reply here in 4 weeks to give an update but expect that it will take some time to prioritize things, start work, implement, test and finally land. But I think it will be a good idea that I share the progress either in this thread or in a new one.
     
    Last edited: Feb 28, 2023
    Khang_Pham and zalogic like this.
  12. zalogic

    zalogic

    Joined:
    Oct 6, 2010
    Posts:
    273
    Uhu! That's great to know @Elvar_Orn ! Thank you so much for the feedback! Really useful to at least get a feel of the roadmap ahead. Much appreciated! ✌
     
    Khang_Pham likes this.
  13. epoupardcosquer-mitm

    epoupardcosquer-mitm

    Joined:
    Oct 5, 2016
    Posts:
    1
    Thanks @Elvar_Orn for the updates!

    Would it be possible to add this cache on the centralized Unity-roadmap? We may be able to help by submitting a report on the "How important is this for you?" form.

    Our application runs in WebGL in URP. The sun and the scenes are static most of the time. Caching all these shadow-maps would be a huge deal, especially for our clients on low-end devices and on mobile.

    Again, thank you for pushing this feature!
     
    Last edited: Mar 14, 2023
    Kabinet13, Khang_Pham, ViCoX and 2 others like this.
  14. DamonJager

    DamonJager

    Joined:
    Jul 16, 2015
    Posts:
    56
    is there any news?
     
  15. Elvar_Orn

    Elvar_Orn

    Unity Technologies

    Joined:
    Dec 9, 2019
    Posts:
    162
    Hey!
    Sorry for not getting back in the 4 weeks like I planned to do.
    Things are still quite hectic in the Shader Variant + Build time area.

    The latest update I have is this:
    • An item has been added to the public roadmap so feel free to vote on it.
    • This task is still being considered for when Shadow Improvements begin. Unfortunately I won't be able to start on those yet as there are a few other tasks that I've been asked to work on and finish before. This will take some time.
    • I however will try to work on Shadow improvements prioritization as well in this quarter and the good news is that I've made the higher ups well aware of the importance of this for you.
    So I'm trying as much as possible to get started on this but I will need to ask for patience as URP covers so many areas and many of them need some focus. I'm a little scared of promising a date for another update but let's say I come back in June with an update, even if it's just a no update post.
     
    Last edited: May 1, 2023
  16. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,063
    Thanks!
     
  17. Neonage

    Neonage

    Joined:
    May 22, 2020
    Posts:
    287
    Are you literally the only person working on URP? Why Shadows improvements are bottlenecked by Shader Variants?
    I've only now realized that Static Shadow Caster is HDRP only feature, but is visible in URP since 2021 and does nothing. What a confusing joke.
    Not to push on you specifically, but it's just ridiculous how much time it takes for any basic features to come out.

    Shadows are the most pain right now, they need both performance and quality. You can't look at them without tears of pixelated jitter and bias artifacts (especially when back side is translucent / light wrapped). And my GT 740m can't handle even 6 spot lights with low shadows, not mentioning point lights.

    Now, let me dream for a moment. There is so many different rendering techniques that URP could have, to satisfy all kinds of use-cases/needs, performance targets, and make some games an actual possibility.
    Just to name a few:

    - SDFs that can be used for ANYTHING -- 10KM soft shadows with full GI, distant-impostors, metaballs, collisions/physics on GPU for VFX or gameplay. You name it! Graphics - Erebus - Real-Time Ray Tracing SDFs; UE4/5 Style DFAO and Soft Shadows [HDRP/URP/BUILT-IN]
    And it seems that there was some work done already with mesh-to-SDF, but it needs to be much more focused on, as it's the most promising universal solution for many problems that is relatively cheap. Unity-Technologies/com.unity.demoteam.mesh-to-sdf: A light and fast real-time SDF generator.

    - Old-school stencil shadows https://github.com/rhedgeco/UnityShadowVolumeGenerator

    - Virtual shadows akin to tile-based lighting. HD | Tile-based Shadows (hd-prg.com)

    - Dual Paraboloid Point Lights (implemented in Godot) or Reflection Probes. So I got dual-paraboloid 97% working.. would you gurus co-brainstorm with me for the last 3%? :) - Unity Forum

    - Capsule Shadows (under consideration for HDRP? well, since 2022..)

    If only Unity invested a few banks of beer at R&D...
     
    Last edited: May 22, 2023
  18. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,622
    Neonage and DevDunk like this.
  19. Neonage

    Neonage

    Joined:
    May 22, 2020
    Posts:
    287
    Here's a document demonstrating many different shadowing techniques and occuring problems, including all VSMs:
    Advanced Soft Shadow Mapping Techniques (nvidia.com)

    Looks like it's not even hard to implement! And performance should be much faster, since it's only 1 fetch per-pixel, + they eradicate bias artifacts and aliasing thanks to blur. (yet might look weird, expanded, incorrect.. or lets say - stylized :p)
    All types of VSM suffer from light bleeding inside fully-shadowed penumbra (which is especially noticable with translucency), which can be mitigated with some sorts of clamping/threshold, or by using Layered VSM.

    Here's an old implementation of VSM:
    gkjohnson/unity-custom-shadow-experiments: A few custom shadow implementation experiments within Unity (github.com)

    upload_2023-5-22_9-2-48.png
    - Default Lit, looks ok?
    upload_2023-5-22_9-4-31.png
    - Translucent material, oh gosh.
    upload_2023-5-22_9-4-46.png
    > Extreme Expansion, bruh

    And why, would you look at that! They've attempted to make it in SRP long ago!
    ScriptableRenderPipelineData/ShadowMoments.hlsl at master · Unity-Technologies/ScriptableRenderPipelineData · GitHub
    And now this code exists only in HDRP?? Is it even used?
    Graphics/ShadowMoments.hlsl at master · Unity-Technologies/Graphics · GitHub
     
    Last edited: May 22, 2023
    Peter77 likes this.
  20. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,063
    Ask this during the graphics blitz day (;
     
  21. Elvar_Orn

    Elvar_Orn

    Unity Technologies

    Joined:
    Dec 9, 2019
    Posts:
    162
    I most certainly am not :)
    But as you know, URP covers a pretty big array of things and while shadows is my area. unfortunately (or thankfully depending on the stakeholder) some things get prioritized higher than others. Improving build times happened to be one of those. That's why I mentioned it in previous replies here.

    I don't control the prioritizations of tasks but I have a pretty strong voice inside the team and I've used it to express the urgency of what we've discussed here. The team is aware and we will prioritize again soon but I can't promise anything. All I can ask for is patience.

    Also, I want to do this right. Even though in this thread we're specifically discussing Cached Shadows, there are plenty of improvements/feature requests/issues for shadows that I want to tackle. I've been working on gathering those and doing a separate prioritization step specifically for Shadows so when I start I have a plan to give you the best wins as soon as possible.

    Finally, like I've mentioned before here, I placed cached shadow maps pretty high on that list. And that's thanks to all of you here in this thread. So again, thank you all! I really appreciate it.
     
  22. Kabinet13

    Kabinet13

    Joined:
    Jun 13, 2019
    Posts:
    130
    Thanks for your continued work on all this, we appreciate it. Much as someone else mentioned in this thread above, I'm interested in why URP wouldn't use Variance Shadow Mapping, or even EVSM, it really can work wonders for really soft shadows. (They aren't physically accurate, but that's perfect for URP) It's even pretty performant, see the slides I've linked below which show how it's used in roblox of all things. (Clearly that makes it fast enough for most hardware URP targets)


    I think the stuff on shadow casting starts around slide 40
    https://ubm-twvideo01.s3.amazonaws....ering_Roblox_Vulkan_Alhuwalia_Maya_slides.pdf
     
    DevDunk likes this.
  23. Elvar_Orn

    Elvar_Orn

    Unity Technologies

    Joined:
    Dec 9, 2019
    Posts:
    162
    Hey!
    Thanks for the link. I've bookmarked it.

    It's difficult for me to explain why VSM/EVSM hasn't been implemented before as I wasn't part of that.
    But it is one of the items in my document (I have a pretty big list :) ).

    But to be realistic, I don't foresee myself working on that anytime soon.
    I would much prefer setting up a good modular framework so that anyone can, if they want, replace/modify almost anything happening when rendering shadows. That would open the door for anyone to make their own custom shadow solution, asset store developers to create even more awesome assets, etc. Then in URP I would continue to build shadow features on top of that framework so the system would be used by both the internals of URP as well as users of Unity.
     
    Kabinet13, zalogic, glenneroo and 2 others like this.
  24. joshuacwilde

    joshuacwilde

    Joined:
    Feb 4, 2018
    Posts:
    731
    VSM / EVSM / ESM is worthless for your main directional light, although it can be much more useful for special use cases (point shadows, and even then, still some drawbacks). If it really were the great solution like it seems on paper you would see it in way more games. I've implemented quite a few variations and it has way too much light bleeding to be usable on medium and bigger light sources.

    COD Warzone does use ESMs (iirc) for point shadows though, so definitely some good use cases there.
     
    ontrigger likes this.
  25. Kabinet13

    Kabinet13

    Joined:
    Jun 13, 2019
    Posts:
    130
    I see your point, but I'd like to argue the oppsite specifically for the case of EVSM on a directional light. All VSMs have light bleeding issues, it's true, but a good EVSM implementation with a bit of over darkening to hide any remaining leaks can work wonders. Don't take my word for it though, take a look at the slides I linked earlier for implementation details, and for an example of it working very well for pretty general use cases, just mess around with roblox studio. It's not perfect, but it's surprisingly performant, and has very soft, good looking results. Just not having to deal with the performance, quality, and bias issues of PCF and standard shadows makes it a win for me honestly.

    (As a bonus it even works with anisotropic filtering, which is pretty neat)
     
  26. joshuacwilde

    joshuacwilde

    Joined:
    Feb 4, 2018
    Posts:
    731
    If I am not mistaken, EVSM requires at least 2 maps (or channels), and up to 4 for better quality. More info here : https://gamedev.net/forums/topic/663139-evsm-is-the-best-needed/5195302/ and here : https://www.martincap.io/project_detail.php?project_id=9

    So performance is going to take a big hit from memory reads alone. I think in some ways memory performance would be improved a bit because you could use mipmaps, but then again you also have to generate the mips and do the blurring. A lot of options with shadow maps open up of course when you aren't so performance limited.
     
  27. Kabinet13

    Kabinet13

    Joined:
    Jun 13, 2019
    Posts:
    130
    Not really, a four channel read in one, single texture sample is way less expensive then something like a 9 (or more) sample PCF. While VSM's are more expensive at low filter widths, they quickly eclipse PCF's performance at any reasonably soft kernel size. (See the chart towards the end of this article, figure 8-13)

    You absolutely aren't wrong about increased VRAM usage though.

    https://developer.nvidia.com/gpugem...ws/chapter-8-summed-area-variance-shadow-maps
     
  28. Neonage

    Neonage

    Joined:
    May 22, 2020
    Posts:
    287
    I just hope it doesn't take another year or so to get some decent improvements. I'd much prefer to have something useful right now, rather than 'complete' but at undefined point in a looong future. (It wouldn't hurt much to make improved shadows first, and then move them to a newly developed framework, right? Could be a nice test of portability for such system)
     
    Lars-Steenhoff likes this.
  29. scheichs

    scheichs

    Joined:
    Sep 7, 2013
    Posts:
    77
  30. JasonAnx

    JasonAnx

    Joined:
    Jan 7, 2016
    Posts:
    1
    Hi, has there been any updates on this? could really use cached shadow maps on URP
     
  31. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,063
    On the asse4 store
     
  32. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,644
    The author stated that the cached system is meant to be used for games where the dynamic objects use fake shadows. I still think it would be great instead to have the option to differentiate, one day I will need to dig into it.
     
  33. scheichs

    scheichs

    Joined:
    Sep 7, 2013
    Posts:
    77
    Maybe I should have been more precise... I'm totally fine with Corgi's solution for the moment. But if Unity would implement their own cached shadow system it with a distinction between cached static geometry and per-frame dynamic one, that would be perfect!
    As stated previously the MeshRenderer component has already a (unused in URP) flag called "Static Shadow Caster" that is meant for such a system.
     
    sebas77 likes this.