Skip to content

Instantly share code, notes, and snippets.

@Doom2fan
Last active June 26, 2021 17:50
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 Doom2fan/7925b6149ded65ce6c9c319d2dc0cc8f to your computer and use it in GitHub Desktop.
Save Doom2fan/7925b6149ded65ce6c9c319d2dc0cc8f to your computer and use it in GitHub Desktop.
vec2 texCoord = /* (e.g. vTexCoord.st) */;
vec2 texSize = /* (e.g. textureSize (tex, 0)) */;
float scalingFactor = /* The virtual res the user wants */
vec2 pixelCoords = texCoord * texSize;
vec2 subPixel = (fract (pixelCoords) - .5) * 2;
subPixel = pow (abs (subPixel), vec2 (scalingFactor)) * sign (subPixel) / 2 + .5;
texCoord = (floor (pixelCoords) + subPixel) / texSize;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment