Game Development Reference
extern float damageBitArray; // Set to maximum size needed.
VS_OUTPUT VS_Main(VS_INPUT In)
// Check whether this vertex belongs to a "damaged" area.
// Damage ID is compressed with vertex normal.
float damageID = round(length(In.normal))-1;
if (damageID > 0)
// Assume a single-precision floating-point number
// can represent an integer number of about 24 bits.
damageID = modf((damageID-1)/24, bitArrayIndex) * 24;
float damageBitField = damageBitArray[bitArrayIndex];
float damaged = checkBit(damageBitField , damageID);
In.position *= 1.0f-damaged; // Collapse vertex if damaged
Listing 3.3. Sample code of the more complex case of supporting an unrestricted number
of damage areas in the vertex shader.
2. Rendering each damage geometry in a separate draw call: This is the di-
rect method, but it suffers from increased draw-call count per damaged
object. For certain platforms, this can be more e cient than wasting time
processing hidden damage-geometry vertices all the time.
Level of Detail
One important aspect to 3D objects is that they might be authored in multiple
levels of detail (LODs), which are used to increase rendering eciency at runtime
by reducing the geometric detail of a 3D object as it covers smaller area of the
screen. Since our technique is tightly bound to the topology of the 3D object,
any change in this topology requires adjusting the marked damage polygons and
their replacement damage geometry. This requires that when the artist builds
additional LODs for a certain 3D object, he must remember to mark the dam-
age polygons in those additional LODs in a similar way to the main LOD. The
replacement geometry could also benefit from having LODs of their own, but in
some cases authoring LODs for those pieces of geometry is not necessary, and the
main LOD version can be reused as is with lower main-object LODs. It really
depends on the type of 3D object and how it was modeled.