Archive for March, 2009

Optimizing fixed

March 22, 2009

Work continues on the terrain engine. I’ve managed to fix the holes left by the old optimization implementation. To reduce the number of vertices sent to the graphics card, the new system uses triangle fans for rendering. The result are somewhat amusing:

Holes fixed

Holes fixed

Close up:

One terrain fan

One terrain fan

I wrote a new rendering pipe to handle the triangle fans, so the renderer can now handle both fans and vertex arrays, even mixed in the same scene. 🙂 Works good, and looks good.

OK, the last few posts have all been about optimization and redusing the number of vertices. Now I’ll see if I can add something fun and cool! 🙂

-Knut

More optimization

March 17, 2009

I’ve been on a cabin trip this weekend, and I haven’t worked on the project while I’ve been away. But this week I’ve finaly implemented a function to optimize the terrain based on how interesting it is. And what is interesting terrain? Well, in my implementation it’s terrain containing lots of angles, bumps and turns. Flat areas are not interesting. Sides of hills are not interesting either. And those bits are removed, or rather, being represented by bigger squares. The result?

Optimizer working

Optimizer working

Rather looks like a quilt blanket. 🙂 But it works. Sort of. There is a problem.

There's a hole in the ground

There's a hole in the ground

See that hole there. Those holes appear where one big square meets several smaller ones. I need to fix this, and the way to do it is to divide the triangles meeting smaller squares…but how do I find out witch ones to divide… This will take some thinking, but hopefully it will be doable. I also created a bigger height map, to test and to show of a bit. 🙂 This one is less hilly, and is optimized even more.

Bigger map

Bigger map

Looks pretty good. And runs smoothly 🙂 Except for the holes of course. Hopefully I’ll be able to solve those soon.

-Knut

Begining optimization

March 10, 2009

I’ve begun optimizing the terrain, or rather, I’ve begun implementing the optimization functions. It’s not trivial, and it’s taken quite a lot of thinking and throwing away ideas as I figure out how to do different parts of it. Also, I have no experience with these kinds of things. But thats part of the reason I want to do this project, not to mention part of the fun! 🙂

The terrain is now stored in memory as a quad tree. The program will first create a large square representing the entire terrain, and then split these into smaller bits. At some point these smaller squares will be the same size as one tile, and at this point each square, or node in the tree if you like, is saved. These are used when creating the actual tiles. The result when only rendering each tile?

Maximum optimization

Maximum optimization

Not very pretty, but quite fast. However, I can create some additional levels in the optimization tree, and it starts to look quite a bit better.

Medium optimization

Medium optimization

As you can see, the terrain is quite detailed, even if it’s using a lot fewer polygons. But I’m not done. I want to have optimization based on the terrain itself, that is, if the terrain is hilly and interesting I want to keep that information and use lots of polygons to render it, but if it’s flat and boring I want to optimize more. I would also like to tie the level of detail to the range between the tile and the camera.

So thats what I’m looking into right now. It’s quite difficult, so I’ll probably spend some time wrapping my head around it and implementing it. I’ll update as soon as I have something though. 🙂

I did find one trick for improving the speed however. When I lowered the size of each tile, the program began to run faster. Right now, each tile is 32 squares wide and deep. My (educated) guess is that moving each tile to OpenGL was a big bottleneck. The program is set up so each tile is rendered by itself. So when I lowered the size of each tile, OpenGL could render it while I moved the next one to the GPU. Well, I think thats why. Works good anyway. 🙂

-Knut