Skip to content

Instantly share code, notes, and snippets.

@BigZaphod
Last active June 6, 2016 14:25
Show Gist options
  • Save BigZaphod/e695d101c5f4499481b2b3c16d19ca23 to your computer and use it in GitHub Desktop.
Save BigZaphod/e695d101c5f4499481b2b3c16d19ca23 to your computer and use it in GitHub Desktop.
// translates a normalized texture coordinate into a normalized texture coordinate that has been "snapped" to the center of a pixel
vec2 nearest(vec2 uv, vec2 size) {
vec2 pixel = uv * size;
vec2 snapped = floor(pixel - 0.5) + 0.5;
return (snapped + step(0.5, pixel - snapped)) / size;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment