Masked VAT extends standard VAT 2.1 playback by enabling each rigid body to playback independently of each other.
Partially destroyed house
The typical approach for Vertex Animation involves looking up the position and rotation of a vertex for a given frame time. Masked VAT modifies this by also looking up the playback StartTime for each body independently. This enables each rigid body to be playing a different frame. This is used to eject pieces over various times instead of all at once.
To accomplish this, a dynamic “VATMask” texture is created and modified by the game. It is very small, only 1 x NumRigidBodies in size. This texture a single float representing the StartTime to eject the body (or 0 if not ejected). The material looks up this start time using the same uv coordinate index (RigidbodyIdx) that is used to lookup the position and rotation vat textures.
In the material, this looks like this (remember this feeds WPO and is run in the vertex shader and not in the fragment shader):
TexCoord[1] contains the rigid body index for the incoming vert. The DynVAT texture contains the time to eject the particle. If this is 0, then the first frame ends up being used. Otherwise, the frame is calculated for the desired playback time by subtracting the StartTime from the CurrentTime.
Updating the DynVAT texture
In UE4 c++, we create a texture that stores 1 x NumberofRigidBodies. Anytime the mesh is damaged, we update this texture, setting the eject time for every piece we want to eject. To determine which rigid bodies need to be affected by the damage we use a specialized AABB tree. An AABB is an Axis Aligned Bounding Box. By constructing a Bounding Volume Hierarchy of AABBs, we are able to quickly determine whether a given body lies in a certain damage region and should be ejected.
Creating AABBs By Wrapping Packed Primitives
When a piece of geometry is damaged, we want to only eject the pieces in the damage radius. To determine this list of pieces, we use a special AABB Tree that contains the bounding volumes for each piece. Note - this is intentionally done completely outside of the UE4 Physics Collision Scene so as not to increase the size or complexity of the collision scene. Thus, when our troll smashes a wall with a club, we can quickly determine which pieces need to be ejected.
Creating the AABB Tree
In Houdini, we make an additional pass over the points that represent each packed rigid body and calculate the bounding box size and center of that piece. This list of points is exported via a json, and used in UE4 to build an AABB tree at runtime used for collision playback.
In Houdini we loop over each packed primitive (rigid body) and calculate and store the bounds.
Exporting JSON from Python in Houdini
The following script is attached to the HDA and can be run from a button. Exporting the actual JSON is pretty straightforward - simply build up a dictionary with the data you want and dump it to json. (Ideally, this step could be fully integrated with the regular VAT export)
Here is the Python script :
Some Videos In Action
Thanks for sharing Nice idea !! Can u give me some more details of setting vex in attributewrangle 17 & 19?
hard to understand how the vat uv working~
for me after set up the Vat material in ue4 the object doesn't work correct~
hope you can record a little tourtial about this for better understand vat。