#version 330 core 
#define GLSL_VERSION 3.00
#define PI 3.14159265359

out vec4 FragColor;

in vec2 uv;

uniform vec3 data;

void main() {
    //float time=data.x;
    float rad=PI/180.0;
    //float time=(data.x * 1.0 / 86400) * 25000; // 50 breaks
    //float time = ((data.x * 25000.0f) * rad) * 25; // 50 breaks
     float phase = data.x;



//-- // Example: Day-night cycle
   //-- float light = 0.5 + 0.5 * sin(uTime); // 0 to 1 over 86400 seconds
   //-- 
   //-- // Example: Cloud movement
   //-- vec2 cloudOffset = vec2(sin(uTime), cos(uTime)) * 0.5;
   //-- 
   //-- // Example: Star twinkle every 10 seconds
    float twinkleSpeed = 86400.0 / 3;
   //-- float twinkle = sin(uTime * twinkleSpeed);

    //float time = sin(phase * twinkleSpeed);

    float time = phase / (2.0 * 3.14159) * twinkleSpeed;
    ///vec2 flame_uv = uv + vec2(0.0, offset_y);


    float x = uv.y;
    float y = uv.x;

    // Calculate flicker using multiple sin and cos functions
    float flicker = 0.0;
    flicker += 0.5 * sin(y * 2.0 - time * 1.0);
    flicker += 0.3 * cos(y * 4.0 - time * 2.0);
    flicker += 0.2 * sin(y * 8.0 - time * 4.0);
    flicker += 0.1 * cos(y * 16.0 - time * 8.0);

    // Amplitude based on y position
    float amplitude = max(0.0, 1.0 - x);
    float total_flicker = amplitude * flicker;

    // Adjusted y position
    float adjusted_x = x + total_flicker;
    float adjusted_y = y + total_flicker;
    //adjusted_y adjusted_x;

    // Determine color based on adjusted_y
    vec3 color;
    float t=0;
    if (adjusted_y < 0.0) { // black
        color = vec3(0.0, 0.0, 0.0); // No fire below y=0
    } else if (adjusted_y < 0.5) { // red to yellow
        t = adjusted_y / 0.2;
        color = mix(vec3(1.0, 0.0, 0.0), vec3(1.0, 0.5, 0.0), t);
    } else { // yellow to white
        t = 1.0 - (adjusted_y - 0.5) / 0.5;
        color = mix(vec3(1.0, 0.5, 0.0), vec3(1.0, 1.0, 0.5), t);
    }

    // Set the fragment color
    //vec3 color=vec3(0.0,1.0,0.0); // test green
    FragColor = vec4(color, t);
}
