Disintegration Effect in Unity

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Nowadays, in the video game world, it's not uncommon to find a disintegration effect applied to the body of the fallen enemies. This kind of effect is also often used to recompose the player when it spawns. Today we'll recreate this effect on Unity. The core of the effect is to break a mesh into pieces and move them away like a group of particles. Usually, in Unity, this is done by using a particle system or a VFX graph, but to keep greater control of the whole mesh we wanted to use a different kind of approach. We created this using a shader. To be more specific, since we want to subdivide the mesh and manipulate the divisions we used a geometry shader. This is the same kind of shader that we used in the fur effect video. If you are not familiar with it, this shader is able to access and modify the primitives that compose a mesh. The first operation was to move each triangle of the mesh detaching it from the others. Instead of moving all of them in the same direction, we used a flow map to control the direction and the speed of the flow. This is a special texture that contains 2D vectors. The vector's U component is in the Red channel while the V component is in the Green one. We sampled it using the position in the world space of each triangle and then we re-mapped the result between -1 and 1. Also, we used an external direction and a multiplier to calculate the final position. We exposed a value that we used as a weight for the interpolation between the original and the target position. Changing this value moves the triangles away. To scale down and vanish the triangles we used the average position between the vertices and let them converge to it during the lerp. The effect was simultaneous for all the triangles, but we wanted to follow an order instead. So we introduced a dissolve map. We sampled it using the average UV of each triangle and we used the result to affect the weight of the interpolation. This way all the triangles detach from the mesh at different times following the map. The mesh was correctly divided and all the pieces were able to fly away, but with this simple division, the triangles were quite evident either in solid and in the already detached parts. The solid part was simple to fix. First of all, we kept a copy of each triangle in the geometry shader, this copy stays in position untouched and its color was set to black. Then, we used the dissolve texture in the fragment shader and clipped the mesh accordingly. This approach is super common for the dissolve effect. The difference, in this case, is that we also check the color of the fragment before clipping it to be sure to apply this only to the solid part. Back to the triangles, we created a little quad for each triangle that is detached from the mesh This is the same technique that we used in the real-time fluids video. Since the quads are flat, we wanted them to face the camera. This effect is called "Billboard" and we achieved this by changing the Up and the Right value according to the inverse transpose of the model multiplied by the view matrix. Square particles are not super interesting! We wanted to give them a custom shape. To do that we used a grayscale texture, and since every quad has its own UV coordinates we used them to sample it. We used the result to choose if keeping or discarding the pixels. Also, we change the color to enhance the particles and get them bright. In the end, we added another pass that calculates the shadows and we repeated all the operations into it. We've created an animation, added a bit of bloom and this is the final result. Let us know in a comment below what you think about this effect. Don't forget to subscribe, smash the like button and follow us on the other socials. See you next time, cheers!
Info
Channel: TNTC
Views: 33,999
Rating: undefined out of 5
Keywords: vfx, vfx breakdown, unity, disintegration, gamedev, unity3d, game development, gameart, development, indie, TNTC, tntc, unity3d tutorial, game dev, indie gamedev, water, unity geometry shader, geometry shader, disintegration shader, dissolve shader, dissolve effect, pulverize, pulverize shader, particles shader, death effect, unity enemy death animation, unity enemy death effect, unity shader tutorial, unity game dev, unity game development, shader
Id: ndhFZ7WlWB8
Channel Id: undefined
Length: 5min 16sec (316 seconds)
Published: Fri Nov 27 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.