//Written for the Godot engine in GLSL

shader_type spatial;

render_mode cull_disabled, blend_add, unshaded;

uniform float time_speed = 1.0;

uniform float spin = 0.0; //Twisting motion of the flame

uniform float flame_brightness = 0.6;

uniform float color_intensity = 0.0;

//Tiling frequency of the noise accross the mesh

uniform float horizontal_frequency = 1.0;

uniform float vertical_frequency = 1.0;

//overall size muliplier

uniform float size = -0.3;

//banding bias, affects total size

uniform float core_size = 1.0;

uniform sampler2D noise_texture;

//preset band colors

uniform vec4 color1 : source_color = vec4(0.286, 0.22, 0.733, 1.0);

uniform vec4 color2 : source_color = vec4(0.98, 0.38, 0.34, 1.0);

uniform vec4 color3 : source_color = vec4(0.98, 0.95, 0.53, 1.0);

uniform vec4 color4 : source_color = vec4(1.0, 1.0, 1.0, 1.0);

void fragment() {

float time = TIME * time_speed;

// Calculate dot product of normals and combine with noise texture value

float normal_facing = dot(NORMAL, VIEW);

float noise_value = texture(noise_texture,vec2(UV.x * horizontal_frequency + spin * (time /2.0), (UV.y * vertical_frequency) + time)).r;

normal_facing += (noise_value -0.5 + size) * 0.3;

float band = normal_facing * 3.0 * core_size;

vec4 flame_color = vec4(0,0,0,0);

if (band <= 1.5) {

discard;

}

else if(band <= 2.0){

flame_color = mix(color1, color2, -0.01 / (band-2.01)); //Mixes the color bands to make a slight gradient

}

else if (band <= 2.5) {

flame_color = mix(color2, color3, -0.01 / (band-2.51));

}

else if (band <= 2.9) {

flame_color = mix(color3, color4, -0.01 / (band-2.91));

}

else if (band >= 0.0) {

flame_color = color4;

}

//Final color adjestment

ALBEDO = clamp(flame_brightness * (vec3(1.0, 1.0, 1.0) - (flame_color.xyz * -color_intensity)) * flame_color.xyz, vec3(0.0, 0.0, 0.0), vec3(flame_brightness, flame_brightness, flame_brightness));

}