Website powered by
Making Of / 25 April 2021

Lightningstrikes VFX Breakdown

The task at hand

For my second Games project at The Game Assembly, I was tasked with creating “lightning strikes” visual effects. The effect was intended to be used for several different parts of the game, so versatility was important. Since the particle system in our engine didn’t allow for custom meshes, nor advanced behavior, I took the approach of creating the lightning's behavior in a custom shader.

Let there be Light..ning strikes

Demo-Scene in Blender. This Shows two differently set up Lightning-strike meshes using the same material. The meshes are deformed in place using curve modifiers. 

The core of the lightning-strike shader is that it is a mesh-flipbook. Basically, a mesh containing all of the lightning-strikes appearances is masked out component by component, creating an animated look. The shader cycles through a defined amount of increments between 0 and 1, which is compared to the vertex color information of the flipbook mesh. When the mask's value is within range of any value of the flipbook mesh, that part of the mesh is made visible on the screen.

The Blender Material used to proof the effect before writing the HLSL Shader.

The flipbook part of the mask enables me, or any other artist, to quickly design a group of lightning-strike meshes, and then, by assigning them unique vertex color values (in this case stored in the red channel), the mesh would instantly be compatible with the shader. Based on “segments”, a user-defined parameter in the shader, the shader is described how many frames the flipbook has, and how many value increments the shader should cycle through. To make sure that the mesh vertex colors will also align with the number of segments defined in the shader, the vertex color values of the mesh get rounded up to each valid frame.

Above Frame: Vertex color values are rounded to nearest valid increment value of the mask.
Below Frame: The flipbook-mask, based on the defined speed of the effect and flipbook segmtents, a value-mask is defined. The mask jumps from one valid value to the next, rather than being a smooth transition, this gives it the flipbook-effect.

On top of the flipbook, I multiply another mask, a looping fade. Using the blue channel of the vertex color set I can instruct a dissolve/fade effect. The entire lightning appears in full when it's segment is masked, but using this added layer, the artist can control what parts of the lightning fades first, giving more life to the effect.

Left: The vertex colors of the meshes instructring the effects behaviour. Right: Lightning strikes!

HLSL

To run in our own proprietary game engine, Monostein Engine, the shader was translated from the material graph in Blender to HLSL code.

Going Procedural

For the protagonist, our animators had the idea of creating a modular, magic gun containing procedurally animated moving components. The gun itself was a charge-pistol, meaning that the longer you held the trigger, the more powerful the blast. I had the idea that just like the pistol's animations, the pipeline for creating the lightning-strike meshes for the charge-pistol could be generated procedurally.

The network I drafted in Houdini work as follows: The components of which I want electricity to be generated are put in a group. Points with assigned normal directions are then scattered across all selected pieces. From these, vectors are then generated where a ray cast from any point hits another component in the same "electric" group. Using parameters to control the length of the vectors to be cast, there is also a small amount of user control for what kind of lightning strike-lengths make for valid vectors. Based on the desired amount/count of lightning jolts that are to be generated, 1 polyline is selected and saved every amount/animation-length frames. In the end, this leaves the user with a set of vectors, that match up with the procedural gun's animation x amount of times during its animation length. Finally, these curves can be used as a reference for copying a lightning-jolt mesh along with them, creating the final mesh output.

 A short demo showing of the procedural pipeline for creating the lightningstrike meshes for the gun.

In the end, the gun didn't get a wide variety of procedural animations, so the procedural generation of it's meshes were scrapped. Instead I got to finish a draft of temporary lightningstrike meshes that I had created using curve deformers in blender. Using object IDs as a complement for authored vertex colors, concepting the shape and design of the lightning was fairly quick, and the hand-made ribbons for the guns 3 different "levels" could be produced in barely any time at all.