Terrain, Part 8

By Shamus
on Feb 15, 2006
Filed under:
Programming

If you recall back in Part 6 I introduced shadowing, and then I did some tests on the terrain to see how it looks at various resolutions. I’ve noticed that most of the problem with the lower resolutions is not that the hills look undefined or blocky, but that the lighting looks bad. The light and dark side of hills get blurred, and shadows become big dark blobs.


Notice how the shadows are kind of vague blobs of darkness. I’ve turned down the the resolution on the terrain, and the result was that the shadows became undefined.


But keeping the high polygon count just to preserve the lighting just doesn’t make any sense. Polygons are there to give the thing shape, and if you’re adding polygons just so you can have little areas of light and dark, you’re probably doing something wrong. That’s a job for textures.

You remember in Part 7 I added zone textures. I can very easily add the lighting and shadows to these textures as well. The results are very nice:

Amazingly, this image and the previous are of the same scene from the same point of view, and they even have exactly the same polygon count. This is a 2 million polygon terrain that has been reduced to a mere 12,000 polygons! Back in part 7 I concluded polygon counts this low were unworkable because the terrain looked too simple. This sidesteps the problem by drawing a texture with lots of subtle lighting and shadowing effects. Nothing is left out. So what we have are 12,000 polygons being drawn with a texture generated with 2 million polygons worth of detail. All of the smaller hills you see are just shading: the surface itself is totally flat at this distance. As you get closer, polygons will be added that will make those areas more detailed. Here is the same view again, only showing the polygons that make up the terrain:


The circled area is a large quad (a pair of triangles). See how that area still has little shadows and lighting changes? Those would have been turned into a big ‘ol hazy dark blob using the old system.

With this feature in place, I can afford to keep the polygon count low. Also, remember how I was crying about sending vertex data back in part 4? Well, now I don’t have to send the lighting data with each vertex. As far As OpenGL is concerened, I’m drawing a flat white unlit terrain with a texture on it. This is about the fastest way you can draw textured polygons.

Let’s look at another before and after:


But of course, as Mark would tell you, we don’t so much solve problems as we trade one set of problems for another with the hope that the new set of problems is more favorable than the old. The drawback is this: The lighting goes on the texture, so if I change the lighting (like, sunset, sunrise, etc) it will have no effect whatsoever on the terrain unless I rebuild all of the terrain textures. However, these improvements are so great that I intend to keep them, even if it means I have to give up on smooth day/night changes.


Here is a view of the same scene, only from ground level. Just a few years ago this would have been passable as a first-person view, although the ground looks a little blurry by today’s standards. Still, this looks very nice. Makes me want to replace the “fly around” style movement with standard first-person movement so I can run around and jump on these hills. :)

My test machine is a 1Ghz with 512MB of memory. My video card is a GeForce 5200. So far, the engine runs nice and smooth on this system. I think we’re nearing the end of the project. There are only a few items left on my goal list at this point.

Enjoyed this post? Please share!


3Three comments. 33% of them are the most recent.

From the Archives:

  1. Marcus Stade says:

    Lightmapping is cool, but this can be much improved upon by using normal mapping. What you do then is to save the normals instead of the lighting, with which you can then easily calculate the lighting of the high resolution map and texture your low resolution map with the results.

    I really like your shadowing optimization by the way.

  2. Neil Roy says:

    I just wanted to say, even though this is years later than I am enjoying this series. Given modern hardware and techniques, these are still usable as every bit of extra speed you can squeeze out of the machine means more you can add to your world.

    Plus this is a great starting point for anyone considering starting this type of project.

    I like your writing style and have chuckled more than once at your wonderful sense of humour. :)

  3. WJS says:

    As I’m sure you’d love suggestions on a project you finished with almost a decade ago, I’ll make one: from the text, it sounds like you have a single texture map with lighting baked onto it. It would probably be better to have a second map just for the lighting. (Multiplying them together should be significantly faster than alpha-blending the ground textures, right?) This would allow you to regenerate lighting much more frequently (and smoothly if you want to simulate a sun traversal), maybe even every frame (depending on how big your terrain is and what else you’re drawing).

Leave a Reply

Comments are moderated and may not be posted immediately. Required fields are marked *

*
*

Thanks for joining the discussion. Be nice, don't post angry, and enjoy yourself. This is supposed to be fun.

You can enclose spoilers in <strike> tags like so:
<strike>Darth Vader is Luke's father!</strike>

You can make things italics like this:
Can you imagine having Darth Vader as your <i>father</i>?

You can make things bold like this:
I'm <b>very</b> glad Darth Vader isn't my father.

You can make links like this:
I'm reading about <a href="http://en.wikipedia.org/wiki/Darth_Vader">Darth Vader</a> on Wikipedia!

You can quote someone like this:
Darth Vader said <blockquote>Luke, I am your father.</blockquote>