/*
==============[ BASAHIN / PLEASE READ ]===============

[ENGLISH]
• AZIFY SHADER EXTRA FILE !!
• This file use to calculate shaders function
• Don't break this file !!

[TAGALOG]
• AZIFY SHADER DAGDAG NA FILE !!
• Ang file na ito ay ginagamit para ma buo ang Shader
• Wag Mong sirain ang file na ito !!

===========================================
*/
#define time TOTAL_REAL_WORLD_TIME
#define invr(x) (1.-x)

// Tonemapping
// Credits: https://www.shadertoy.com/view/WdjSW3

// AZIFY TONEMAP
vec3 AzifyToneMap(vec3 x) {
    float A = 2.38;
    float B = 0.05;
    float C = 2.32;
    float D = 0.38;
    float E = 0.38;
    float F = 1.0;
    x = x*(A*x+B) / (x*(C*x+D) + E/F);
return (x-dot(x, vec3(0.1)))*1.5+0.05;
}

// AZIFY TONEMAP 2nd GENERATION
vec3 TONE2(vec3 x) {
    float A = 2.35;
    float B = 0.05;
    float C = 2.39;
    float D = 0.40;
    float E = 0.40;
    float F = 1.0;
    x = x*(A*x+B)/(x*(C*x+D)+E/F);
return (x-dot(x, vec3(0.1)))*1.5+0.05;
}

// ACES TONEMAP
vec3 TonemapACES(vec3 x) {
    float A = 2.51;
    float B = 0.03;
    float C = 2.43;
    float D = 0.59;
    float E = 0.14;
    x = x*(A * x + B) / (x * (C * x + D) + E);
return (x-dot(x, vec3(0.1)))*1.5+0.05;
}

// ACES 2 TONEMAP
vec3 ACES2(vec3 x) {
    x *= 0.85;
    const float a = 1.04;
    const float b = 0.03;
    const float c = 0.93;
    const float d = 0.56;
    const float e = 0.14;
return clamp((x * (a * x + b)) / (x * (c * x + d) + e), 0.0, 1.0);
}

// REINHARD TONEMAP //This is so easy bro//
vec3 Reinhard(vec3 x) {
return x / (0.7 + x);
}

// EXTENDED REINHARD TONEMAP







// ACES FILM TONEMAP
vec3 AcesFilm( vec3 x ) {

	float a = 4.6;
	float b = 0.1;
	float c = 3.6;
	float d = 0.48;
	float e = 0.5;
return((x*(a*x+b))/(x*( c * x + d ) + e ) );}







// TONEMAP FOR NETHER
vec3 Nether( vec3 x ) {

	float a = 2.6;
	float b = 0.1;
	float c = 1.6;
	float d = 0.48;
	float e = 0.5;
return((x*(a*x+b))/(x*( c * x + d ) + e ) );}




// END TONE
float filmic_curves(float x) {
  float A = 1.48; 
  float B = 0.15; 
  float C = 0.15; 
  float D = 0.65; 
  float E = 0.05; 
  float F = 0.35;
return ((x * (A * x + C * B) + D * E) / (x * (A * x + B) + D * F)) - E / F;
}
vec3 End (vec3 cx) { // final step
  float W = 1.3 / 1.0; 
  float LUM = dot(cx, vec3(0.0, 0.3, 0.3)); // luma
  vec3 CHOR = cx - LUM; // chroma
  cx = (CHOR * 1.70) + LUM;
  cx = vec3(filmic_curves(cx.r), filmic_curves(cx.g), filmic_curves(cx.b)) / filmic_curves(W); return cx;
}



vec3 jodieReinhardTonemap(vec3 c) {
  float l = dot(c, vec3(0.2126, 0.7152, 0.0722));
  vec3 tc = c / (c + 0.4);
  return mix(c / (l + 1.7), tc, tc);
}






vec3 RTxBE(vec3 x){
    float A = 1.0;
    float B = 0.1;
    float C = 0.7;
    float D = 0.5;
    float E = 0.02;
    float F = 0.5;
   return (((x * (A * x + C * B) + D * E) / (x * (A * x + B) + D * F)) - E / F); 
   }



vec3 simpleReinhardToneMapping(vec3 color) {
	float exposure = 1.4;
	color *= exposure/(1. + color / exposure);
	return color;
}


vec3 saturation(vec3 rgb, float adjustment) {
    const vec3 wpos = vec3(0.2125, 0.7154, 0.0721);
    vec3 intensity = vec3(dot(rgb, wpos));
    return min( mix(intensity, rgb, adjustment), vec3( 1.0, 1.0, 1.0 ));
}












highp float hash( highp float n ){
  return fract(sin(n)*43758.5453);}
highp float hash(highp vec2 p){
  return fract(cos(p.x + p.y * 332.) * 335.552);}
highp float noise(highp vec2 x){
  highp vec2 p = floor(x);
  highp vec2 f = fract(x);
  f = f*f*(3.0-2.0*f);
  highp float n = p.x + p.y*57.0;
return mix(mix( hash(n+  0.0), hash(n+  1.0),f.x), mix( hash(n+ 57.0), hash(n+ 58.0),f.x),f.y);}






  // Voronoi
#define F length(.5-fract(v.xyw*=mat3(-0,-1,2, 3,-2,1, 1,2,2)*

highp float voro( highp vec2 uv ){
  uv *= 20.;
  highp vec4 v = vec4(uv,uv.x+uv.y,uv.x+uv.y);
  v.xy = uv*(sin(v=vec4(time*0.0)).w+1.5)/2e2;
  v = pow(min(min(F.5)),F.4))),F.3))), 3.0)*3.+vec4(0,.35,.5,1);
return v.r;
}





// Credits: https://www.shadertoy.com/view/WdjSW3

// • AZIFY SHADER
// • Version = 1.3.834
// • Made on Philiphines (March,10,2022)
// • Last Change on (Friday,March,17,2022)
// • Under MIT License!!