Last active
March 8, 2023 07:32
-
-
Save benjamingorman/840f42cca525ab2cd6bf to your computer and use it in GitHub Desktop.
Shader - Circle and Rectangle functions
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
// returns 1.0 if inside circle | |
float disk(vec2 r, vec2 center, float radius) { | |
return 1.0 - smoothstep( radius-0.005, radius+0.005, length(r-center)); | |
} | |
// returns 1.0 if inside the disk | |
float rectangle(vec2 r, vec2 bottomLeft, vec2 topRight) { | |
float ret; | |
float d = 0.005; | |
ret = smoothstep(bottomLeft.x-d, bottomLeft.x+d, r.x); | |
ret *= smoothstep(bottomLeft.y-d, bottomLeft.y+d, r.y); | |
ret *= 1.0 - smoothstep(topRight.y-d, topRight.y+d, r.y); | |
ret *= 1.0 - smoothstep(topRight.x-d, topRight.x+d, r.x); | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment