#extension GL_EXT_gpu_shader4 : enable

#if __VERSION__ >= 130
  #define varying in
  out vec4 mgl_FragColor;
  #define texture2D texture
  #define gl_FragColor mgl_FragColor
#endif

#ifdef GL_ES 
precision mediump float; 
precision mediump int; 
#endif 

varying  vec4   varying_Color;

uniform float alpha ;
uniform int   invertPattern ;

// const array is not available  
// fill level is 0/16 .. 16/16 
// bounds is 1/32 shifted , 
mat4 pattern = mat4(
		 0 , 8 , 2 ,10 ,
		12 , 4 ,14 , 6 ,
		 3 ,11 , 1 , 9 ,
		15 , 7 ,13 , 5 
	) ;

                               
void main (void) 
{
	int x = int(gl_FragCoord.x ) % 4 ;
	int y = int(gl_FragCoord.y ) % 4 ;
	
	int val = 1 + pattern[x][y] ;  			// 0..15 >> 1..16
	int alphaInt = int( alpha*16 + 0.5 ) ;	// scale & round off 0.5 , 1.5 .. 15.5
	
	if( val <= alphaInt ) discard ;
	gl_FragColor = varying_Color; 
} 
