uniform vec2 size;
varying vec2 v_texCoord;
uniform sampler2D u_texture;

vec3 scanline(vec2 coord, vec3 screen)
{
	screen.rgb -= sin((coord.y + (CC_Time.g * 29.0))) * 0.01;
	return screen;
}


vec3 sampleSplit(sampler2D tex, vec2 coord)
{
	vec3 frag;
    
/*    float temp_time = CC_Time.g;
    
	frag.r = texture2D(tex, vec2(coord.x - 0.0075 * sin(temp_time), coord.y)).r;
	frag.g = texture2D(tex, vec2(coord.x                          , coord.y)).g;
	frag.b = texture2D(tex, vec2(coord.x + 0.0075 * sin(temp_time), coord.y)).b;*/

    float temp_time = CC_Time.g;
    
    float x_px = 1.0/1680.0 * 2;

    frag.r = texture2D(tex, vec2(coord.x - x_px, coord.y)).r;
    frag.g = texture2D(tex, vec2(coord.x                          , coord.y)).g;
    frag.b = texture2D(tex, vec2(coord.x + x_px, coord.y)).b;
	
	return frag;
}

void main(void)
{
	vec2 iResolution = vec2(1680,1050);
	vec2 uv = v_texCoord;//gl_FragCoord.xy / iResolution.xy;
	//uv.y = 1.0 - uv.y; // flip tex
	vec2 crtCoords = uv;

	// Split the color channels
	gl_FragColor.rgb = sampleSplit(u_texture, crtCoords);

	// HACK: this bend produces a shitty moire pattern.
	// Up the bend for the scanline
	vec2 screenSpace = crtCoords * iResolution.xy;
	gl_FragColor.rgb = scanline(screenSpace, gl_FragColor.rgb);
}
