Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. vec2 backgroundUV (vec2 uv, vec2 resolution, vec2 texResolution) {
  2. float tAspect = texResolution.x / texResolution.y;
  3. float pAspect = resolution.x / resolution.y;
  4. float pwidth = resolution.x;
  5. float pheight = resolution.y;
  6.  
  7. float width = 0.0;
  8. float height = 0.0;
  9. if (tAspect > pAspect) {
  10. height = pheight;
  11. width = height * tAspect;
  12. } else {
  13. width = pwidth;
  14. height = width / tAspect;
  15. }
  16. float x = (pwidth - width) / 2.0;
  17. float y = (pheight - height) / 2.0;
  18. vec2 nUv = uv;
  19. nUv -= vec2(x, y) / resolution;
  20. nUv /= vec2(width, height) / resolution;
  21. return nUv;
  22. }
  23.  
  24. #pragma glslify: export(backgroundUV)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement