Game Development Reference
In-Depth Information
1. Validate the presence of vertex color information in meshes that support
damage, otherwise consider this an export error (missing required informa-
tion).
2. For each vertex, compare its color with the colors in the damage areas table.
If the color was not found, then return an error (unknown color code used
for marking a damage area).
3. Obtain the ID of the color found from the table, and store the ID in the
final mesh vertex information. If the vertex does not belong to any damage
area, set the ID to zero.
It is possible to store this number in its own vertex attribute or to try to
compress it. For example, we can store the ID in the vertex normal by
adding 1 to the ID value then multiply it by the vertex normal value. To
extract the value in the shader, simply take the vertex normal length and
subtract 1 from it. The original vertex normal can be reclaimed by standard
normalization. This trick requires no additional space of per-vertex data,
but it might not work if the vertex normal is already compressed by some
form.
This color ID is all that is needed to support hiding the polygons at runtime.
The damage geometry exported with the main object can be processed using the
standard mesh-processing pipeline.
3.4.3
Runtime Step
The final step of the process is to actually use the data to control the visibility of
damage on the object at runtime. For each object supporting damage, we prepare
a bit field that holds flags representing the visibility of each damage area on the
object, where the first bit represents the damage area with ID 1 from the damage
table, and so on. To hide the polygons of the object associated with a particular
color code, we raise the bit matching the ID to 1. Notice that multiple bits may
be set to 1 simultaneously, resulting in the ability to show/hide different damage
area polygons freely. Damage areas that are not “damaged” yet should set their
respective bits in the bit field to 0.
When the time comes to render the object, the damage bit field is set as a
vertex-shader constant. The vertex shader then checks if the damage ID value of
the vertex has its respective bit set to 1 in the bit field. If so, the position of the
vertex is set to (0 , 0 , 0); otherwise it is left untouched.
Note that this bit-check operation is an integer computation that is not sup-
ported by all shader models and current-generation console GPUs. Thus, we will
describe a way to achieve the same result with floating-point mathematics only
for such cases.
 
Search Nedrilad ::




Custom Search