[gd_resource type="ShaderMaterial" load_steps=3 format=2]
[ext_resource path="res://assets/shaders/electric/noise.png" type="Texture" id=1]
[sub_resource type="Shader" id=1]
code = "shader_type spatial;
render_mode blend_add,depth_draw_never,cull_disabled,diffuse_burley,specular_schlick_ggx,unshaded;
uniform float health: hint_range(0.0, 1.0);
uniform float shield_level: hint_range(0.0, 1.0);
uniform vec4 primary_color : hint_color;
uniform vec4 damage_color: hint_color;
uniform sampler2D texture_albedo : hint_albedo;
uniform float animate;
const float ground_glow_width = 0.7;
const float edge_glow_width = 1.0;
const float lightning_smoothness = 0.1;
const float distort = 1.0;
vec3 neon(float val, vec3 color) {
float ramp = clamp(val, 0.0, 1.0);
vec3 outp = vec3(0.0);
ramp = ramp * ramp;
outp += pow(color, vec3(4.0)) * ramp;
ramp = ramp * ramp;
outp += color * ramp;
ramp = ramp * ramp;
outp += vec3(1.0) * ramp;
return outp;
}
float sample_both_tex(vec2 uv1, vec2 uv2) {
return smoothstep(
-lightning_smoothness, lightning_smoothness,
texture(texture_albedo,uv1).r - texture(texture_albedo,uv2).g
);
}
void fragment() {
vec4 shield_color = mix(damage_color, primary_color, health);
vec2 uv_distort = texture(texture_albedo, UV).bb * distort;
vec2 base_uv1 = UV * 2.0 + vec2(0.0, animate) + uv_distort;
vec2 base_uv2 = UV * 2.0 + vec2(animate, 0.0)+ uv_distort;
float center = sample_both_tex(base_uv1, base_uv2);
float lightning = clamp((0.5 - abs(center - 0.5)) * 1.5, 0.0, 1.0);
float edge_glow = pow(1.0 - dot(NORMAL, VIEW) / edge_glow_width, 2.0);
// highlight when near surfaces
float depth_tex = textureLod(DEPTH_TEXTURE,SCREEN_UV,0.0).r;
vec4 world_pos = INV_PROJECTION_MATRIX * vec4(SCREEN_UV*2.0-1.0,depth_tex*2.0-1.0,1.0);
world_pos.xyz/=world_pos.w;
float near_surface = clamp(1.0-smoothstep(world_pos.z+ground_glow_width,world_pos.z,VERTEX.z),0.0,1.0);
//ALPHA=
near_surface = clamp(1.0 - near_surface, 0.0, 1.0);
float intensity = 0.0;
float shield_level_glow = 1.0 - abs(UV.y - (1.0 - shield_level)) * 50.0;
if (UV.y > (1.0 - shield_level)) {
intensity += clamp(lightning, 0.0, 1.0);
intensity += edge_glow;
}
intensity += near_surface;
intensity += clamp(shield_level_glow, 0.0, 1.0);
float damage = 1.0 - health;
vec3 lightning_color = neon(intensity - damage * 0.5, shield_color.rgb);
ALBEDO = lightning_color;
}
"
[resource]
shader = SubResource( 1 )
shader_param/health = 1.0
shader_param/shield_level = 1.0
shader_param/primary_color = Color( 0.0862745, 0.470588, 0.984314, 1 )
shader_param/damage_color = Color( 0.584314, 0.305882, 0.858824, 1 )
shader_param/animate = 4.976
shader_param/texture_albedo = ExtResource( 1 )