- Category: Blueprints
- Update: 1.0 (011.02.2020)
- Unreal Engine: 4.18 - 4.24
- Platforms: VR, PC, Console, HTML
Lightning Fast is a powerful combination of materials and blueprints that implements a wide range of realistic and stylized electricity effects.
Lightning effects have plenty of uses in games, from background ambiance during a storm, electronic fences to the devastating lightning guns and spells. This system is designed in mind to achieve all those effects with high performance, AAA quality at the same time.
- lightning flashes
- lightning bolts
- lightning chains
- lightning strikes
- lightning discharges
- lightning beams
- lightning trails
- lightning guns
- lightning electrocute
- GPU friendly and optimized for all platforms
- Wide range of high-quality effects
- Two types o beam rendering (spline mesh/spline billboard mesh)
- Integrated with UE4 dynamic lights and material light functions and splines
- Over a hundred parameters in materials to customize the final effect
- Spline based shape of bolt easy to adjust to the scene
- Character electrocute discharges effect
- Advanced lightning mesh editor tools
- Multiple animated lines rendered in a single beam
- Depth fade/direction fade effect
- Glow and line color
- Refraction based distortion
- Procedural beam texture
- Dynamic branch masking and fading effect
- prototype pack – textures and materials created for demonstration purposes
- mesh generator – advanced tool prepared for editing and generating lightning meshes, allows implementing external lightning propagation class
- demo example map – a showcase of 14 use cases
- Procedural mesh lib – Additional library of functions that helps to create static meshes in UE4
Basically everything starts from the geometry (meshes) and effect (materials) rendered using geometry.
The Lightning Fast mesh combined with the material has some useful features and properties that are very important in the production.
- can be used witch spline meshes
- can be skinned and used as skeletal mesh
- can be scaled and keeps the proper shape
- can be used in a particle system
- can be watched from every angle
That gives us a wide range of effects that the system can handle so the package is divided on multiple blueprints specialized in custom effects.
All of the effects can be found in the Blueprint folder and are presented on ExmapleMap (Demo/Maps/LightningFastMap)
- Find folder Blueprints/LightningBolt
- Drag end drop BP_LightningBolt on scene
- The effect is ready to use. Now you can adjust parameters to get the effect that you need.
Blueprints folder contains multiple lightning effects that show how the system works with materials and meshes is should be treated as example content or templates prepared for general use cases. Some of the effects contain blueprints the other are represented only by particle effects used that main character is using.
Check the Demo/Manequin/ThirdPersonCharacter blueprint to analyze the implementation of the skills.
The list of effects will be extended in future updates.
It’s good practice to create your own effects by inheriting Blueprint classes and copy material instances to your project folder.
The Blueprints/BP_LightningSpline blueprint is a simple combination of mesh spline effects and lights. You can combine any mesh created using Lightning Fast package with splines even bending the lightning bolts is allowed.
Drag and drop BP_LightningSpline on the scene and modify parameters. [Editing splines]
|Static Mesh||Mesh used to bend|
|Material||The material used on mesh|
|Forward Axis||The axis of mesh that is directing forward of bending.|
|Translucency Sort Priority||Rendering priority|
|Fix Spline Direction||Additional correction of spline UP direction. Fixes some twist bugs.|
|Texture Scale||Scale texture UV for beam start and end.|
|Glow Color||Override material glow color.|
|Line Color||Override material line color.|
|Lights Count||Number of lights created for spline|
|Light Snap Curve||Importance of snapping the lights to the curve (0-1)|
|Light Color||Override color of light|
|Light Falloff||Fall off parameter of light.|
|Use inverse squared falloff||Fall of the mode switch.|
|Light Function||The light material function used for blinking|
BP_LightningBolt is a complex example of lightning bolt effect implementation based on lightning spline blueprint. The biggest advantage of this blueprint is that can be easily integrated with every weather system.
|Animation||Bolt animation curves describe how parameter changes during the update. R – time offset, G – fade, B -(not used yet), A- lightning intensity|
|Animation Rate||Speed of animation update.|
|Activation Loops||-1 (infinite), 0 – not active at start, 0> loop counts|
|Activation Delay||Delay until the first activation.|
|Preview Time||Draw debug preview at some time of animation.|
|Retrigger Time||Random time in range (x-y) that system wait until next activation.|
|Use Randomization||Whether the system should randomize rotation and location in Random Volume.|
|Rotation Range||Range of rotation change during randomization.|
|World||The world that manages the light intensity on the scene|
Use parameter World to register blueprint in BP_LightningWorld. The BP_LightningWorld actor is the manager that changes directional light intensity and skylight intensity during the stormy weather according to all managed lightning bolts.
To activate Lightning Bolt by hand (from events) use Activation function and set ActivationLoops = 0.
Dynamically updated chain of splines that connects target points in the closest range.
Simple use case of working with a beam:
- Drag and drop BP_LightningBeam on scene
- Drag and drop a few target actors (BP_lightningTarget) on the scene near to the lightning beam actor.
- Select BP_LightningBeam and edit parameters:
- Find InitChain array and add one element. Setup the starting chain element.
Set TargetActor to self it will make the beam actor the source of effect.
- Play and watch how the beam connects the target actors that are moving around.
Basically the concept of BP_LightningBeam actor is based on the idea that the chain should be represented by multiple nodes connected by spline meshes in a specific order. The list of nodes and order can be set by the user or generated automatically.
The BP_LightningBeam effect is divided on the static and dynamic parts.
- Static (set by user) – predefined, represented by InitChain structure created by the user during activation.
- Dynamic (generated) – generated starting from the last element of the static fragment using an algorithm of searching in range.
InitChain is the array that describes the connections between chain elements. The first element of the array is a root (starting point). For example, the Init Chain of lightning guns can be represented by 2 nodes. The first node is the gun muzzle and the second one is the hit point. The ParentIndex is the index of the parent node in the InitChain.
You can even specify a looping shape in init chain by this kind of config:
InitChain = (TargetActor=Target0, ParentIndex=0) //start, points to self so it’s empty
InitChain = (TargetActor=Target1, ParentIndex=0) //spline from element 0 to Target1
InitChain = (TargetActor=Target2, ParentIndex=1) //spline from element 1 to Target2
InitChain = (TargetActor=Target0, ParentIndex=2) //spline from element 2 to Target0 (loop)
|Init Chain Node||Description|
|Target Actor||The actor used as node in the chain. The algorithm uses the location of the actor as the endpoint of the spline mesh.|
|Parent Index||The index of element InitChain array where the algorithm will look for the starting point of the spline mesh. InitChain[ParentIndex].TargetActor is used to set the location.|
|Target Location||If the target actor is null then Target Location is used.|
|Target Normal||Overrides the normal direction of spline mesh. It can be used to change the shape f spline.|
|Source Direction||Overrides the source direction of spline mesh. It can be used to change the shape f spline.|
|Null Target||How to react if the actor is destroyed/null:
The last element of the InitChain is the starting point of searching. The searching uses the attributes in the Search tab to specify which actor should be in the dynamic chain.
After the InitChain is specified then there it comes to dynamic chain generation. ChainLength is the number of spline meshes that can be rendered by BP_LightningBeam actor. The ChainLength attribute is used to calculate how many additional nodes should be generated. The number of the dynamic nodes that algorithm will look for is ChainLength reduced by the number of renderable connections specified in the Init Chain.
Example situation (lightning gun)
ChainLength = 4
InitChain contains 2 elements, the connection between start point(muzzle) and one target point is represented by 1 spline mesh.
Finally, algorithm will look for 4-1 = 3 target points and try to render 3 additional spline meshes.
The algorithm of searching is simple:
- Find closest target actor in range to the last element of the chain
- Add the element to the chain.
- If CombinedChain is smaller than ChainLength then goto 1
After the searching process, all the nodes are linked together in a chain 0-1-2-3 … -n. UseClosestToChain=true option runs an additional update that changes the topology of the chain to render the shortest possible spline meshes. Basically it looks for closest connections between nodes.
A complex example of Lightning gun implementation based on Lightning Beam blueprint.
Particle emitter that presents discharges effect.
Effect of trail attached to the actor example content was used as a ribbon behind the character during a slow-motion run.
Object targeted by lightning gun and other skills. Target also spawns an example discharges particle when it is attacked by a lightning beam or lightning gun.
Folder contains a base class of dynamic light source components and light materials.
M_LightningFast is the heart of the package and all material subtypes derive functionalities from this advanced master material.
Creating material instance in UE4 is really simple. Click right on the material (M_LightningFast) and chose option “Create Material Instance”. After that operation the newly created material will be ready to configure and use on Lightning Fast meshes. You can do the same with all material instances created for specific cases stored in the blueprints folder which I am recommending to do first.
The material has a very high potential for setting up and create a wide range of effects. The following list includes all available configuration options with usage recommendations. Some of the parameters can be hard to describe and understand at first but I encourage you to test it in the engine and check the results of changes. 🙂
List of general basic options.
|MeshWidthScale||Scales the geometry of billboarding mesh.|
|OpacitClamp||Opacity clamping for high values.|
|UseBillboardMesh||True – use billboarding system for rendering, false – render original mesh|
|UseDebugMesh||Draw debug mesh|
|UseRefraction||Use the refraction effect.|
|RefractionClamp||Clamp intensity of refraction effect.|
|UseVertexInterpolators||Optimization that forces system to use interpolators (does not work with particle emitters)|
Group of parameters that helps to fade effect in some specific conditions. Close to the wall or unpleasant angle.
|UseNormalFade||Normal fade is the feature that helps to hide beam when its in bad wrong related to mesh. The fade is calculated based on the normal vector of the mesh. For the mesh in billboard mode the normal means axis of rotation. When the Axis is similar to the camera direction then mesh should be invisible because we can notice some bugs.|
|NormalFadeScale||Scale the effect makes it fade faster or lower|
|NormalFadeOffset||Offset the effect to make it more visible.|
|Fade||Makes effect translucent.|
|UseDepthFade||Whether lightning should fade when intersecting scene meshes.|
|DepthFadeScale||How fast lightning should fade when intersecting scene meshes.|
|UseVertexFade||Vertex color of lightning meshes contains additional information about fade this option allows to use the for fading begin and end of the node.|
|VertexFadeStart||Scale vertex fade start|
|VertexFadeEnd||Scale vertex fade end|
The lightning beam is build of four branches that can be displayed at the same time or one after one. This section covers the basic settings.
|UseBranchFading||Activate the algorithm of asynchronous fading of branches.|
|BranchFadngAlpha||Alpha multipliers of each branch of beam stored separately in RGBA channels.|
|BranchFadingOffsets||Time offsets in fading animation.|
|BranchFadingPower||Exponential fading speed of endpoint.|
|BranchFadingSource||Fading blend in of start point.|
|BranchFadingScale||The scale of fading UV.|
|BranchFadingTimeScale||Branch fading animation speed.|
|BranchFadingOffset||External controller of branch fading time.|
|UseBranchCombine||Combine branches into one beam. Set False to use separate colors.|
|UseBranchCombineMax||Combine branches by max function. False forces system to use sum function.|
|UseAlphaChannelBranch||Use the fourth branch from the alpha channel.|
Masking is the feature implemented for randomly hiding the branches of lightning. Even static meshes can look dynamic and various thanks to masking some of the nodes during the update.
Beam configuration focused on UV mapping transformations.
UV mapping of distortion texture:
Additional skew UV offset stretches the distortion.
|UseBeamBlend||Beam blend is the effect of the fading beam on start and end.|
|BeamBlendStart||The intensity of start beam blending.|
|BeamBlendEnd||The intensity of end beam blending.|
|UseVertexColorUVOffset||Adding UV offset based on vertex color R-value. Parameter helps to make mesh beam look more variable.|
|BeamUVScaleSpeed||Most important parameter|
Bolt is the effect that allows animated offsetting of the beam position on the mesh.
Whether the bolt animation should be active.
|BoltStart/BoltEnd||Start/end position of bolt.|
|BoltMoveOffset||Sets the offset of bolt animation (can start from any point)|
|BoltMoveRange||Sets the value range of bolt animation.|
|BoltMoveSpeed||Speed of bolt animation.|
Each beam is created of multiple light lines that are distorted by noise texture. The texture is moving so the effect looks dynamic and chaotic.
|DistoritonScale||Scales the distortion effect.|
|DistortionTexture||The texture used for distortion offset and detail distortion offsets.|
|UseDistortionDetail||Whether distortion detail should be active.|
|DistortionDetailUVScale||Scales the UV mapping of detailed distortion.|
|DistortionDetailScale||Scales the intensity of detailed distortion.|
Describes basic parameters of the line that is distorted and generates glow.
|LineColor||Color of line|
|GlowColor||Color of glow effect around the line|
|GlowTexture||The texture used for masking glow.|
|GlowTextureScaleMove||Animating glow texture RG-Scale, BA-Move|
|UseGlowTexture||Whether the glow texture effect should be active.|
Width of line.
Line disappearing in distance from the start point of lightning.
Material supports two modes of rendering glow effect around line Hard/Soft. The first one based on smoothstep function and the second one based on division by distance.
Lightning Fast package contains mesh editor BP_LightningMesh that allows creating unique lightning meshes. Drag and drop blueprint on scene Blueprints/LightningMesh/BP_LightningMesh to start creating a lightning mesh.
Each mesh is generated from a node list (attribute Nodes array). The node list is an array that contains a graph of connections between nodes described using a special structure called BS_LightningNode.
|Parent||This attribute describes the index from an array of the parent nodes. Each node has a parent. If the parent of the node has the same index as the source node than the parent is the root(starting point) of the hierarchy generated from the node list.|
|EndPos||Location of the ending point. It can be edited visually in the main viewport as well by selecting and using translation gizmo.|
|Loop||A value higher or equal 0 is the index of loop endpoint. The -1 is the default and means that there is no loop.|
|Priority||Higher priority means that the node describes the main branch.|
|TangenInOut||The scale of the tangent input-output vector.|
The package comes witch additional tools that help to create unique lightning meshes in the Unreal Engine 4 editor. There are two methods of editing Nodes array.
- Editing by hand using Tree Editor
- Editing using Tree Generator
Tree editor is the basic method of editing the node list there are multiple buttons that increase the speed of building the new branches of lightning mesh.
|Node Append||Append the child to the selected node (selected node index).|
|Node Insert||Divide the selected node (selected node index) by inserting a node in the middle.|
|Node Remove||Removing the selected node (selected node index).|
|Node Selected Get||Load data from the selected index to Selected node Data.|
|Node Selected Set||Save data from Selected Node Data to the selected node (selected node index).|
|Node transform||Transform a selected node by Transform to apply attribute.|
|Reset||Clear the tree.|
Lightning Fast has an advanced system of mesh generators that can be used to automatize the creating of wide range meshes.
Working with generators is simple:
- Add generator to the Generator List used by the BP_LightningMesh editor.
- Chose the class of generators LTG_Branch
- Click Evaluate All Generators
- Double click on the generator instance and edit parameters and click “Evaluate All Generators” again.
BP_LightningTreeGenerator is the base lightning generator class that can be extended by other generators by overriding the Evaluate function.
Example generators provided in version 1.0 of the package described below:
LTG_Branch – Example generation that creates branched lightning effects.
LTG_Spline – Example generator that creates lightning based on spline shape.
Create static mesh
A generated mesh can be easily converted to static mesh and used in other blueprints and particle effects. Few steps needed to do this:
- Select BP_LightningMesh blueprint and find component called ProceduralMesh
- Find option UseDynamicMaterial and set to false.
- Click button Create Static Mesh
- Select where to save the mesh
UseDynamicMaterial = false forces system to use default not instanced material. If you will skip this step then newly created meshes will contain reference to instanced material ant wont save.
Questions & Answers
Integration with Fast Stylized Procedural Sky?
Yes! Last update of Stylized Procedural Procedural Sky supports integration with Stylized Procedural Sky just place lightning bolt on map and activate it on event from build in lightning system.
It is worth buying?
Hell yes! After four mounts of:
- researching the topic,
- watching thousands of photos and videos with lightning effects,
- testing multiple solutions,
- removing huge amounts of unsatisfying effects
- hard time spend on iterations and optimizations
I can ensure you now that it's not worth to do it by yourself from the beginning when you have finished solution and my support. I would never start again if I would could... 😉