Skip to content

Instantly share code, notes, and snippets.

@max-lv
Created June 2, 2017 13:37
Show Gist options
  • Save max-lv/92fda992a6ef9f6eee46f311982ed6b7 to your computer and use it in GitHub Desktop.
Save max-lv/92fda992a6ef9f6eee46f311982ed6b7 to your computer and use it in GitHub Desktop.
precision highp float;
varying vec3 n;
varying vec2 uv;
uniform sampler2D tex;
uniform vec2 resolution;
const vec3 BLACK = vec3(0.0);
const vec3 WHITE = vec3(1.0);
const float pix = 1.0;
vec3 middle(float size) {
vec4 pos = floor(gl_FragCoord / pix);
if(mod(pos.x, size) < 1.0 && mod(pos.y, size) < 1.0) {
return BLACK;
}
if(mod(pos.x+size/2.0,size) < 1.0 && mod(pos.y+size/2.0,size) < 1.0) {
return BLACK;
}
return WHITE;
}
void main(void)
{
// constants & options
vec2 pos = floor(gl_FragCoord.xy/pix)/300.0*pix;
const float grads = 5.0; // color levels
vec4 img = texture2D(tex, pos);
float gray = (img.x + img.y + img.z) / 1.5;
gray = floor(gray*grads) / grads;
float st = 1.0/grads;
vec3 color = vec3(gray);
for(int i=0; i<int(grads); i++) {
if(gray < st*1.02*float(i+1) && gray >= st*0.98*float(i)) {
if(i==0) { color = BLACK; break; }
if(i==int(grads)) { color = WHITE; break; }
color = middle(2.0+float(i-2)*2.0);
//break;
}
}
gl_FragColor = vec4( color, 1.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment