Friday, May 6, 2011

I'm Making a Note Here



Huge success. I finally got blocks procedurally drawing in 3D. With a camera that can navigate around them. I'm still not done with that though. I've got a lot of optimizations to do. To understand them, let me try to explain the process as simply as I can.

The most efficient way to draw something in 3D is to put each vertex into what's known as a VertexBuffer. Then, all at once, you draw them. Something about the order you fed them in determines where the faces are drawn on them. Also, you end up feeding in more vertices than you finally use, because some of the ones you fed in are shared. For each triangle, you need 3 vertices. For each square, you therefore need 6. And for each cube, you need 36. On a cube, a total of 8 vertices are eventually actually used. If you don't fill the buffer and render them all at once, you end up with wasted things that could have been shared.

Right now, I draw each block individually. I tried combining them all into one buffer the first time, but that didn't work out. From the point I'm at, I can now move towards doing that optimization.

Second, the algorithm I mentioned previously about which faces need to be drawn. Right now I'm not using that - I draw every face of every block. I need to do that optimization. Once all that is done, I should be able to render a ton of blocks very efficiently. Right now, before the optimizations, it's lagging a little with only 20x20x2 blocks. But there's a lot of optimization that can be done.

No comments:

Post a Comment