Using the geometry shader to achieve model explosion effect

Jiadong Chen
Jul 31 · 3 min read

0x00 Description

This article will show you how to use the geometry shader to turn the Stanford Armadillo model into sand.

0x01 Implementation

What you may be more familiar with is the “Stanford Bunny”.

They came from models used by Greg Turk and Marc Levoy at Stanford. But the Bunny is so cute, therefore the Armadillo, which looks like a monster, is a good choice. What’s more it has more vertices, so using it for sanding is better.

As you can see, it has 106,289 vertices and 212,574 polygons.

Ok, now let’s import the Stanford Armadillo obj file into Unity and you can see that this monster is already in our scene. Next we will use the geometry shader to achieve the desired explosion visual effect.

When I mentioned the geometry shader, I used it to generate more new vertices and polygons to achieve the desired effect, such as using it to generate grass on the GPU for real-time rendering of real grass.

But the geometry shader can not only generate new primitives, but it also reduces the output of vertices and polygons to achieve some interesting effects, such as the example in this small article, using the geometry shader to achieve the monster’s explosion and sanding effect.

And what we have to do is very simple, that is to change the input triangle composed of 3 vertices into a point composed of only one vertex in the geometry shader.

In this way, the mesh that makes up the monster is changed from triangles to points, and the number of vertices is also reduced. As for the monster itself, it becomes like this:

But the model at this time is static, therefore there is no effect of explosion. So next we have to let the monster’s model move over time.

And a kinematic formula that everyone knows can be used to achieve this effect:

The S is the latest position of the vertex, the values of v0 and a can be passed to the shader as a uniform variable, the direction of motion can be along the normal direction of the triangle, and the value of t is the y component of _Time which is a Unity built-in variable.

Now, we have the variables we need:

Then we just bring them in the kinematics formula:

tempPos += norm * (_Speed * realTime + .5 * _AccelerationValue * pow(realTime, 2));

The final result will look like this:

And you can find the demo here:

Explosion and sand effect

check it out!

0x02 Conclusion

Ok, the above is my blog this week and I hope everyone can gain something!

Jiadong Chen

Written by

Programmer | Author | Blogger | Speaker | Microsoft Developer Technologies MVP | @Unity3d China | Views = my own

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade