# 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!

Written by