Breaking glass effect PART V

Conclusions

After having worked out all the game prototype scripting, this last part contemplates on performance issues, other ideas, references and other implementations out there.
glass shuttered by high-velocity projectile

 

Talking about Effectiveness and Realism

My approach calculates the impact point on the glass object, and then splits the original mesh into a number of tetrahedron children meshes, where each tetrahedron is made from one triangle of the original mesh and a new vertex at the impact point. If the original mesh had m triangles, then this approach creates m new shard meshes that replace the original mesh after it has been broken. Now, you may wonder, how effective is this? Moreover, is it realistic?


Well, to be honest, in a standard game where you have a lot of meshes to break the answer is no and no. It is a simplistic approach that is used to demo some basic mesh manipulation, and let others learn from that. If one would like to better model a glass mesh breaking apart, would study how glass is cracked or shuttered in real life (see the 2 pictures in this post).

security glass shuttered

In the first picture, a typical cracking pattern is the result of a high-velocity projectile hitting the glass surface at a mostly perpendicular direction to the surface plane. Look at how concentric circles are formed around the impact point, and crack lines starting from the impact point like radius.

In the second picture we have a security glass frame like the one put in the front and back shields in cars. Look at the cracking pattern that is formed after the impact, is resembles to a Voronoi pattern.

So, definitely the cracking pattern created by the mesh manipulation approach should be altered in order to be more realistic, but I wonder what the impact would be in terms of performance. I leave it to you to find out.

What other people did on this subject

The glass breaking effect has been discussed many times in the Unity forum, from many angles and for very varying game requirements.

Most implementations for a similar effect for Unity entail prefabricated shards that are instantiated (spawned) just after the initial object is hit. The original glass object immediately disappears, either having been destroyed or by having its renderer and collider disabled. This is an effective strategy, with low computation requirements, easy to implement, and scales well with a lot of such glass-made objects in the scene (e.g. an FPS shooter while shooting with an automatic weapon at a skyscraper).

I am providing here a -not explicit but representative- list of threads on this subject:


If on the other side you would prefer a more realistic effect, or when the breaking surface /object is large enough for the simple prefab technique to produce nice results, you will need some kind of mesh manipulation or mesh splitting. So from my perspective with this small demo, the breaking glass effect can be seen as a special case of the general topic of mesh manipulation. In Unity forum, there is a couple of references to such approaches that are really interesting:

Future directions

Some enhancements can certainly be made to the current project:
  1. Instead of applying force to the barycentre of the glass shards when GlassTerrain (the glass object) breaks appart, we could add the force to the impact point (vertice) of each shard. The shards are rigid bodies, and the physics engine would simulate their trajectory more realistically.
  2. Having the shards being rigid bodies increase the performance bottleneck when there are many of them in the scene at the same time. A simple improvement would be to disable their collider when they hit the ground. An alternative would be to be destroyed when they disappear from the camera (this may need some raycasting from the camera to each shard or some other method)
  3. A hybrid approach between prefabricated shards and mesh manipulation should be the optimum solution: making a kind of LOD mechanism, and determining from the distance of the camera to the glass object whether we will go for the former (pre-fab) or the latter (mesh splitting) approach. 
  4. Some rather minor aesthetic improvements can be made for the sake of polishing the demo. As you may have noted, VisibleHorizon is a hollow sphere used to check when the balls are colliding with it and to destroy them as soon as they exit its collider. It can get a proper texture (a skybox-type), have its normals flipped (already done in the code but not explained in this series) and be rendered. Some materials can be improved as well, and have some shaders on them.
  5. Finally, I would like to re-write the mesh cutting script and implement my version of BTM's approach for glass-breaking objects, which I believe is the most balanced solution between performance impact and realism (see link above). Thanks BTM for sharing this, very clever idea actually, which I will discuss in another series of posts, devoted to destroyable worlds (yes, how to wreak havoc in a game scene!).

References

  1. A nice Computer Graphics approach into modelling cracks is the following, although it goes after realism rather than performance efficiency (and acceptable illusion) that are normally sought after in computer game implementations: Aurelien Martinet, Eric Galin, Brett Desbenoit, Samir Akkouche, "Procedural Modeling of Cracks and Fractures", available at http://artis.imag.fr/Publications/2004/MGDH04/modellingShort.pdf
  2. KlaRo115 on the Unity forum has shared his implementation of a destroyable buildings package that can be found here: http://forum.unity3d.com/threads/169718-Destroyable-Buildings-v4/page2. It might be used to get an idea into a more structured (and constructive) approach to breaking up things. Thanks KlaRo115 for sharing.
  3. An implementation (for sale in the asset store) that seems to be a pre-cut mesh glass object ready to be smashed to pieces. As the author says "The pieces of glass are hand modelled, they fit together like a puzzle and match the exact mesh they come from". Always useful to look at commercial solutions (do you know of others?): http://forum.unity3d.com/threads/137765-Destructible-Mesh-Glass-With-Physics

YOUR OWN IDEA HERE

Why not contributing your idea for this effect in the comments area below? Also, feel free to comment on my post and correct any factual errors, or just simply provide your own view. If it is indeed contributing to this subject, I would be more than happy to include it in the post and properly attribute you for it.

Comments