Sample Overview
Games often need to render many copies of the same model, for instance covering a landscape with trees or filling a room with crates. The calls needed to render a model are relatively expensive, and can quickly add up if you are drawing hundreds or thousands of models in a row. This sample demonstrates several techniques you can use to reduce the overhead of drawing many copies of the same model.
Note that there is no single perfect instancing technique. This must be implemented in a different way on Windows compared to Xbox 360, and on Windows the ideal technique requires shader 3.0, but there is also a fallback approach that will work with shader 2.0. This sample implements several different instancing techniques, so it can work on both platforms and shader versions.
These instancing techniques can dramatically reduce the amount of CPU work required to draw models, but they will make little difference or in some cases may even slightly increase the GPU cost. The CPU cost of drawing a model is constant regardless of how complex the model may be, but the GPU cost increases in proportion with the number of triangles and shader complexity. For this reason, drawing low polygon models with simple shaders is likely to be limited mainly by CPU performance, while more detailed meshes are likely to be bottlenecked on the GPU side. If the GPU is your bottleneck, there is nothing to be gained from using these instancing techniques. Also, if your models are large and complex, the memory overhead required to instance them may be prohibitive. Instancing yields the most dramatic performance gains when used with relatively small and simple models: somewhere in the ballpark of 1000 triangles or less.
Instancing requires the vertex and index data to be organized in a particular way. The Model class that comes built in to the XNA Framework is not flexible enough to properly support instanced rendering, so this sample implements an alternative InstancedModel class. A custom Content Pipeline processor is used to convert model data from input file formats such as .X and .FBX into our InstancedModel class: see the Custom Model Class sample for more information about how this works.
|


GS 2.0
VS 2.0
PS 1.1


GS 3.1
VS 2.0
PS 1.1
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/