Today I created a nice adjustable bullet shaped blade tip for the Style Editor 3D render SDFs code using ChatGpt. Would be nice if we could get the current rounded tip updated with this one.
Here is a reference code:
// Signed distance for capped cylinder
float sdCappedCylinder(vec3 p, float h, float r) {
vec2 d = abs(vec2(length(p.xz), p.y)) - vec2(r, h);
return min(max(d.x,d.y), 0.0) + length(max(d,0.0));
}
// Bullet tip with smooth quarter-ellipse profile
float radiusProfileSmooth(float y, float h, float rBase, float a, float b) {
float t = clamp(y / h, 0.0, 1.0);
float profile = pow(1.0 - pow(t, a), b); // always convex if a,b ≥ 1
return rBase * profile;
}
float sdBulletTip(vec3 p, float h, float rBase, float a, float b) {
if (p.y < 0.0) return 1000.0;
float y = clamp(p.y, 0.0, h);
float r = radiusProfileSmooth(y, h, rBase, a, b);
float q = length(p.xz);
return q - r + max(0.0, y - h);
}
// Scene SDF combining cylinder + bullet tip on top
float map(vec3 p) {
float cylH = 0.5;
float cylR = 0.2;
float tipH = 0.5; // tip height
float d1 = sdCappedCylinder(p, cylH, cylR);
vec3 pt = p;
pt.y -= cylH;
float a = 2.5; // tip taper steepness
float b = 0.6; // roundness near tip
float d2 = sdBulletTip(pt, tipH, cylR, a, b);
return min(d1, d2);
}
Adjust these numbers to change the shape of the tip:
float tipH = 0.5; // tip height
float a = 2.5; // tip taper steepness
float b = 0.6; // roundness near tip