D言語くん距離関数

#距離関数とD言語くん
くびれた腰。細い足。そしてつぶらな瞳。
D言語くんの奇跡のキャラデザを見ていて思いました。
**「これ、数式で書けるんじゃね？」**
というわけで書きました。
以下、任意の点からD言語くんまでの距離を返す関数です。

```glsl:dman.frag
float length8(vec2 p) {
    return pow( p.x*p.x*p.x*p.x*p.x*p.x*p.x*p.x
               + p.y*p.y*p.y*p.y*p.y*p.y*p.y*p.y,
               1.0 / 8.);
}
vec3 rotate(vec3 p, float t) {
    return vec3(
        p.x * cos(t) - p.y * sin(t),
        p.x * sin(t) + p.y * cos(t),
        p.z);
}
//D's right side
float dist1(vec3 p) {
    vec2 t = vec2(60.,1.9);
    vec3 p2 = p + vec3(61.4,0,0);
    vec2 q = vec2(length(p2.xy)-t.x,p2.z);
    float d1 = length8(q)-t.y;
    float s = atan(p2.y / p2.x);
    if (abs(s) > 0.41 || p2.x < 0.) d1 = 1145141919810.;
    return d1;
}
//D's left side
float dist2(vec3 p) {
    vec2 t = vec2(23.,1.9);
    vec3 p3 = p + vec3(5,0,0);
    p3.x *= 1.5;
    vec2 q = vec2(length(p3.xy)-t.x,p3.z);
    float d2 = length8(q)-t.y;
    if (p3.x < 0.) d2 = 1145141919810.;
    return d2;
}
//Right leg base
float dist3(vec3 p) {
    p += vec3(4,28,0);
    p = rotate(p, .4);
    vec2 h = vec2(.6, 4.);
    vec2 d = abs(vec2(length(p.xz),p.y)) - h;
    return min(max(d.x,d.y),0.0) + length(max(d,0.0));
}
//Right leg tip
float dist4(vec3 p) {
    p += vec3(4,34,0);
    p = rotate(p, -.4);
    vec2 h = vec2(.6, 3.);
    vec2 d = abs(vec2(length(p.xz),p.y)) - h;
    return min(max(d.x,d.y),0.0) + length(max(d,0.0));
}
//Left leg base
float dist5(vec3 p) {
    p += vec3(-7,26,0);
    p = rotate(p, -.4);
    vec2 h = vec2(.6, 6.);
    vec2 d = abs(vec2(length(p.xz),p.y)) - h;
    return min(max(d.x,d.y),0.0) + length(max(d,0.0));
}
//Left leg tip
float dist6(vec3 p) {
    p += vec3(-8,33.5,0);
    p = rotate(p, .4);
    vec2 h = vec2(.6, 3.);
    vec2 d = abs(vec2(length(p.xz),p.y)) - h;
    return min(max(d.x,d.y),0.0) + length(max(d,0.0));
}
//Right arm base
float dist7(vec3 p) {
    p += vec3(7,-15,0);
    p = rotate(p, -.6);
    vec2 h = vec2(.6, 7.);
    vec2 d = abs(vec2(length(p.xz),p.y)) - h;
    return min(max(d.x,d.y),0.0) + length(max(d,0.0));
}
//Right arm tip
float dist8(vec3 p) {
    p += vec3(7,-29,0);
    p = rotate(p, .4);
    vec2 h = vec2(.6, 9.);
    vec2 d = abs(vec2(length(p.xz),p.y)) - h;
    return min(max(d.x,d.y),0.0) + length(max(d,0.0));
}
//Left arm base
float dist9(vec3 p) {
    p += vec3(-10,-20,0);
    p = rotate(p, .2);
    vec2 h = vec2(.6, 8.);
    vec2 d = abs(vec2(length(p.xz),p.y)) - h;
    return min(max(d.x,d.y),0.0) + length(max(d,0.0));
}
//Left arm tip
float dist10(vec3 p) {
    p += vec3(-8,-32,0);
    p = rotate(p, -.7);
    vec2 h = vec2(.6, 6.);
    vec2 d = abs(vec2(length(p.xz),p.y)) - h;
    return min(max(d.x,d.y),0.0) + length(max(d,0.0));
}
//Left hand
float dist11(vec3 p) {
    p += vec3(-4.,-38,0);
    p.y *= .4;
   	return length(p) - 1.5;
}
//Right hand
float dist12(vec3 p) {
    p += vec3(4.,-38,0);
    p.y *= .4;
   	return length(p) - 1.8;
}
//Right foot
float dist13(vec3 p) {
    p += vec3(5.,38,0);
    p.x *= .8;
   	return length(p) - 2.2;
}
//Left foot
float dist14(vec3 p) {
    p += vec3(-8.,38,0);
    p.x *= .8;
   	return length(p) - 2.2;
}
//Right black eye
float dist15(vec3 p) {
    p += vec3(-6.5,-8,-6.);
    p = rotate(p, .1);
    p.y *= .45;
   	return length(p) - 1.5;
}
//Right white eye
float dist16(vec3 p) {
    p += vec3(-6.,-10,-4);
    p.x *= 1.3;
    p.y *= .5;
   	return length(p) - 2.7;
}
//Left black eye
float dist17(vec3 p) {
   p += vec3(-.6,-12,-6.);
    p = rotate(p, .1);
    p.y *= .45;
   	return length(p) - 1.5;
}
//Left white eye
float dist18(vec3 p) {
    p += vec3(0,-14,-4);
    p.x *= 1.3;
    p.y *= .6;
   	return length(p) - 2.8;
}
vec2 dist(vec3 p) {
    p.xz = mod(p.xz, vec2(100, 100)) - vec2(50,50);
    p.y *= 2.;
    p.y -= 40.;
    vec2 result = vec2(114514191981000., -1);
    float d = dist1(p);
    if (d < result.x) {
        result.x = d;
        result.y = 0.;
    }
    d = dist2(p);
    if (d < result.x) {
        result.x = d;
        result.y = 1.;
    }
    d = dist3(p);
    if (d < result.x) {
        result.x = d;
        result.y = 2.;
    }
     d = dist4(p);
    if (d < result.x) {
        result.x = d;
        result.y = 2.;
    }
     d = dist5(p);
    if (d < result.x) {
        result.x = d;
        result.y = 2.;
    }
     d = dist6(p);
    if (d < result.x) {
        result.x = d;
        result.y = 2.;
    } 
    d = dist7(p);
    if (d < result.x) {
        result.x = d;
        result.y = 2.;
    }
    d = dist8(p);
    if (d < result.x) {
        result.x = d;
        result.y = 2.;
    }
     d = dist9(p);
    if (d < result.x) {
        result.x = d;
        result.y = 2.;
    } 
    d = dist10(p);
    if (d < result.x) {
        result.x = d;
        result.y = 2.;
    }
     d = dist11(p);
    if (d < result.x) {
        result.x = d;
        result.y = 3.;
    }
     d = dist12(p);
    if (d < result.x) {
        result.x = d;
        result.y = 3.;
    }
     d = dist13(p);
    if (d < result.x) {
        result.x = d;
        result.y = 3.;
    }
     d = dist14(p);
    if (d < result.x) {
        result.x = d;
        result.y = 3.;
    }
     d = dist15(p);
    if (d < result.x) {
        result.x = d;
        result.y = 2.;
    }
     d = dist16(p);
    if (d < result.x) {
        result.x = d;
        result.y = 3.;
    }
    d = dist17(p);
    if (d < result.x) {
        result.x = d;
        result.y = 2.;
    }
    d = dist18(p);
    if (d < result.x) {
        result.x = d;
        result.y = 3.;
    }
    return result;
}
```

これでD言語くんが描けます。
![D-man4.png](https://qiita-image-store.s3.amazonaws.com/0/105364/28079cbd-388c-d830-3404-a77c44416e8b.png)
動くやつは[こちら](https://www.shadertoy.com/view/XscGWN)。