Home       About Me       Contact       Downloads       Part 86    Part 88   

Part 87: Working on Terrain

September 8, 2013

Work is going slowly, so I don't know what to do about the blog. I really hate posting when there's nothing to show you. But it's been three weeks, so I guess I should write some kind of update.

The Problem of Scale

I have a very large world here, with objects millions of meters apart. I can't render all of these with a single pass, since it exceeds the resolution of the depth buffer. Back in Part 28, I did multiple passes and reused the depth buffer. I can do that here, with one pass from 16 kilometers to 16 million meters, then another closer pass from 0.25 meter to 16 kilometers. There are two problems.

First, the clipping doesn't seem to be exactly right, and there are artifacts right at the boundary between the two passes. I'm not sure if I can fix this with different projection matricies. It seems to vary with the machine I use, meaning it's some subtle difference in OpenGL drivers.

Second, it doesn't completely solve the problem. In the Part 28 demo, all the distant chunks are large grids and so don't need high resolution in the depth buffer. The exception was water, which at maximum distance is a very thin layer over the landscape. With high values for the front and back planes, there's not enough depth buffer resolution to handle this and you get flimmering.

In Part 28, I handled this by just coloring the distant landscape to look like water, instead of actually rendering a water polygon over the landscape. That's not a very general solution. In the SeaOfMemes world, I have distant objects like the RingWorld with relatively small features, such as the walls of the ring. Using the depth buffer causes those features to drop out.

I decided that since the distant versions of objects would be simple, I could just sort them. In the Part 86 demo, I did this, but not very thoroughly. The worlds are all spheres and the landscape doesn't need sorting. I just sorted the top layer, making sure the ring segments were behind the moon, etc.

This month I've been trying to get all that right, but it's a real nuisance. Even the landscape mesh has to be sorted when nearby mountains can obscure more distant elements of the mesh. Since I haven't finished this, there's no decent looking demo.

Terrain Data

I played around with procedurally generating asteroid shapes. These are all height maps still, but they look OK. I don't have all the code to do interference checking with the terrain, so it's hard to walk around on these. Still, they should be interesting places to build once it all works. I'm not sure what to do about gravity.

I've also looked for sources of landscape for the planet, moon, ring, and the little habitats in the asteroid belt. I had originally thought I would generate it all procedurally, but I'm not really impressed with the landscapes I get that way. They don't have any logic to them -- no river valleys or mountain ranges, just individual peaks and plains.

Instead, I've been pulling files off the U.S. Geological Survey site. The site has its quirks and dead links, but it will let you read topographic data in various formats. One format is called "GridFloat", and is just a huge array, already in Intel float format. Just read the whole thing into memory and you get a 3612 by 3612 array, ready to play with. Some of the mountain areas are very dramatic:

I have no idea why the array is 3612 wide. These are 1 degree areas, at arc-second resolution, so I would expect 3600 samples, not 3612. If anyone knows, leave a comment!

Another problem is coloring the landscape. For that, I need a "land cover" database, which they also supply. However, these are in "geotiff" format, have a different resolution, and cover a different area. Also, I have no idea how to convert the pixel array into lat/lon or vice versa. I've been puzzling over it, but can't find a simple resource that tells me how to do it in my own code. If anyone knows, please tell me.

Without that, I'm going to have to pick some simple algorithm for coloring water, trees, etc. As it is, I'm just displaying white landscape, and it's hard to evaluate the look.

The ring is 12,500 km in circumference and about 300 km wide, for 3.7 million square kilometers. Each of these 1 degree arrays are around 80 km wide, and 50 megabytes of data. To cover just the ring with these, I would need 480 patches, or 24 gigabytes of data. I've been playing around with reducing the resolution and summarizing these with a quad tree, but don't have any results yet. Then I have to get it displayed at a reasonable rate as you move.

Importing 3D Models

At one point while I was playing with the demo, I wanted to change the way movement is handled. Instead of just flying everywhere, I wanted three modes - walking on the ground, flying over the landscape (in the coordinate system of the object) and flying through space. I could just have mode keys or a menu, but I wanted to draw some vehicles. Then you could pick your travel mode by entering and exiting the vehicle. I also wanted people and houses placed in the landscape to give you a sense of scale.

To do this, I needed to import some 3D models. In Part 34 I used Collada for importing bricks I designed in Google SketchUp. This format is endless and I never did finish off any kind of reasonable importer. A couple of weeks ago, I decided to take a shot at Wavefront OBJ files, since the format is very simple.

Then I needed some good, free, low-polygon models of people, houses, space ships, etc. There are a variety of sites, but I was underwhelmed with the models. One very high quality set of models is on TF3DM ("The Free 3D Models"), but I'm not really sure about the ownership of some of them. I also found models on ShareCG and MakeHuman. Since I'm just using these as temporary filler to show scale, I guess I shouldn't fuss with this any more. The ones I've collected here would do:

My current goal is to have real landscape for the asteroids, the habitats/stations, etc., and the Ringworld. The Planet and Moon have so much landscape that they are going to have to wait a bit until I figure out how to generate it.

The player should be able to hop in a spaceship and launch, fly to and then land on his destination object. The stations should have a docking procedure. Then you are out of the ship and can walk around. For flying, I will add another object, once I figure out what it should be. A helicopter would work on the worlds with air, but looks silly on an asteroid.

I'll think of something!

Home       About Me       Contact       Downloads       Part 86    Part 88   

blog comments powered by Disqus