Adding light to the terrain

June 7, 2009

I wanted to add lighting to the terrain engine, but I did not want to use OpenGL’s implementation, instead I wanted to create my own. So I added a light map to the terrain data, and set the program to modify the pixels when creating the textures. Then I added a very simple algorithm to fill it with some interesting data; I just use the height map so that hight pixels will be bright, and low pixels will be dark. The result is better than I hoped for:

With light

With light

Even with this very simple light scheme, the terrain looks a lot better 🙂 It looks even better when moving the camera around. This was a lot easier to add than I expected. Here is another angle:

Another angle

Another angle

But as you can see, the deep valleys are where the simple scheme falls through. The terrain is just too dark.

Dark valley

Dark valley

I need to change the lighting scheme to use normals compared to a artificial sun. I will also add some minimum amount of light, to simulate ambient light. Hopefully this will not be too difficult. 🙂

-Knut

More texture splatting

June 6, 2009

As I mentioned in the last post, the number of textures, the images used as textures and even the steepness thresholds for when each texture should be used was hard coded into the program. This is clearly wrong, and therefore I have made it all configurable. The terrain engine has a configuration file, just a text file really, where I can specify several values, such as camera speed and height map file, and now also witch textures to use, and their steepness thresholds. I’ve also changed the code where the splatting takes place so I can use as many textures as I like. I added another grass texture, and tweaked it a bit, and it produced this:

Another texture

Another texture

I’m very pleased with the way it looks. 🙂

Another view, three textures used

Another view, three textures used

I’ve also been tweaking the code quite a bit, so it runs a bit faster, even on my very modest laptop. Of course, the detail level is configurable as well, so if I test it on another PC, I can beef it up a lot 🙂

Another view

Another view

Although it gets better and better, even with texture splatting, the terrain looks a little flat. I would like to try and add some lighting to try to fix that. I guess that will be in the next update.

-Knut

Adding texture splatting

May 30, 2009

As you could see from the screen shots in the previous post, plain textures, although better than wire frame, was a bit boring and repetitive. So I added texture splatting. Now, the program will look at the steepness of the terrain and decide witch texture to use. Or rather, how much of each texture, as they are blended together. The result is impressive:

Texture splatting added

Texture splatting added

What a difference it makes. The terrain is really starting to come alive 🙂

Another angle

Another angle

As you can see, steeper terrain means more rock. These values are taken from the unoptimized height map, so even a flat area can contain interesting textures. This really makes the drawing faster while still giving a good looking terrain.

Another angle

Another angle

I still need to tweak this a bit. And I would also like to be able to use more than just two textures, and perhaps different sized ones as well. But at least now, the terrain is starting to look really good. 🙂

-Knut