Last active
March 16, 2024 19:38
-
-
Save MateSteinforth/93d3447f889b253e06ad6a52791efa22 to your computer and use it in GitHub Desktop.
Rounded Box Outline SDF in SparkSL
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
| //============================================================================== | |
| // Rounded Box Outline SDF | |
| //============================================================================== | |
| float roundedBoxSDF(vec2 CenterPosition, vec2 Size, float Radius) | |
| { | |
| return length(max(abs(CenterPosition)-Size+Radius,0.0))-Radius; | |
| } | |
| float roundBoxOutline(vec2 size, float thickness, float radius) | |
| { | |
| vec2 uv = fragment(std::getVertexTexCoord()); | |
| float edgeSoftness = 0.002; | |
| float distance = roundedBoxSDF(uv - vec2(0.5), size/2.0, radius); | |
| float smoothedAlpha = 1.0 - smoothstep(-edgeSoftness, edgeSoftness, abs(distance) - thickness); | |
| return smoothedAlpha; | |
| } | |
| vec4 main(vec2 size, float radius) { | |
| return vec4(roundBoxOutline(size, 0.005, radius), 0., 0., 1.); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment