Skip to content

Instantly share code, notes, and snippets.

@MarcoCiaramella
Last active April 18, 2020 19:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarcoCiaramella/6a6f63be65918e9c52561ddd248f6a0d to your computer and use it in GitHub Desktop.
Save MarcoCiaramella/6a6f63be65918e9c52561ddd248f6a0d to your computer and use it in GitHub Desktop.
A fragment shader for glsl v1.0 that create a pixellation effect.
#version 100
precision mediump float;
uniform sampler2D u_texId;
// render target width
uniform float u_rt_w;
// render target height
uniform float u_rt_h;
// width of a low resolution pixel
uniform float u_pixel_w;
// height of a low resolution pixel
uniform float u_pixel_h;
varying vec2 vTexCoords;
void main(){
float dx = u_pixel_w*(1.0/u_rt_w);
float dy = u_pixel_h*(1.0/u_rt_h);
vec2 coord = vec2(dx*floor(vTexCoords.x/dx), dy*floor(vTexCoords.y/dy));
vec3 tc = texture2D(u_texId, coord).rgb;
gl_FragColor = vec4(tc, 1.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment