Last active
July 5, 2020 09:56
-
-
Save doxas/32004dedf1d7a650a4588ba75af0ded5 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
/** | |
* @param {vec2} coord - base texture coord | |
* @param {vec2} view - resolution of viewport | |
* @param {vec2} resource - resolution of resource | |
* @return {vec2} like a `background-size: cover` on css | |
*/ | |
vec2 cover(vec2 coord, vec2 view, vec2 resource){ | |
vec2 ratio = vec2( | |
min((view.x / view.y) / (resource.x / resource.y), 1.0), | |
min((view.y / view.x) / (resource.y / resource.x), 1.0) | |
); | |
return vec2( | |
coord.x * ratio.x + (1.0 - ratio.x) * 0.5, | |
coord.y * ratio.y + (1.0 - ratio.y) * 0.5 | |
); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment