Search Unity

  1. New Unity Live Help updates. Check them out here!

    Dismiss Notice

Terrain 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:
    1,109
    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?
     
  2. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    4,993
    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:
    712
    awesomedata and Rowlan like this.
  4. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    984
    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 Moderator

    Joined:
    Apr 11, 2010
    Posts:
    26,456
    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.
     
    Rowlan, awesomedata and neoshaman like this.
  6. awesomedata

    awesomedata

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

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    26,456
    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.
     
    AcidArrow and awesomedata like this.
  8. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    1,109
    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:
    984
    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.
     
  10. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    26,456
    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:
    4,993
    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:
    509
    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.
     
    Rowlan likes this.
  13. awesomedata

    awesomedata

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

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    1,109
    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:
    984
    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:
    1,109
    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:
    984
    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.
unityunity