/*
 * Pixelate GLSL Shader
 * http://www.geeks3d.com/20101029/shader-library-pixelation-post-processing-effect-glsl/
 * 
 * textureId (sampler2D):  the final scene image.
 * rt_w (float):          render target width (GeeXLab built-in uniform)
 * rt_h (float):          render target height (GeeXLab built-in uniform)
 * pixel_w (float):       width of a low resolution pixel
 * pixel_h (float):       height of a low resolution pixel
 */
uniform sampler2D textureId; // 0
uniform float rt_w; // GeeXLab built-in
uniform float rt_h; // GeeXLab built-in
uniform float pixel_w; // 10.0
uniform float pixel_h; // 10.0
void main (void)
{ 
  vec2 uv = gl_TexCoord[0].xy;
  
  vec3 tc = vec3(1.0, 0.0, 0.0);
  
    float dx = pixel_w*(1./rt_w);
    float dy = pixel_h*(1./rt_h);
    vec2 coord = vec2(dx*floor(uv.x/dx),
                      dy*floor(uv.y/dy));
    tc = texture2D(textureId, coord).rgb;
  
	gl_FragColor = vec4(tc, 1.0);
}