Skip to content

Instantly share code, notes, and snippets.

@ykob
Last active July 18, 2018 00:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ykob/08f335981f2f95dcf8d8d525a9a9e7b6 to your computer and use it in GitHub Desktop.
Save ykob/08f335981f2f95dcf8d8d525a9a9e7b6 to your computer and use it in GitHub Desktop.
fragment shader of mosaic filter
uniform vec2 resolution;
uniform sampler2D texture;
varying vec2 vUv;
const float mosaic = 12.0;
void main() {
vec4 color = vec4(0.0);
vec2 offset = vec2(mod(gl_FragCoord.x, mosaic), mod(gl_FragCoord.y, mosaic));
for (float x = 0.0; x < mosaic; x++){
for (float y = 0.0; y < mosaic; y++){
color += texture2D(texture, vUv - (offset + vec2(x, y)) / resolution);
}
}
gl_FragColor = color / pow(mosaic, 2.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment