Sign in to follow this  
spek

Rendering a cell grid

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this