Zombie Dance

To test the brute force performance of the engine I have rendered 5000 zombies (people and dogs). As one would expect, performance does suffer. FPS drops from a constant 60 to ~20-25. Doing 5000 extra frustum checks per frame is taking allot of time. There are a number of ways I will improve this performance while maintaining support for a high density of zombies.

  • Add spatial partitioning which will divide the world into blocks. Only blocks which can be seen need to be rendered.
  • Only blocks which are within a certain distance need to be populated with zombies and updated. (who really cares whats happening on the other side of the city right now?)

Lets presume I want 20000 zombies in the city. The city measures about 1km x 2km. This gives a zombie density of 10000 per square km or 1 zombie per 100 square meters. (That’s about 1 zombie per 10m X 10m block). Updating and rendering 20000 zombies would kill performance but thankfully we do not have to.

Lets break the world into 50m X 50m blocks. Each block will have 25 zombies.Viewing distance with fog is 200 meters which is 4 blocks. The player can turn at any time so we need to maintain 4 blocks in each direction. That gives us an 8×8 grid of blocks to maintain. (this number decreases when the user is close to the edge of the city). Maintaining these 16 blocks means we have to have 1600 active zombies. Since only a portion of these will be visible at any given time because of a field of view of 37.5 degrees we will only have to frustum check about 25% of the zombies (the rest can be immediately ruled out because the block they are in isn’t visible).