Lightning Ball
An electric effect shader which I created to be part of a composite effect which can be seen in the demo video. This is a Godot 4 shader.
The lightningNoise1 and lightningNoise2 uniforms have a specific set up:
- Create new noise texture to lightningNoise1
- Set Seamless to true
- Add a new gradient to the color ramp
- Place offsets at roughly 0.7, 0.75 and 0.8
- Set the three color to black, white and black
- Add a new FastNoiseLite
- Set Noise type to Cellular
- Set Fractal/Octaves to 3
- Set Fractal/Weighted Strength to 0.38
- Set Cellular/Jitter to 1
- Set Cellular/Return Type to Distance2Div
- Enable Domain Warp
- Set Domain Warp/Amplitude to 20
- Copy lightningNoise1 to lightningNoise2
- Make lightningNoise2 unique
- Set lighningNoise1 seed to 0
- Set lightningNoise2 seed to 1
For noiseVertex:
- Add new noise texture
- Set Seamless to true
- Add new FastNoiseLite
- Set Noise Type to simplex
Experiment with noise and other parameter values to get an effect you are happy with!
Shader code
shader_type spatial;
render_mode unshaded, cull_disabled;
uniform sampler2D lightningNoise1;
uniform sampler2D lightningNoise2;
uniform vec3 tint : source_color;
// vertex uniforms
uniform float distortionVertex : hint_range(0.0, 0.3, 0.005) = 0.03;
uniform float speedVertex : hint_range(0.0, 1.0, 0.005) = 0.5;
uniform sampler2D noiseVertex;
void vertex()
{
float noiseVal = (texture(noiseVertex, UV + (TIME * speedVertex)).r * 2.0) - 1.0; // Range: -1.0 to 1.0
vec3 displacement = NORMAL * noiseVal * distortionVertex;
VERTEX = VERTEX + displacement;
}
void fragment()
{
float layer1 = texture(lightningNoise1, UV + (TIME * 0.1)).r * sin(TIME * 5.0);
float layer2 = texture(lightningNoise2, UV - (TIME * 0.1)).r * cos(TIME * 5.0);
ALBEDO = vec3(layer1 + layer2) * tint;
ALPHA = layer1 + layer2;
}