
// If you change the input channel texture, disable this:
#define HAS_GREENSCREEN

// Uniform variables for texturing
uniform sampler2D 	aaa_tex2d[4];

// Dimension of textures : 0, 1, 2, 3 dimension, -1 if unused per Tex Unit
uniform	int			aaa_tex_dim[4];

// Size of Texture for each texture unit
uniform vec2		aaa_tex_0_size;

// 0 = time
// 1 = mouse X
// 2 = mouse Y
uniform float		aaa_pu_float[6];


float character(float n, vec2 p) // some compilers have the word "char" reserved
{
	p = floor(p*vec2(4.0, -4.0) + 2.5);
	if (clamp(p.x, 0.0, 4.0) == p.x && clamp(p.y, 0.0, 4.0) == p.y)
	{
		float k = p.x + 5.0*p.y;
		if (int(mod(n/(exp2(k)), 2.0)) == 1) return 1.0;
	}	
	return 0.0;
}

void main()
{
	vec2 uv = gl_FragCoord.xy;
	vec3 col = texture2D(aaa_tex2d[0], floor(uv/8.0)*8.0/aaa_tex_0_size.xy).rgb;	
	
	#ifdef HAS_GREENSCREEN
	float gray = (col.r + col.b)/2.0; // skip green component
	#else
	float gray = (col.r + col.g + col.b)/3.0;
	#endif
	
	float n =  65536.0;             // .
	if (gray > 0.2) n = 65600.0;    // :
	if (gray > 0.3) n = 332772.0;   // *
	if (gray > 0.4) n = 15255086.0; // o 
	if (gray > 0.5) n = 23385164.0; // &
	if (gray > 0.6) n = 15252014.0; // 8
	if (gray > 0.7) n = 13199452.0; // @
	if (gray > 0.8) n = 11512810.0; // #
	
	vec2 p = mod(uv/4.0, 2.0) - vec2(1.0);
	if (iMouse.z > 0.5)
	{
		col = gray*vec3(character(n, p));
	}
	else
	{
		col = col*character(n, p);
	}
	
	gl_FragColor = vec4(col, 1.0);
}