///IS THIS EVEN USE?
///
/// COLOR CORRECTION (final pass) on a bitmap but blending between to luts...



#ifdef GL_ES
precision mediump float;
#endif
uniform sampler2D al_tex;
uniform sampler2D depthTexture;

uniform sampler3D ColorGradingLUT;
uniform sampler3D ColorGradingLUT2;
uniform float LUTMix;

uniform bool al_use_tex;
varying vec4 varying_color;
varying vec2 varying_texcoord;


const float lutSize = 16.0;
const vec3 scale = vec3((lutSize - 1.0) / lutSize);
const vec3 offset = vec3(1.0 / (2.0 * lutSize));

///for film noise haha
uniform float randSeed;
uniform float randSeed2;
uniform float noiseamount;

float rand(vec2 co){
    return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}

void main()
{
	if (al_use_tex) {

		vec4 rawColor = varying_color * texture2D(al_tex, varying_texcoord);
		vec4 lutSample = texture3D(ColorGradingLUT, scale * texture2D(al_tex, varying_texcoord).rgb + offset);
		vec4 lutSample2 = texture3D(ColorGradingLUT2, scale * texture2D(al_tex, varying_texcoord).rgb + offset);

		//gl_FragColor = lutSample;
		
		
		//mix lut samples depending on blend amount
		vec4 finalLutSample = mix(lutSample, lutSample2, LUTMix);
		//vec4 finalLutSample = lutSample2 + (0.0000001 * lutSample);


		///add noise
		gl_FragColor = finalLutSample + (noiseamount * clamp(rand( vec2(randSeed+gl_FragCoord.x, randSeed2 +gl_FragCoord.y)), 0.0,1.0));

		///just output..
		//gl_FragColor = finalLutSample;

		
		//get alpha value but ... yeah
		gl_FragColor.a = texture2D(al_tex, varying_texcoord).a;
		if (gl_FragColor.a < 0.001) {
			gl_FragColor.r=0.0;
			gl_FragColor.g=0.0;
			gl_FragColor.b=0.0;
			gl_FragColor.a=0.0;
		}
		
		///visualize depth texture -- REMEMBER TO BIND IN SHADER MANAGER (LUTDrawing)
		/*
		if (varying_texcoord.x < 0.5) {
			gl_FragColor.rgb = texture2D(depthTexture, varying_texcoord).rrr;
			//gl_FragColor.g=0;
			gl_FragColor.b=1;
	   		gl_FragColor.a=1;
		}
		*/

		
	} else {
   		gl_FragColor = varying_color;
  		
	}
}


