Created
June 13, 2023 18:18
-
-
Save romainavalle/36c1a480b627c6b366f48d483e3a16df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://gist.github.com/raphaelameaume | |
vec2 uvCover (vec2 uv, vec2 size, vec2 resolution) { | |
vec2 coverUv = uv; | |
vec2 s = resolution; // Screen | |
vec2 i = size; // Image | |
float rs = s.x / s.y; | |
float ri = i.x / i.y; | |
vec2 new = rs < ri ? vec2(i.x * s.y / i.y, s.y) : vec2(s.x, i.y * s.x / i.x); | |
vec2 offset = (rs < ri ? vec2((new.x - s.x) / 2.0, 0.0) : vec2(0.0, (new.y - s.y) / 2.0)) / new; | |
coverUv = coverUv * s / new + offset; | |
return coverUv; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment