Added improved non-clay text handling along with consistent origin and rotation API

This commit is contained in:
Zachary Levy
2026-04-19 18:28:42 -07:00
parent 30b72128b2
commit 7a21d6f253
12 changed files with 1157 additions and 388 deletions

View File

@@ -24,32 +24,41 @@ struct main0_in
float4 f_params [[user(locn2)]];
float4 f_params2 [[user(locn3)]];
uint f_kind_flags [[user(locn4)]];
float f_rotation [[user(locn5), flat]];
};
static inline __attribute__((always_inline))
float2 apply_rotation(thread const float2& p, thread const float& angle)
{
float cr = cos(-angle);
float sr = sin(-angle);
return float2x2(float2(cr, sr), float2(-sr, cr)) * p;
}
static inline __attribute__((always_inline))
float sdRoundedBox(thread const float2& p, thread const float2& b, thread float4& r)
{
float2 _56;
float2 _61;
if (p.x > 0.0)
{
_56 = r.xy;
_61 = r.xy;
}
else
{
_56 = r.zw;
_61 = r.zw;
}
r.x = _56.x;
r.y = _56.y;
float _73;
r.x = _61.x;
r.y = _61.y;
float _78;
if (p.y > 0.0)
{
_73 = r.x;
_78 = r.x;
}
else
{
_73 = r.y;
_78 = r.y;
}
r.x = _73;
r.x = _78;
float2 q = (abs(p) - b) + float2(r.x);
return (fast::min(fast::max(q.x, q.y), 0.0) + length(fast::max(q, float2(0.0)))) - r.x;
}
@@ -142,16 +151,23 @@ fragment main0_out main0(main0_in in [[stage_in]], texture2d<float> tex [[textur
float4 r = float4(in.f_params.zw, in.f_params2.xy);
soft = fast::max(in.f_params2.z, 1.0);
float stroke_px = in.f_params2.w;
float2 param = in.f_local_or_uv;
float2 param_1 = b;
float4 param_2 = r;
float _453 = sdRoundedBox(param, param_1, param_2);
d = _453;
float2 p_local = in.f_local_or_uv;
if (in.f_rotation != 0.0)
{
float2 param = p_local;
float param_1 = in.f_rotation;
p_local = apply_rotation(param, param_1);
}
float2 param_2 = p_local;
float2 param_3 = b;
float4 param_4 = r;
float _491 = sdRoundedBox(param_2, param_3, param_4);
d = _491;
if ((flags & 1u) != 0u)
{
float param_3 = d;
float param_4 = stroke_px;
d = sdf_stroke(param_3, param_4);
float param_5 = d;
float param_6 = stroke_px;
d = sdf_stroke(param_5, param_6);
}
}
else
@@ -161,14 +177,14 @@ fragment main0_out main0(main0_in in [[stage_in]], texture2d<float> tex [[textur
float radius = in.f_params.x;
soft = fast::max(in.f_params.y, 1.0);
float stroke_px_1 = in.f_params.z;
float2 param_5 = in.f_local_or_uv;
float param_6 = radius;
d = sdCircle(param_5, param_6);
float2 param_7 = in.f_local_or_uv;
float param_8 = radius;
d = sdCircle(param_7, param_8);
if ((flags & 1u) != 0u)
{
float param_7 = d;
float param_8 = stroke_px_1;
d = sdf_stroke(param_7, param_8);
float param_9 = d;
float param_10 = stroke_px_1;
d = sdf_stroke(param_9, param_10);
}
}
else
@@ -178,15 +194,22 @@ fragment main0_out main0(main0_in in [[stage_in]], texture2d<float> tex [[textur
float2 ab = in.f_params.xy;
soft = fast::max(in.f_params.z, 1.0);
float stroke_px_2 = in.f_params.w;
float2 param_9 = in.f_local_or_uv;
float2 param_10 = ab;
float _511 = sdEllipse(param_9, param_10);
d = _511;
float2 p_local_1 = in.f_local_or_uv;
if (in.f_rotation != 0.0)
{
float2 param_11 = p_local_1;
float param_12 = in.f_rotation;
p_local_1 = apply_rotation(param_11, param_12);
}
float2 param_13 = p_local_1;
float2 param_14 = ab;
float _560 = sdEllipse(param_13, param_14);
d = _560;
if ((flags & 1u) != 0u)
{
float param_11 = d;
float param_12 = stroke_px_2;
d = sdf_stroke(param_11, param_12);
float param_15 = d;
float param_16 = stroke_px_2;
d = sdf_stroke(param_15, param_16);
}
}
else
@@ -197,10 +220,10 @@ fragment main0_out main0(main0_in in [[stage_in]], texture2d<float> tex [[textur
float2 b_1 = in.f_params.zw;
float width = in.f_params2.x;
soft = fast::max(in.f_params2.y, 1.0);
float2 param_13 = in.f_local_or_uv;
float2 param_14 = a;
float2 param_15 = b_1;
d = sdSegment(param_13, param_14, param_15) - (width * 0.5);
float2 param_17 = in.f_local_or_uv;
float2 param_18 = a;
float2 param_19 = b_1;
d = sdSegment(param_17, param_18, param_19) - (width * 0.5);
}
else
{
@@ -218,26 +241,18 @@ fragment main0_out main0(main0_in in [[stage_in]], texture2d<float> tex [[textur
{
angle += 6.283185482025146484375;
}
float ang_start = start_rad;
float ang_end = end_rad;
if (ang_start < 0.0)
{
ang_start += 6.283185482025146484375;
}
if (ang_end < 0.0)
{
ang_end += 6.283185482025146484375;
}
float _615;
float ang_start = mod(start_rad, 6.283185482025146484375);
float ang_end = mod(end_rad, 6.283185482025146484375);
float _654;
if (ang_end > ang_start)
{
_615 = float((angle >= ang_start) && (angle <= ang_end));
_654 = float((angle >= ang_start) && (angle <= ang_end));
}
else
{
_615 = float((angle >= ang_start) || (angle <= ang_end));
_654 = float((angle >= ang_start) || (angle <= ang_end));
}
float in_arc = _615;
float in_arc = _654;
if (abs(ang_end - ang_start) >= 6.282185077667236328125)
{
in_arc = 1.0;
@@ -262,9 +277,9 @@ fragment main0_out main0(main0_in in [[stage_in]], texture2d<float> tex [[textur
d = (length(p) * cos(bn)) - radius_1;
if ((flags & 1u) != 0u)
{
float param_16 = d;
float param_17 = stroke_px_3;
d = sdf_stroke(param_16, param_17);
float param_20 = d;
float param_21 = stroke_px_3;
d = sdf_stroke(param_20, param_21);
}
}
}
@@ -272,9 +287,9 @@ fragment main0_out main0(main0_in in [[stage_in]], texture2d<float> tex [[textur
}
}
}
float param_18 = d;
float param_19 = soft;
float alpha = sdf_alpha(param_18, param_19);
float param_22 = d;
float param_23 = soft;
float alpha = sdf_alpha(param_22, param_23);
out.out_color = float4(in.f_color.xyz, in.f_color.w * alpha);
return out;
}