{"id":956,"date":"2009-11-20T23:06:32","date_gmt":"2009-11-20T12:06:32","guid":{"rendered":"http:\/\/www.vectorstorm.org\/?p=956"},"modified":"2009-11-20T23:06:32","modified_gmt":"2009-11-20T12:06:32","slug":"dividing-space","status":"publish","type":"post","link":"https:\/\/www.vectorstorm.com.au\/2009\/11\/20\/dividing-space\/","title":{"rendered":"Dividing space"},"content":{"rendered":"
Continuing in my tradition of working on things which can’t have screenshots taken of them…<\/p>\n
I’ve recently begun a short-term goal of putting a forest of thousands of trees into MMORPG Tycoon 2. \u00a0This task has two obvious sub-tasks, and a few non-obvious sub-tasks.<\/p>\n
The obvious sub-tasks are (1) create a tree model — preferably using the procedural geometry creation systems which I’ve already built, so that we can have a couple of different types of trees without any extra labour on my part. \u00a0And (2), put lots of copies of those tree models into the world.<\/p>\n
The big non-obvious sub-task is that I need to come up with a mechanism so that I won’t be sending every tree in the world to the graphics card to be rendered every frame — only the ones which could potentially be visible right now. \u00a0But at the same time, I don’t want the CPU to overload itself, testing each individual tree to see whether it might be visible.<\/p>\n
In video games, the usual approach to this sort of problem is to divide up space, and then test the different bits of space for visibility, instead of testing each individual object. \u00a0You can think of it a little like arranging lots of small objects on a chess board — instead of checking each tiny object to see whether it could be visible, you instead can check each square of the chess board to see whether that square might be visible, and if so, then draw every object inside that square.<\/p>\n
This approach is usually a pretty good compromise between spending a lot of time on the CPU determining precisely what objects will be visible when drawn by the graphics card, and between spending a lot of time on the graphics card drawing objects which turn out not to even have been in front of the camera.<\/p>\n