Friday, October 17, 2008

One Lumpy Planet

I spent a long time with a pen and paper and a calculator (and a debugger) to get a heightmap imported as a material and as a, well heightmap for the mesh.

Here's where I've ended up so far:
lumpy planet

And this is a version with wireframe overlay:
wireframe lumps

The quality of the normals is not very good because I'm using this cheap cross calculation that I saw on GameDev whilst reading this informative article on normal calculation algorithms by Jeromy Walsh. It's a very simple algorithm, but it doesn't seem to work well for me and I think I will try the MWA method next.

For the heightmap I'm using a 1025x1025 pixel grayscale 8bit png (or similiar raw). I divide that up to get the heights for all the vertices. It did not occur to me at first that quadrants share vertices (duh) so I didn't have their heightmap bounds overlap at first and that threw everything out of wack. Once I fixed that though, I discovered I need to store the heights for the neighbor vertices to calculate normals correctly. That also took a while to get the algebra to where I wasn't causing memory access errors.

Before I got the neighbor heights in there for normal calculations I got this quilt effect:
quilt

I still don't have the calculations correct for getting the correct 3d positions of neighbors across faces, but that's on the list. First, however, I have to fix the normal quality and the problem I'm having with quadrants at different levels having higher resolutions for their normals and that causing a seem - ugh. Hopefully, improving the quality of the normals and always assuming there are no neighbors at the edges will work.

I also fixed a memory leak, but I think I still have some minor ones left somewhere - but that's for later.

It's great to be able to actually fly around a bumpy planet now, even if it does have crazy normals.

No comments: