Our Properties: Gamasutra GameCareerGuide IndieGames Indie Royale GDC IGF Game Developer Magazine GAO
My Message close
Latest News
spacer View All spacer
 
February 10, 2012
 
What drives the developers of Unity?
 
Analyst questions validity of unusual January NPD results [12]
 
Road to the IGF: Lucky Frame's Pugs Luv Beats
spacer
Latest Features
spacer View All spacer
 
February 10, 2012
 
arrow Virtual Goods - An Excerpt from Social Game Design: Monetization Methods and Mechanics
 
arrow Principles of an Indie Game Bottom Feeder [21]
 
arrow Postmortem: CyberConnect 2's Solatorobo: Red the Hunter [1]
spacer
Latest Jobs
spacer View All     Post a Job     RSS spacer
 
February 10, 2012
 
Irrational Games
Systems Designer
 
CCP - North America
Lead Character Artist
 
CCP - North America
Sr VFX Artist
 
CCP - North America
Sr. Tech Artist
 
CCP - North America
Animation Director
 
Toys for Bob / Activision
Senior Programmer
spacer
Blogs

  Fast Object Instancing
by David Rosen on 12/07/09 09:29:00 am   Expert Blogs
2 comments Share on Twitter Share on Facebook RSS
 
 
  Posted 12/07/09 09:29:00 am
 

When I was testing out character shadows on Hale's Riverhurst level, the framerate was not as smooth as I would like it to be. To remedy this, I'm taking a few days to make the engine handle complex scenes more efficiently. My first step was to create a system for fast object instancing (copy-drawing). Because of our modular plants and buildings, most Overgrowth levels consist of many instances (copies) of relatively few unique models, so this is an important feature to optimize. As an example, Riverhurst contains about 4000 instances of the same wooden plank model.Trees are also very good candidates for fast instancing. Here is one of the trees in Overgrowth: 

As you can see in the bottom-left of the screenshot, the framerate is very smooth: 90 frames per second. However, if I create a few dozen more trees, the framerate drops down to 14 -- unacceptably low. 

This is because the renderer is not taking advantage of the fact that the trees are using the same model. The rendering algorithm looks much like this:

for each object in scene{
   setup rendering state
   setup shadersetup texture
   setup vertex arrays
   setup transformdraw
}

This is a problem, because for simple models like this tree, the setup code takes much more time than the actual drawing. This is compounded by the fact that the tree is actually a collection of even simpler objects!

I decided to restructure the rendering loop to look more like this:

for each object-type in scene {
   setup rendering state
   setup shadersetup texture
   setup vertex arrays
   for each object in object-type{
      setup transform
      draw
   }
}

The drawing itself is already as fast as possible, since it's just drawing a vertex buffer object with one line of code, but I further optimized the "setup transform" step by encoding the transformation matrix in the texture coordinates (aka GLSL pseudo-instancing).Now we can draw that same group of trees at 90 frames per second!

 It's still possible to slow the framerate down, but it takes many more trees than before:

Shadows are disabled in these pictures because I'm currently working on efficient texture atlases for shadow maps.This kind of optimization may seem premature, but I think it's necessary so that we can see what level designs are technologically possible. When planning out the story and gameplay, it's important to know whether or not dense forest scenes and complex town scenes can be rendered smoothly. Do you have any ideas about further optimizations I could do, or any questions about how the object instancing works?

Follow us here!
Facebook iconModDB iconSteam iconTwitter iconYouTube icon

 
 
Comments

Chris Howe
profile image
Nice article as usual. :)

Are you planning to do any kind of LOD for your trees? For *really* simple objects (such as reduced-LOD trees in the distance) you can bake multiple copies of the same object into the same vertex buffer. It requires that you pre-transform the verts into world space, but it means no per-object setup cost. I created a system once for creating forests where the user could choose a mesh and paint it over the landscape. The transform for each instance would be randomized slightly, the mesh would be transformed and then it would be baked into the vertex buffer.


James Hofmann
profile image
With regard to "seeing what designs are technologically possible" I think it's actually a really good idea, if the schedule allows it, to build out the tech to a polished state, test as many gameplay features as possible, do early-stage balancing, and set design limits before building final scenes. You can get a sketch of what's possible in test scenes and then push the engine accordingly to take it "all the way." By contrast, building empty/barebones scenes on an unfinished feature set is a very restrictive process for the entire team because it enforces an implicit lock-down of many features and assets, and it inevitably leads to more passes of tuning and bugfixing later.

The main problem with that strategy is that it essentially dictates lengthy pre-production and short production cycles. The game has "nothing to see" for months and months on end, which is nerve-wracking for the leadership and strains resources at the tail end when everything suddenly comes together in one huge crunch.


none
 
Comment:
 




 
UBM Techweb
Game Network
Game Developers Conference | GDC Europe | GDC Online | GDC China | Gamasutra | Game Developer Magazine | Game Advertising Online
Game Career Guide | Independent Games Festival | Indie Royale | IndieGames

Other UBM TechWeb Networks
Business Technology | Business Technology Events | Telecommunications & Communications Providers

Privacy Policy | Terms of Service | Contact Us | Copyright © UBM TechWeb, All Rights Reserved.