Bounce Effect

This post is part two in the post series on my re-implementation of the GDC talk “The Inner Workings of Fortnite’s Shader Based Procedural Animations”. For the other parts, click here.

The second shader implemented is the shaders for bounce effects. The idea is that the objects should “wobble” a bit at the point were something impacted them. Here, we need to input some information into the shader: An impact location and an axis along which the wobble should happen. In the shader, we do a distance calculation: The effect should be centered on the impact location and fall off linearly until the maximal distance. This is done by calculating this distance and dividing it by the maximal distance, then clamping the resulting value. Then, an animation input value is used to modulate an offset that is added to the vertices. This offset is calculated by multiplying the impact normal by the animation value. Since this offset is also modulated by the distance falloff, it will result in more wobbling in the center and less at the fringes. The figure shows you the gradient and the resulting scaling of the normal.

A visualization of the effect: At point p, an impact is generated. The normal n at this point is used to animate the vertices in a radius by modulating the normal.

A visualization of the effect: At point p, an impact is generated. The normal n at this point is used to animate the vertices in a radius by modulating the normal.

The actual curve could be created in the shader with a linearly falling part and a sine wave, but to be consistent with the presentation, I decided to drive it using an animation that has a curve shape.

The animation value, realized as a Unity animation fed into the material property of the shader.

The animation value, realized as a Unity animation fed into the material property of the shader.

In practice, the animation will be triggered when a character or something has impacted an object and the object should wobble. In the demo, you can walk around with a character and hit a wall to trigger the effect. Alternatively, you can use the mouse to send rays into the scene that impact the wall. It’s a nice and simple effect to create a cartoonish soft body look, and it’s easy to implement. The only downside is that your objects have to have enough vertices so you get a gradual falloff, if the object were flat and modelled with only a plane, of course the effect would not work.

You can find the source code on github, like the other examples of this series. The character model used in the demo is the model “Two-Swords Warrior” by David Lopez Portoles. To detect collisions, colliders are attached to the character’s swords.

Leave a Reply

Your email address will not be published.