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:

  1. Create new noise texture to lightningNoise1
  2. Set Seamless to true
  3. Add a new gradient to the color ramp
    1. Place offsets at roughly 0.7, 0.75 and 0.8
    2. Set the three color to black, white and black
  4. Add a new FastNoiseLite
    1. Set Noise type to Cellular
    2. Set Fractal/Octaves to 3
    3. Set Fractal/Weighted Strength to 0.38
    4. Set Cellular/Jitter to 1
    5. Set Cellular/Return Type to Distance2Div
    6. Enable Domain Warp
    7. Set Domain Warp/Amplitude to 20
  5. Copy lightningNoise1 to lightningNoise2
  6. Make lightningNoise2 unique
  7. Set lighningNoise1 seed to 0
  8. Set lightningNoise2 seed to 1

 

For noiseVertex:

  1. Add new noise texture
  2. Set Seamless to true
  3. Add new FastNoiseLite
    1. 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;
}
Tags
3d, Electric, godot4, lightning, shock
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

More from thelastflapjack

Distortion bubble

Related shaders

electric ball canvas item

2D lightning

2D Lightning, Electric Arc, plasma

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments