Skip to content

Instantly share code, notes, and snippets.

@michlimlim
Created November 18, 2021 16:50
Show Gist options
  • Select an option

  • Save michlimlim/75f79f8eb3bc7e76085f4cba5d8d20af to your computer and use it in GitHub Desktop.

Select an option

Save michlimlim/75f79f8eb3bc7e76085f4cba5d8d20af to your computer and use it in GitHub Desktop.
distance field from rectangle
float distance_from_rect(vector_float2 pixel_pos, vector_float2 rect_center, vector_float2 rect_corner, float corner_radius) {
vector_float2 p = pixel_pos - rect_center;
vector_float2 q = abs(p) - (rect_corner - corner_radius);
return length(max(q, 0.0)) + min(max(q.x, q.y), 0.0) - corner_radius;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment