Skip to content

Instantly share code, notes, and snippets.

@slembcke
Last active December 27, 2020 21:19
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save slembcke/23e1d96d7e3c739caf12 to your computer and use it in GitHub Desktop.
Save slembcke/23e1d96d7e3c739caf12 to your computer and use it in GitHub Desktop.
Anti-aliased Nearest Neighbor Filtering.
uniform sampler2D texture;
varying vec2 uv;
void main(){
vec2 size = textureSize(texture);
vec2 puv = uv*size;
vec2 hfw = 0.5*fwidth(puv);
vec2 fl = floor(puv - 0.5) + 0.5;
vec2 nnn = (fl + smoothstep(0.5 - hfw, 0.5 + hfw, puv - fl))/size;
gl_FragColor = texture2D(texture, nnn);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment