Created
September 27, 2019 23:19
-
-
Save ar-android/e3c71851a69849f443eb6f4effb4cdc0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
float square(float val) { | |
return val * val; | |
} | |
float distanceSquared(vec2 p1, vec2 p2) { | |
vec2 vector = p2 - p1; | |
return vector.x * vector.x + vector.y * vector.y; | |
} | |
float calcRoundedCorners() { | |
if (radius <= 0.0) { | |
return 1.0; | |
} | |
vec2 pixelPos = pass_textureCoords * vec2(uiWidth, uiHeight); | |
vec2 minCorner = vec2(radius, radius); | |
vec2 maxCorner = vec2(uiWidth - radius, uiHeight - radius); | |
vec2 cornerPoint = clamp(pixelPos, minCorner, maxCorner); | |
float lowerBound = square(radius - cornerSmooth); | |
float upperBound = square(radius + cornerSmooth); | |
return smoothstep(upperBound, lowerBound, distanceSquared(pixelPos, cornerPoint)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment