/*
 * Crosshatch Shader
 * http://www.geeks3d.com/20110219/shader-library-crosshatching-glsl-filter/
 * 
 * PARAM NAME		TYPE			DESCRIPTION					DEFAULT
 * textureId		sampler2D		the texture input			0
 * hatch_y_offset	float			controls the hatch size		5.0
 * lum_threshold_1	float										1.0
 * lum_threshold_2	float										0.7
 * lum_threshold_3	float										0.5
 * lum_threshold_4	float										0.3
 */

uniform sampler2D textureId; 
uniform float hatch_y_offset; 
uniform float lum_threshold_1; 
uniform float lum_threshold_2; 
uniform float lum_threshold_3; 
uniform float lum_threshold_4; 
void main() 
{ 
	vec2 uv = gl_TexCoord[0].xy;
  
	vec3 tc = vec3(1.0, 0.0, 0.0);

	float lum = length(texture2D(textureId, uv).rgb);
	tc = vec3(1.0, 1.0, 1.0);

	if (lum < lum_threshold_1) 
	{
		if (mod(gl_FragCoord.x + gl_FragCoord.y, 10.0) == 0.0) 
			tc = vec3(0.0, 0.0, 0.0);
	}  

	if (lum < lum_threshold_2) 
	{
		if (mod(gl_FragCoord.x - gl_FragCoord.y, 10.0) == 0.0) 
			tc = vec3(0.0, 0.0, 0.0);
	}  

	if (lum < lum_threshold_3) 
	{
		if (mod(gl_FragCoord.x + gl_FragCoord.y - hatch_y_offset, 10.0) == 0.0) 
			tc = vec3(0.0, 0.0, 0.0);
	}  

	if (lum < lum_threshold_4) 
	{
		if (mod(gl_FragCoord.x - gl_FragCoord.y - hatch_y_offset, 10.0) == 0.0) 
			tc = vec3(0.0, 0.0, 0.0);
	}
  
	gl_FragColor = vec4(tc, 1.0);
}