Energy Shield with Hit Ripples (hex grid, no textures)
A sci-fi energy shield for Godot 4: fresnel rim, a scrolling hexagon grid, a soft pulse, and up to 4 impact ripples at the same time. No textures, no UVs needed (the hex grid wraps around the mesh with no seam).
Tested by hand in Godot 4.7 with the Compatibility renderer, so it also works in web exports. Unshaded, additive, no depth write.
How to use
- Add a MeshInstance3D with a SphereMesh around your character (96 radial segments looks smooth).
- Give it a ShaderMaterial with this shader (material_override).
- Tweak shield_color, energy, rim_power, hex_scale, hex_strength, scroll_speed, pulse_speed.
- appear goes from 0 to 1 to raise the shield from the bottom (nice for “shield up”).
- Hits: each hit_N is vec4(local x, y, z, age in seconds). Age below 0 = off. The ripple grows with ripple_speed and fades out after ripple_life.
Helper script for hits (put it on the shield MeshInstance3D, then call $Shield.hit(bullet.global_position)):
extends MeshInstance3D
var _hits: Array[Vector4] = []
func hit(global_point: Vector3) -> void:
var p := to_local(global_point)
_hits.push_front(Vector4(p.x, p.y, p.z, 0.0))
if _hits.size() > 4:
_hits.resize(4)
func _process(delta: float) -> void:
var mat := material_override as ShaderMaterial
if mat == null:
return
for i in 4:
if i < _hits.size():
var h := _hits[i]
h.w += delta
_hits[i] = h
mat.set_shader_parameter("hit_%d" % i, h)
else:
mat.set_shader_parameter("hit_%d" % i, Vector4(0, 0, 1, -1))
Glow in your WorldEnvironment makes it pop.
Code written with AI assistance, tested by hand in Godot 4.7.
If you want shields, auras, impacts and 1,600+ more effects already set up for Godot 4: https://pixeldreamerstd.gumroad.com/l/vfxcol?utm_source=godotshaders
Shader code
// Energy Shield with Hit Ripples - free Godot 4 shader (MIT) - Pixel Dreamer Studio
// Put it on a SphereMesh (or any closed mesh) around your character.
// Hits: set hit_0..hit_3 = vec4(local_x, local_y, local_z, age_in_seconds) from a script
// (age < 0 = off). A small helper script is in the description.
// Tested by hand in Godot 4.7 with the Compatibility renderer (works in web exports).
shader_type spatial;
render_mode blend_add, unshaded, depth_draw_never, cull_disabled;
uniform vec4 shield_color : source_color = vec4(0.25, 0.75, 1.0, 1.0);
uniform float energy : hint_range(0.0, 8.0) = 1.0;
uniform float rim_power : hint_range(0.5, 8.0) = 2.6;
uniform float base_alpha : hint_range(0.0, 1.0) = 0.06;
uniform float hex_scale : hint_range(1.0, 40.0) = 9.0;
uniform float hex_line : hint_range(0.01, 0.4) = 0.08;
uniform float hex_strength : hint_range(0.0, 2.0) = 0.3;
uniform float scroll_speed : hint_range(-2.0, 2.0) = 0.12;
uniform float pulse_speed : hint_range(0.0, 8.0) = 1.4;
uniform float ripple_speed : hint_range(0.1, 6.0) = 1.8;
uniform float ripple_width : hint_range(0.02, 1.0) = 0.14;
uniform float ripple_life : hint_range(0.1, 4.0) = 1.1;
uniform float ripple_strength : hint_range(0.0, 6.0) = 1.4;
uniform float appear : hint_range(0.0, 1.0) = 1.0; // 0 = hidden, animate to 1 to raise the shield from the bottom
uniform vec4 hit_0 = vec4(0.0, 0.0, 1.0, -1.0);
uniform vec4 hit_1 = vec4(0.0, 0.0, 1.0, -1.0);
uniform vec4 hit_2 = vec4(0.0, 0.0, 1.0, -1.0);
uniform vec4 hit_3 = vec4(0.0, 0.0, 1.0, -1.0);
varying vec3 local_pos;
void vertex() {
local_pos = VERTEX;
}
// distance to the nearest hexagon edge (0 = on the line)
float hex_edge(vec2 p) {
const vec2 s = vec2(1.0, 1.7320508);
vec4 c = floor(vec4(p, p - vec2(0.5, 1.0)) / s.xyxy) + 0.5;
vec4 h = vec4(p - c.xy * s, p - (c.zw + 0.5) * s);
vec2 q = dot(h.xy, h.xy) < dot(h.zw, h.zw) ? h.xy : h.zw;
q = abs(q);
return 0.5 - max(dot(q, s * 0.5), q.x);
}
float ripple(vec4 hit, vec3 p) {
float age = hit.w;
if (age < 0.0 || age > ripple_life) return 0.0;
float d = distance(normalize(p), normalize(hit.xyz)); // distance across the shield surface
float ring = 1.0 - smoothstep(0.0, ripple_width, abs(d - age * ripple_speed));
float spot = (1.0 - smoothstep(0.0, ripple_width * 1.5, d)) * (1.0 - smoothstep(0.0, 0.25, age));
float fade = 1.0 - age / ripple_life;
return (ring + spot * 0.7) * fade * fade;
}
void fragment() {
float fres = pow(1.0 - clamp(abs(dot(NORMAL, VIEW)), 0.0, 1.0), rim_power);
vec3 n = normalize(local_pos);
// wraps around the mesh without UVs: whole number of cells around = no seam
float cols = floor(hex_scale * 3.0);
vec2 hp = vec2(atan(n.z, n.x), asin(clamp(n.y, -1.0, 1.0)) + TIME * scroll_speed) * cols / 6.2831853;
float hex = 1.0 - smoothstep(0.0, hex_line, hex_edge(hp));
float pulse = 0.65 + 0.35 * sin(TIME * pulse_speed + n.y * 6.0);
float r = ripple(hit_0, local_pos) + ripple(hit_1, local_pos) + ripple(hit_2, local_pos) + ripple(hit_3, local_pos);
float shown = 1.0 - smoothstep(appear * 2.4 - 1.25, appear * 2.4 - 1.15, n.y);
float a = (base_alpha + fres * pulse + hex * hex_strength * (0.25 + fres + r) + r * ripple_strength) * shown;
ALBEDO = shield_color.rgb * energy * a;
}


Comments 0
No comments yet.