I'm rendering a city of several million cuboids that are all axis-aligned, touching each other and same-sized. They only differ in height.
Rendering them as real geometry is vertex-bound and too slow, so I've went with another approach: render them as several flat layers of a single, big texture. The more layers, the better the buildings look. This is similar to how a 3D printer works. Also I've seen it used for rendering hair, grass and snow. In my case, I'm using nearest-neighbor filtering to make the buildings square-shaped, and alpha-testing to control the building heights.
Here's a very zoomed-in screenshot so the individual layers are visible:
This works great, but when I use a higher number of layers, it gets too slow due to the fillrate. The cuboids are opaque so I tried optimizing this by enabling z-testing, but it hardly helped, because my shader is cheap (fixed-function, actually), and it's the only thing z-testing helps to skip. Or maybe it's because on my dev machine I have an Intel GPU and it doesn't do early-z discard.
So now I'm out of tricks. What could be used to optimize this? Also, any common names for the technique?
- I'm aiming for OpenGL 1.4-level hardware, which is pretty restrictive when it comes to optimizing.
- I'm additionally using multitexturing with alpha-modulation to make arbitrarily-shaped, antialiased buildings (not enabled in the screenshot)
- Usually the city is viewed from a RTS-style viewpoint, all of it is visible, and it fills the screen, so fog or LOD techniques wouldn't work