Terrain cascades

Just a quick thing I wanted to post, because I’ve been banging my head against it for a few days, and finally got it working just now.

In the game, I draw a lot of the ground details into a texture, and then use that texture while drawing the ground, as an overlay. (In fact, we have a couple different overlay textures, for different purposes). This works great in general, for the game camera that’s mostly looking downward. The problem is that when you’re near the ground and looking forward, suddenly you can see a lot of terrain all at once, and that overlay texture has to stretch to cover all that extra terrain… which makes the texture suddenly go quite blocky.

(That shot is slightly exaggerated to show the effect. It wasn’t that bad before). This is a classic problem when you’re dealing with shadows; when your camera is close to the ground, you typically need a lot more shadow detail near the camera, than in areas far away from the camera. So… I decided to try using one of the classic shadow solutions; cascades.

With cascades, you draw essentially the same data at several different sizes. We draw the overlay data which is close to the camera really big, and the data which is further away much smaller. And then when rendering, we check how close a bit of the terrain is, and read from either the close bit of data, or the far bit of data. This lets us do this:

Now we have really sharp terrain texture detail up close where it’s important, and much lower-resolution detail further away. With this change, it means that I now have enough terrain overlay resolution up close that we can consider using real textures for road surfaces, instead of using solid-color paths, as we’ve been doing so far.

I know a couple artists who will be very excited to get their hands on this. :wink:

(Of course, I still need to adjust number of cascades, distances, and so on; the path in the second image is still much too low-resolution in the middle-distance. But now I have the ability to fix that!)


All done!

Lots of detail up close to the camera, reasonable detail far away from the camera, and minimal glitches at the transitions between cascades. Pretty pleased with how this has come out!

This will be in an updated build within the next day or two.


On a mildly related note, here’s some work on shadows.

With shadow quality set to “Medium”, here’s the “before”:

And here’s “after”:

This is just from handling shadows better; it’s no more expensive to draw than it was before (in fact, it’s probably somewhat less expensive). Higher-quality shadows are even better; you can actually see people’s arms and legs in the shadows, even from this distance, on “Ultra”.

Still need to actually cascade the shadows, but that’s a bit further down on my list. Next up is the class configuration dialog revamp!


I’ve finally gotten around to doing the cascading shadow system! Here’s a picture, in a debugging build:

Here, we have four different “cascades”; dynamic shadow maps which cover different areas in front of the camera. Closest is the red cascade, which covers the first 20 meters. The green covers out to 100 meters in front of the camera, blue covers up to 300 meters away, and magenta goes all the way out to 1km away.

The big advantage of this system is that we can have really high-resolution shadows up close to the camera where we can see lots of pixels, and lower-resolution ones further away, where terrain and other objects are much smaller on the screen and don’t show as much detail.

The real fancy thing about this system is that it can turn itself on and off; when you’re in a downward-facing camera, we still use just a single shadow map, which means we can use all of the available texture resolution for a single map of even detail; it’s only when we bring the camera right down to ground level that we start doing cascaded shadow maps, so we can have extra shadow detail close to the camera, and less detail far away.

This is a thing that we’ve needed for ages. I’m very glad to finally have it working!

1 Like