logo80lv
Articlesclick_arrow
Research
Talentsclick_arrow
Events
Workshops
Aboutclick_arrow
profile_login
Log in

How to Set Up Lightning Effects with Unreal Engine 5

Dmitrii Sokolov talked about how lightning strikes can be created in UE5 and After Effects using Advanced Lightning, which can create lightning bolts procedurally, combined with noise texture and UV distortion to animate the effect.

Introduction

Hi everyone! I'm Dmitrii Sokolov, a VFX Artist at Saber Interactive. But on X and YouTube, most people know me as balaganvfx. In this article, I'll share a bit about the pipeline for creating lightning effects in Unreal Engine 5.

This example actually comes from a tutorial that I made for my course, so it intentionally includes several different ways to create lightning effects for games. But all of them start with the same thing: getting a texture.

The simplest way is to generate it in After Effects. There's a default effect called Advanced Lightning, which allows you to create lightning bolts procedurally. We make a few different variations, disable the glow, and then create a spritesheet. For that, I use the Sheetah plugin.

Lightning Touch

Well, I have three different textures for three other examples. Let's start with the simplest lightning effect. Previously, in Unreal Engine 4, I used a Masked material for lightning, and it worked perfectly, maintaining performance. However, due to the new default anti-aliasing in Unreal Engine 5, I must use the Additive material type to prevent ghosting during fast particle animations.

In material using noise texture and UV distortion technique, we create the animated wobble of the lightning bolt. It is important to make a gradient mask for the distortion so that the beginning of the lightning does not move and stays in place. Then we animate emissive values for flash and fade the bolt out using a Power node in the material to thin out its width.

Lightning should have a short lifetime (0.3-0.4 sec). We create the lightning bolts using a regular Sprite Renderer in Niagara. To switch between sprites, use the Sub UVAnimation module. You can set the switching time to a value shorter than the lifetime, for example, 0.2.

This will allow the particle to switch to another sprite once during its lifetime, creating an additional animation. You can leave them camera-facing, but they look much more realistic when they're fixed in 3D space.

To achieve this, we offset the pivot to one side and set them to be Velocity Aligned. After that, we can direct the velocity wherever we need, using very small speed values so the bolts don't fly off too far. That's how the basic lightning effect is made.

The next type of lightning is the connecting bolt (second spritesheet from the picture above). We use it for arcs that go from a hand to different objects. Because of that, the start and end of the spritesheet need to align on the same line, so we can tile them properly.

Although nothing stops you from using more "frayed" textures for short distances. The material and animation setup are the same as in the previous example.

What's interesting here is how we use them. We can use the classic Ribbon Renderer and stretch a particle from point A to point B using a Beam module in Niagara. But when we need to create a lot of lightning bolts, Ribbon Renderer becomes less convenient and less performant.

That's where we can use a regular Sprite Renderer together with the Line module and distance fields to connect the bolt to surfaces. I showed this method in a short video I previously posted on X. This way, we can make lightning strike surfaces without using ribbon renderers.

But the only thing I forgot to mention in the video is that you need to turn off the sprite rotation (set Sprite Rotation in Initialize Particle module to Unset), which is often set to Random by default and confuses many people:

And the third method of creating lightning is to use three different bolts stored in the RGB channels, instead of spritesheets. This way, the texture can have a much lower resolution while still providing good variation.

A long time ago, I saw an interesting method in this video. In it, a VFX artist who goes by the name M5VFX switches channels directly in the material using color vector to animate the lightning. For example, dot product texture by a red vector (1,0,0) gives you only the red-channel bolt.

Dot product by blue (0,0,1) gives the bolt stored in the blue channel. And the dot product by purple (1,0,1) gives you two channels at once, and so on. However, I didn't like that, to animate the channel switching, he had to bring in an additional texture (which he scrolls quickly using a Panner node to shift the colors). So I improved this method with a bit of HLSL code inside the material.

I generate a pseudo-random number, which I then use to decide which color vector to dot product the texture with at a given moment. I also added black vectors (0,0,0) into the array so that there are random moments when the bolt disappears entirely.

The pseudo-random sequence itself is generated by multiplying time by 0.618. And this number wasn't chosen randomly (kek), it's approximately amount of the inverse of the golden ratio. Using the inverse of the golden ratio gives you a pseudo-random sequence that is more evenly distributed in terms of probability across different values.

Conclusion

In the material, we can also slide the lightning texture using a Panner. Then I use a regular Sprite Renderer in Niagara, and animate the bolt with emissive, just like in the previous examples. I place it vertically using the Position module (which is basically similar to Velocity Alignment). Add a bit of width animation, and you get this simple lightning strike from thin air:

Choose whichever lightning-creation technique fits your pipeline the best. And feel free to add some sparks, flares, and light as seasoning (just go easy on the spices!).

Dimka Sokolov, VFX Artist

Join discussion

Comments 0

    You might also like

    We need your consent

    We use cookies on this website to make your browsing experience better. By using the site you agree to our use of cookies.Learn more