Skip to content

Instantly share code, notes, and snippets.

@Chlumsky
Created July 4, 2017 07:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Chlumsky/693a5d9cfe324d8d113a493385c52a4b to your computer and use it in GitHub Desktop.
Save Chlumsky/693a5d9cfe324d8d113a493385c52a4b to your computer and use it in GitHub Desktop.
glsl {
// Signed distance from half-plane defined by oriented line segment (a, b)
float halfPlaneDistance(vec2 pos, vec2 a, vec2 b) {
return dot(normalize(vec2(b.y-a.y, a.x-b.x)), a-pos);
}
// Anti-aliased half-plane defined by oriented line segment (a, b)
float halfPlaneSmooth(vec2 pos, vec2 a, vec2 b, float border) {
return clamp(halfPlaneDistance(pos, a, b)/border+0.5, 0.0, 1.0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment