Last active
October 18, 2019 13:33
-
-
Save mattdesl/cbbed09cde4700f04e683cd2d0bd36b3 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
float2 background(float2 uv, float2 resolution, float2 texResolution) { | |
float tAspect = texResolution.x / texResolution.y; | |
float pAspect = resolution.x / resolution.y; | |
float pwidth = resolution.x; | |
float pheight = resolution.y; | |
float width = 0.0; | |
float height = 0.0; | |
if (tAspect > pAspect) { | |
height = pheight; | |
width = height * tAspect; | |
} | |
else { | |
width = pwidth; | |
height = width / tAspect; | |
} | |
float x = (pwidth - width) / 2.0; | |
float y = (pheight - height) / 2.0; | |
float2 nUv = uv; | |
nUv -= float2(x, y) / resolution; | |
nUv /= float2(width, height) / resolution; | |
return nUv; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment