// Plasma Pulse shader
// Adapted from https://godotshaders.com/shader/scifi-hologram/

shader_type spatial;
render_mode unshaded, cull_back;

uniform mediump vec3 albedo: source_color = vec3(0.9, 0.0, 0.7);

uniform bool transpose_axis = false;

uniform mediump sampler2D wave_gradient;
uniform mediump float wave_width: hint_range(0, 10) = 1;
uniform mediump float wave_speed: hint_range(-1, 1) = 0.4;

uniform mediump vec4 glow_color: source_color = vec4(0.5, 0.75, 1.0, 1.0);
uniform lowp float glow_intensity: hint_range(0, 20) = 0.618;
uniform lowp float glow_amount: hint_range(0, 20) = 4.5;

uniform mediump sampler2D pulse_gradient;
uniform mediump float pulse_speed: hint_range(0, 10) = 0.3;

vec3 fresnel_glow(float amount, float intensity, vec3 color, vec3 normal, vec3 view) {
	return pow((1.0 - dot(normalize(normal), normalize(view))), amount) * color * intensity;
}

void fragment () {
	float canvas = -UV.x;
	if(transpose_axis) {
		canvas = -UV.y;
	}
	float wave_value = texture(wave_gradient, vec2((canvas + TIME * wave_speed) / wave_width, 0)).r;

	vec3 fresnel_color = vec3(glow_color.r, glow_color.g, glow_color.b);
	vec3 fresnel = fresnel_glow(glow_amount, glow_intensity, fresnel_color, NORMAL, VIEW);

	float pulse_value = texture(pulse_gradient, vec2(TIME * pulse_speed, 0)).r;

	ALBEDO = albedo + fresnel;
	EMISSION = glow_amount * vec3(glow_color.r, glow_color.g, glow_color.b);
	ALPHA = wave_value * pulse_value;
}