Now that we have a colorful ball it's time to give it some height variation. Thankfully all that work we did to get color blending smoothly will also make the height blend nicely. But first there's the big question, what direction is up? On a 2d grid it's easy, we just define the y axis as up and call it a day. But on the surface of a sphere up is the direction away from the center. Unfortunately that isn't as simple as just grabbing one axis. But we could use a coordinate system where this is true for a sphere, spherical coordinates. Then changing height is as simple as changing the r axis. There's one minor problem with this method though, the graphics card wants the vertices in cartesian coordinates. It's a simple equation to convert everything but there's a lot of sines and cosines in there. Now sines and cosines are fairly fast but not nearly as fast as multiplication. Every time we change a section of the mesh that section needs to be redrawn. Each section has ~10000 vertices and each conversion has 5 sines and cosines. So for each redraw there's a lot of computation. Is there a better way to do this? Well we already store the position of each vertex, can we use that? Yes, to change the height of a vertex we can just normalize its position vector, multiply that by the new height, and add it back to the original vector. Doing this we can change the height of a vertex 5 times faster than by using spherical coordinates. Now that that’s out of the way lest implement it. Let’s look at what we currently have. First we’ll just change the height of the cell centers. I’m using a map of Earth to decide the height of each cell. Doesn’t look that great but it’s starting to work. Thankfully all the work we did to get color to blend will also let our height blend. First the bridges. Then the corners. That looks like a planet! But it is a little boring, what if we changed those flat slopes to terraces (look here for the math involved)? Better, but the flat land looks a bit strange. And the tall cells don’t look great either. Lets only add a terrace if the neighboring cells have a small height difference. That’s better, gives some terrain variation but doesn’t look too strange. Just need to fill in the corners Looks pretty good, but it would look even better in color! Now it looks like a planet. Next we’ll try to add some textures.
0 Comments
Leave a Reply. |
ArchivesCategories |