Rendering a cell grid

Started by
1 comment, last by spek 18 years ago
Hi, I'm trying to render a city, GTA1 style, but then isometric. Therefore, I have a 2D cell grid. Each cell contains information about entities (trees,bins, etc.) and the amount of 'stores'. Each cell can have multiple stores. Each store is a cube with a certain material, so this way you could create simple houses. Now my question is, how to render it fast? The geometry / polycount isn't a problem, but I'm afraid the 'material switches' could be. With material I mean the texture applied on a cube(a brick wall, a road texture etc.). For example, I could render with this pseudo code:

// Loop through the 2D cell grid
for x=0 to width
  for z=0 to depth
    // render stores(cubes) for each cell
    for y=0 to cell[x,z].height
       cell[x,z].store[y].material.apply
       cell[x,z].store[y].render
Pretty simple, and I could check the camera position to cull cells outside the view frustrum. But as you can see, I need to apply the material for each cube again. A couple of switches is not that bad, but things will get slow if I need to render many cubes. Normally I would fix it by sorting everything. First render everything with texture1, then texture2, etcetera. But those were static scenes where the culling wasn't that dynamic, so the sorting had to be done only once. Is there a fast way to sort for this type of game? Or maybe there's another better approach? Greetings, Rick
Advertisement
You can pack your textures into larger textures to save on the switches. This technique is know as Texture Atlases.
Developer Journal: The Life of Corman
Of course! Smart idea. Normally this won't work since the textures are repeated, but in this case I could use texcoords offset. The texcoords are always in the 0..1 range, so that should work.

Thanks for the tip!
Rick

This topic is closed to new replies.

Advertisement