I'm creating an XNA game that requires a huge space for players. Currently, the test heightmap I'm using is 4096x4096, and is saved as a 4-bit BMP.
What I'm trying to do is take that huge heightmap file and render it in the game. The problem I'm running into is the fact that it's inefficient to load the entire terrain into memory at once, as it will use majority of available memory.
Another problem I've run into is that I cannot render the terrain all in one primitive because of a hard-limit set within XNA.
With that said, I've come across a number of solutions, all of which I have listed below:
- Rendering based on the current user's location - basically drawing a square around the user no matter their orientation within the world. This isn't exactly what I wanted either, because you're still rendering space that the user does not see.
- Rendering based on the user's orientation and position - I found a formula to retrieve a triangle that is supposed to have what pixels of the heightmap are supposed to be rendered, but this proved to be very difficult.
- Splitting the terrain into multiple chunks and rendering which ones are closest to the user - Still not very efficient as you're still rendering chunks that people won't see. And it's work-intensive because then I have to split my heightmap into several pieces, and scalability becomes a large problem.
After trying those solutions, I'm fresh out of ideas for what to do. I've received some answers where people are telling me to do these complex algorithms, but I simply have no idea even how to approach doing them.
So basically I'm asking for a simple, straightforward way of rendering humongous terrains in XNA with utmost efficiency.
I'm rather new to game development in general, but I am willing to research if it seems promising.
Update 1: After researching the geoclipmapping method, I started to code with that. I have all the math done, and the game runs. However, it is extremely inefficient - which is probably bad coding on my part. It runs at 2FPS and uses an entire core of my CPU. I'm going to try and improve the code, but I think I'll need more help, so here is a Pastebin of the code for the Terrain manager class. I'll post back with more results later if I ever get it to be more efficient.