Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to use shadows in Open World games?

Discussion in 'World Building' started by Rowlan, Feb 6, 2020.

  1. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,200
    Shadows can make a huge difference when rendering trees at a large distance in Open World games.

    The problem: I need to increase the shadow distance to like 10 times the default settings to make the trees in the distance look good. However, the side effect is that it influences the shadows of close objects, they flicker like crazy. Adjusting the cascades doesn't help that much.

    Basically it looks like this:



    Does anyone have a solution for that problem? Or is there a better way?
     
    atincuzun likes this.
  2. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    Theory talk:

    There is no solution I know off, I would say carefully study footage of games, notably AAA and look for paper. But unless I miss something there is mostly two case:
    A- fixed time, the sun don't move, it's baked into a lightmap
    B- time of day change, they just don't render distant shadow, or use approximate technique (like bake shadow sprite for object like in fortnite).

    One solution I haven't tested is to bake zonal harmonics texture indexed by time of day. But that's only static. Another would be to pay the cost of two shadow rendering, one for very large distant objects, and another one for close objects. Modern technique can supplement ONLY important objects with their own shadow maps, or use screen space shadow from the depth buffer to cover only very close find details.

    So while looking for solution and mix them you should look at mostly 4 cases (in each of the two above):
    1. environment to environment
    2. environment to dynamic
    3. dynamic to environment
    4. dynamic to dynamic
    With dynamic meaning anything animated by any purpose, static being non animated one.
    It's easier to solve 1 and 2 by precomting or baking solution in A, for example you can steam lightprobe for dynamic, or even baked shadowmap. Then you use the dynamic shadow map to only project dynamic. I think unity support that option. So if your racing game don't have time of day, I would go for that. Now time of day is a different beast altogether.
     
    Rowlan likes this.
  3. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    943
    Roman200333, awesomedata and Rowlan like this.
  4. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    1,419
    I use mesh-based terrains... Not sure what microsplat does under the hood for the shadow projections, but I wonder what options there are for shadows for mesh environments (that dont require baking into the mesh terrain.)
     
  5. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    HDRP handled shadows for 5 miles that looked crisp close up and fine far off. It can do this because its basically infinitely tweakable with the cascade ranges.

    Use HDRP deferred and then tweak the hell out of the shadows. Experiment with compressing shadow cascades close to player, very close. You only need to mess with blending the distance bands after that.

    It's all built in and AAA quality but if you are on built-in I have no advice sadly.

    You can't do this in stock unity in built-in or URP.
     
  6. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    1,419
    Thanks. That was apparently the bit I was missing here. I've been using URP. D:
     
  7. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I'm on URP myself right now :D I love it. Shadows wise it's not great but neither is built-in. They both don't hold a candle to HDRP's shadows. HDRP doesn't even do anything special (for medium res deferred), it just provides a way to tweak them so outlandish cascade settings still blend so you don't get those huge cuts.

    For HDRP I wasn't even using max res. Just 2048 atlas.

    Turns out that cascade blending really is all the other pipelines need too. I mean, we only use the cascade settings we use because we can't tolerate the huge eye-poppingly bad cuts between them. Still amazes me Unity didn't think that was the trick for their other pipelines but that happens when you don't make games yourself. You miss the little nuggets you're forced to look for.
     
    ron-bohn, AcidArrow and awesomedata like this.
  8. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,200
    I'm hesitating to migrate to URP because I hear it still has problems. But if cascade blending is a solution, I'll try NGSS now. It has that option.

    I'm a noob in that matter, but since I amped up the shadows by accident and thought that this is at least some approximation to the UE long distance forest style, I'm wondering now why Unity didn't improve on that. Unless there is another and better way. But to me it makes all the difference.

    I mean check out the "flight" here, i. e. the terrain in the background when the car is in the air:



    Or here's a screen:

    shadows.jpg

    The terrain texture is too bright, i didn't find the time yet to tweak that, but the forests are quite okay imo for Standard Pipeline.

    Gonna migrate that project to URP once NatureManufacture finishes the upgrade of his Assets next week. I'm curious how that works out and performs.
     
    Last edited: Feb 9, 2020
    wyattt_ likes this.
  9. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    1,419
    It still seems crazy to me that HDRP has this and URP doesn't... It's a pretty big, glaring, oversight to anyone with eyes.

    I can see, maybe from a technical standpoint, that from a mobile-first, non-shaded, baked-lightmap POV, they might have thought including this option was overkill, but at least add it as an option, and add an option to disable it in the pipeline settings so it doesn't include at build if you're not using. A nice warning before enable/disabling the option could be handy too.
     
    atincuzun likes this.
  10. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Yeah it's relevant now I suppose. I'm too busy / thick to add it myself so I've decided to do my own lighting :p
     
  11. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    It made sense in lwrp, but now it's URP, they shoot themselves in the foot
     
    Flavelius and awesomedata like this.
  12. transat

    transat

    Joined:
    May 5, 2018
    Posts:
    779
    I can't wait for NGSS to be URP compatible. It's in the works, I hear. @Rowlan, it would be good if Unity sorted this out but when I was using the standard pipeline NGSS did a brilliant job of solving that issue. The asset made my project look 10 times better.
     
    ron-bohn and Rowlan like this.
  13. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    1,419
    Seems like this should be supported in URP to begin with. D:
     
  14. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,200
    I tried this now in HDRP, however the shadows don't seem to render if the trees are rendered with lod > 0:

    shadows.jpg
    No shadows in the distance, i. e. ugly. In that screen I amped the shadow distance up to 600 and the cascades as high as possible.

    However when I increase the distance for the lods it looks like this:

    shadows lod increased.jpg
    Is there a way to have intense shadows with lod > 0? Gonna move that question into the hdrp forum if there's no easy answer.
     
  15. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    1,419
    Are these trees vanilla HDRP and URP, or are they using Vegetation Studio instancing for LODs? -- Maybe that has something to do with it?

    I know there was a bug in the URP version with Shadow Cascades being inverted... I wonder if this bug is also affecting HDRP in some way? -- i.e. when the LOD level is higher than 0?


    I've not tested it, but I wanted to point it out just in case you might not have known about the URP bug. VS being involved (assuming you're using it) is another potential culprit for this. I'm not at the point of vegetation in my project, so I can't offer much more than that. Maybe VS is flipping the cascade shadow to "fix" the URP bug of inverted shadows somehow? -- Sorry this is all speculation.
     
  16. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,200
    Using HDRP & VS Pro with LOD distance.

    I have to fiddle around more. It makes such a huge difference whether a forest is dark or not.

    Not exactly the same shot with different settings, but similar positions of car & day time:

    1.jpg
    And with the shadows

    2.jpg

    Apologies for not being accurate with those shots, but the general thing is: when you look into a forest, it should be dark.
     
    awesomedata likes this.
  17. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    1,419
    Totally agree.

    I'm sure Unity has a bug with cascades in URP, but not positive about HDRP... That makes me wonder if there's a problem between versions of that and Vegetation Studio which is causing your LOD issue. I definitely suggest looking into it maybe first with Vegetation Studio's author first, since I'm sure he would be much more familiar with (and responsive about) issues with cascades in this particular context.

    A "dark" forest should be within VS's reach, and if it isn't, the author of such a widely-used asset like VS should probably have a grasp on why.

    Just a thought.
     
    Rowlan likes this.
  18. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,364
    A bit late to the party but let me chime in.
    We have a solution for that on NGSS and is called FrustumShadows. It can help you display raystepped filtered shadows from your view depth from any distance, reducing drawcalls and GPU bandwidth considerably as you don't really need cascaded shadows when NGSS FrustumShadows are enabled. The typical setup is a non cascaded directional shadows with around 100-150m distance + FrustumShadows. Is far from perfect but is the only solution that won't eat your bandwidth, its use a tiny portion of memory comparing to lets say 8K shadowmaps, its completely dynamic and works on anything that writes to depth. On top of that it benefits from any RT optimization such as dynamic resolution.

    This is a demo of a very big open world game called WolfQuest showcasing NGSS FrustumShadows (FS get enabled 50secs):


    You can see very far mountains showing accurate non flickering shadows. This is impossible to do with any shadowmapping technique on such distances. Not even to mention the cost in performance!
    Currently only support Built-in renderer but SRP support is also in the works.

    PS: The spikes in the video was my screen capture was doing funny things but NGSS performs really well.
     
    TerraUnity likes this.
  19. TerraUnity

    TerraUnity

    Joined:
    Aug 3, 2012
    Posts:
    1,247
    @tatoforever That's really great implementation there, so if I'm correct distance can be endless as far as camera's far clip plane right? More info please ;)
     
  20. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,364
    Yes, anything visible writing to depth will cast screen space shadows for a tiny unnoticeable cost. In fact, you will see your FPS jump like 2x-3x if you disable al together cascaded shadows and set to something like 100m and let FrustumShadows do the job! :D
     
    ftejada, hippocoder and TerraUnity like this.
  21. transat

    transat

    Joined:
    May 5, 2018
    Posts:
    779
    I've really been missing NGSS since I switched to URP!! @tatoforever, will the depth normals pass coming soon to this PR help with the URP conversion?

    @Rowlan I've been using HBAO to work around this for now. The AO on the grass and trees in the foreground compensates for the poor shadow quality somewhat.
     
    Rowlan likes this.
  22. TerraUnity

    TerraUnity

    Joined:
    Aug 3, 2012
    Posts:
    1,247
    That's super awesome, always thought of having SS shadows cover far viewing distances rather than normal contact shadows for close ups so you'll have better performance and better visuals at the same time as you mentioned. This means a lot for big open-world environments, UE4 has Distance Field shadows for this which uses SDF to achieve.
     
  23. transat

    transat

    Joined:
    May 5, 2018
    Posts:
    779
    Have you tried using darker LODs to fake this a bit?
     
    Rowlan likes this.
  24. transat

    transat

    Joined:
    May 5, 2018
    Posts:
    779
    And if the terrain is flat you could also try setting some darkish ground fog in the distance. If you make it fade out around when it hits the canopy, I’m guessing it might also do the trick somewhat.
     
    Rowlan likes this.
  25. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,200
    That's actually a good idea. I didn't try faking LODs, the distance has only billboards. I'm going to try what tatoforever posted. I've already been there and didn't achieve that good results, but now that he's here with the party, I'm trying again.
     
  26. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,364
    The problem with the SDF implementation in UE4 is that works only with static meshes, requires extra memory to store 3D textures and the computation is no free. There's few compute shaders that combines all SDF textures into a screen space one for a deferred fetch later on in the rendering pipeline. With the advent of Raytracing everybody will just give up and focus on hybrid solutions (raster + raytracing) that are faster and more artistically friendly.
     
    sirleto and TerraUnity like this.
  27. VincentAbert

    VincentAbert

    Joined:
    May 2, 2020
    Posts:
    123
    Hello, I'm really sorry to bother you, I just have a quick question if you have the time : You guys are talking about using VS Pro with HDRP and URP, but it was my understanding it was only compatible with the standard unity pipeline, did I get something wrong ? I'm very new to unity and this would help a lot...

    Any way good luck for your shadow problem, and congrats on the project, it's looking good !
     
  28. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,200
    Not everything works with HDRP/URP, e. g. you can't have billboard grass. But you can use it for e. g. plants, trees and objects.
     
  29. ksam2

    ksam2

    Joined:
    Apr 28, 2012
    Posts:
    1,079
    Rowlan

    Can you please describe more how we can do this with NGSS shadow asset?

    I can't increase shadow distance more than 250 because of losing quality so is there nay way to draw another shadow from 250 to 10000 distance?
     
    Last edited: Aug 17, 2020
  30. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,200
    I think @tatoforever has an example. He's the developer of NGSS.
     
  31. joshcamas

    joshcamas

    Joined:
    Jun 16, 2017
    Posts:
    1,276
    NGSS has a "frustum shadows" screen effect that is designed for open world games - it's a screen effect used for distant shadows.
     
  32. wilgieseler

    wilgieseler

    Joined:
    Oct 17, 2013
    Posts:
    84
    Can someone explain how to configure shadow cascades for an open world game in HDRP 2021? I'm so confused by this. I only want detailed shadows near the character (~20m) and shadows as far away as possible, but I am having such trouble getting anything usable.
     
  33. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,200
  34. wilgieseler

    wilgieseler

    Joined:
    Oct 17, 2013
    Posts:
    84
  35. Deleted User

    Deleted User

    Guest

    Contact shadows when set to very high distances like 50,000, does give me shadows of very distant trees, with a proper look without setting the shadow distance to a very high number!!
     
    wilgieseler and sirleto like this.