preface

We believe that when playing games, should have seen some monsters after death, burst open, or into thousands of fragments, or into a wisp of smoke, or into a pile of powder, the wind scattered. It feels like the death effect is very interesting.

We all know that Shader can do some cool things, but I also used Shader to create a monster in ashes. Take a look.

On the effect picture.

It starts with four monsters dancing, and then it ends with nothing. The monster turned into a pile of sand, and the powder disappeared. So how does this effect work? Let’s talk about how it works.

When we write Shader scripts, most of the time people can handle a lot of requirements with vertex functions and chip functions. And then some people think that Shader only has vertex functions and slice functions.

In fact, in addition to them, there are other functions, also very useful, such as today’s effect, using another function: geometric function or geometric shader. We all know that vertex functions deal with model vertex correlation and slice functions deal with pixel correlation.

So what does this geometric function look like? You know from the name, it’s related to geometry, but it’s actually a function that deals with elements, which is basically a function that deals with triangles.

We all know that models are made up of grids, and grids are made up of countless triangles. Any object can be made up of innumerable triangles. Ok, so that’s it, let’s talk about how this effect works.

OK, since we said that geometric functions deal with triangles, in general our primitives are pretty much like a triangle is an primitives. Then a triangle is a triangle formed by connecting three vertices.

This is the general case, so what we’re going to do here is we’re going to make the model powder, sand, and so on, so if we’re going to do the previous operation, and all the vertices are joined together, and we’re going to sketch out the whole model, that’s absolutely not allowed, so what do we do?

We can make point primitives from ordinary triangle primitives. Then in order to outline the model as far as possible not fragrant a complete model. We can make these point primitives as far away as possible.

** The way is like this: ** make the triangle diagram element point diagram element, the position of the point is the center of the triangle. Then, here’s what happens, as shown:

This is a normal triangle sketch. Here are the point primitives:

Now I can still see the outline of the model. The next step is to let it go to dust. So how do I do that? Drift. It’s easy. They’re all together now, so I’ll just let them drift away. So who’s staying away?

Obviously, let’s move the vertices. So here we can use a physical formula to calculate the displacement of the vertices. And finally we have this effect. The complete code is as follows:

That’s what the geometric function is all about, and that’s the key to this special effect. The rest is not important, it is the normal way to write rendering objects. This effect function is very nice.

Well, that’s all for this sharing. Have need demo friend please private chat add me.