Skip to content

Instantly share code, notes, and snippets.

@romainavalle
Last active January 17, 2023 14:27
Show Gist options
  • Save romainavalle/0b155e34f260b24f2b7dfa43310878ca to your computer and use it in GitHub Desktop.
Save romainavalle/0b155e34f260b24f2b7dfa43310878ca to your computer and use it in GitHub Desktop.
texture resize glsl
float scale(float _val, float _scale) {
_val -= 0.5;
_val *= _scale;
_val += 0.5;
return _val;
}
vec2 coverImage(vec2 _pos) {
float rS = uRes.x / uRes.y;
float rI = uImageRes.x / uImageRes.y;
float scaleX = 1.;
float scaleY = 1.;
// scale UVS
if (rS > rI) {
scaleY = rI / rS;
} else {
scaleX = rS / rI;
}
_pos.x = scale(_pos.x, scaleX);
_pos.y = scale(_pos.y, scaleY);
return _pos;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment