#version 150

#moj_import <light.glsl>
#moj_import <fog.glsl>

// Old Colors
vec3 cherryBiomeColor = vec3(229, 255, 122) / 255;
vec3 whiteColor = vec3(1, 1, 1);
vec3 blueColor = vec3(125, 193, 253) / 255;

// New Colors
vec3 cherryNewBiomeColor = vec3(150, 255, 161) / 255;

vec3 toGrayscale(vec3 color) {
    float gray = 0.21 * color.r + 0.72 * color.g + 0.07 * color.b;
    return vec3(gray, gray, gray);
}

float getCloseColor(vec3 color, vec3 colorToCompare, float min, float max){
    float isClose = length(color - colorToCompare);
    isClose = smoothstep(min, max, isClose);
    return isClose;
}

vec4 getFixedBlueWhiteColor(vec4 color, vec4 texture){
    vec4 finalColorWhite = mix(color * vec4(1.0, 1.0, 1.05, 1), color, getCloseColor(texture.rgb, whiteColor, 0.75, 0.85));
    vec4 finalColorBlue = mix(color * vec4(0.9, 0.9, 1.05, 1), color, getCloseColor(texture.rgb, blueColor, 0.75, 0.85));
    return mix(finalColorBlue, finalColorWhite, getCloseColor(color.rgb, blueColor, 0.25, 0.3));
}

vec4 getCherryBiomeColor(vec4 color){
    return vec4(mix(cherryNewBiomeColor * toGrayscale(color.rgb), color.rgb, getCloseColor(color.rgb / toGrayscale(color.rgb), cherryBiomeColor, 0.1, 0.12)), color.a);
}




