float4 apply_night(float4 color);
float4 apply_twilight(float4 color);
float4 apply_morning(float4 color);
float4 apply_dawn(float4 color);

cbuffer __PROPERTIES : register(b0) 
{
    float __PROPERTIES__hour_of_day;
}

Texture2D __PROPERTIES__input_tex : register(t0);
SamplerState __PROPERTIES__tex_sampler : register(s0);

struct VS_Input
{
    float3 pos : POSITION;
    float2 uv : TEXCOORD0;
};

struct VS_Output
{
    float4 pos : SV_POSITION;
    float2 uv : TEXCOORD0;
};

VS_Output vs_main(VS_Input input)
{
    VS_Output output;
    output.pos = float4(input.pos, 1.0f);
    output.uv = input.uv;
    return output;
}

float4 apply_night(float4 color)
{
    float4 result = color;
    (result -= float4(0.3f, 0.2f, 0.0f, 0.0f));
    (result *= 0.8f);
    return result;
}

float4 apply_twilight(float4 color)
{
    float4 result = color;
    (result += float4(0.2f, -0.1f, 0.1f, 0.0f));
    (result *= 0.9f);
    return result;
}

float4 apply_morning(float4 color)
{
    return (color * 1.3f);
}

float4 apply_dawn(float4 color)
{
    return color;
}

float4 ps_main(VS_Output input)
{
    float4 sampled_color = __PROPERTIES__input_tex.Sample(__PROPERTIES__tex_sampler, input.uv);
    float t = 0.0f;
    float4 a = float4(0, 0, 0, 0);
    float4 b = float4(0, 0, 0, 0);
    if (__PROPERTIES__hour_of_day > 16)
    {
        t = ((__PROPERTIES__hour_of_day - 16) / 6);
        a = apply_twilight(sampled_color);
        b = apply_night(sampled_color);
    }
    else if (__PROPERTIES__hour_of_day > 12)
    {
        t = ((__PROPERTIES__hour_of_day - 12) / 6);
        a = sampled_color;
        b = apply_twilight(sampled_color);
    }
    else if (__PROPERTIES__hour_of_day > 6)
    {
        t = ((__PROPERTIES__hour_of_day - 6) / 6);
        a = apply_morning(sampled_color);
        b = sampled_color;
    }
    else if (__PROPERTIES__hour_of_day >= 0)
    {
        t = (__PROPERTIES__hour_of_day / 6);
        a = apply_night(sampled_color);
        b = apply_morning(sampled_color);
    }

    return lerp(a, b, t);
}

