Skip to content

Instantly share code, notes, and snippets.

@CIOSAI
Created December 9, 2024 19:17
Show Gist options
  • Save CIOSAI/3135f5b97e451d80a823beb08fae7067 to your computer and use it in GitHub Desktop.
Save CIOSAI/3135f5b97e451d80a823beb08fae7067 to your computer and use it in GitHub Desktop.
simple 2d sdf of a heart
float box(vec2 p){
vec2 q = abs(p);
return max(q.x,q.y);
}
// /.-\
// | |
// \ / <- center is here, it's a bit top-heavy
// \/
float heart(vec2 p){
vec2 q = abs(p);
return mix(
box(vec2(p.x-p.y,p.x+p.y))/sqrt(2.),
length(q-(q.x*q.x+q.y*q.y)/(2.*(q.x+q.y))),
step(0.,p.y));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment