@vs vs
in vec3 VertexNormal;

uniform mat4 MVP;
uniform mat4 modelMatrix;

out vec3 vpos;
out vec3 vnorm;

vec4 position(mat4 transform, vec4 vertex_position) {

  vpos = vertex_position.xyz;

  vnorm = VertexNormal.xyz;//( modelMatrix * vec4(VertexNormal,0)).xyz;
  
  return  transform*vertex_position;

}
@end
 
@fs fs
layout (location = 0) out vec4 g_diffuse;
layout (location = 1) out vec4 g_normal;
layout (location = 2) out vec4 g_position;

in vec4 pattern;
in vec3 vpos;
in vec3 vnorm;

uniform sampler2D MainTex;

uniform bool drawingShadow;
uniform float time=0;
uniform float dither=0;

mat4 thresholdMatrix = mat4(
1.0 / 17.0,  9.0 / 17.0,  3.0 / 17.0, 11.0 / 17.0,
13.0 / 17.0,  5.0 / 17.0, 15.0 / 17.0,  7.0 / 17.0,
4.0 / 17.0, 12.0 / 17.0,  2.0 / 17.0, 10.0 / 17.0,
16.0 / 17.0,  8.0 / 17.0, 14.0 / 17.0,  6.0 / 17.0
);

void main() {
  vec4 result = vec4(1,1,1,1);
  vec4 texel = vec4(1,1,1,1);
  vec4 col = fragColor;
  vec3 pos = vpos;
  vec3 norm = (normalize(vnorm)+vec3(1))/2;

  result = texel*vec4(col.rgb,1);

  vec2 screen_coords = gl_FragCoord.xy*screenSize;
  if (dither>=1){
    if ((mod(int(gl_FragCoord.x),4) == 1) && (mod(int(gl_FragCoord.y),4) == 1)) {
      result=vec4(1,1,1,1);
    }
  }else if (dither>0 ){
    if ((0 - thresholdMatrix[int(mod(screen_coords.x+floor(time)*dither,4))][int(mod(screen_coords.y+floor(time)*dither,4))] )+0.1>0){
      discard;
    }
  }

  g_diffuse = result;
  g_normal = vec4(norm,1);
  g_position = vec4(pos,1);
}
@end