27 {
28 static_assert(skgpu::wangs_formula::length_term<3>(1) == 0.75);
29 static_assert(skgpu::wangs_formula::length_term_p2<3>(1) == 0.5625);
30
31 return
32
33"float wangs_formula_max_fdiff_p2(float2 p0, float2 p1, float2 p2, float2 p3,"
34 "float2x2 matrix) {"
35 "float2 d0 = matrix * (fma(float2(-2), p1, p2) + p0);"
36 "float2 d1 = matrix * (fma(float2(-2), p2, p3) + p1);"
37 "return max(dot(d0,d0), dot(d1,d1));"
38"}"
39"float wangs_formula_cubic(float _precision_, float2 p0, float2 p1, float2 p2, float2 p3,"
40 "float2x2 matrix) {"
41 "float m = wangs_formula_max_fdiff_p2(p0, p1, p2, p3, matrix);"
42 "return max(ceil(sqrt(0.75 * _precision_ * sqrt(m))), 1.0);"
43"}"
44"float wangs_formula_cubic_log2(float _precision_, float2 p0, float2 p1, float2 p2, float2 p3,"
45 "float2x2 matrix) {"
46 "float m = wangs_formula_max_fdiff_p2(p0, p1, p2, p3, matrix);"
47 "return ceil(log2(max(0.5625 * _precision_ * _precision_ * m, 1.0)) * .25);"
48"}"
49"float wangs_formula_conic_p2(float _precision_, float2 p0, float2 p1, float2 p2, float w) {"
50
51 "float2 C = (min(min(p0, p1), p2) + max(max(p0, p1), p2)) * 0.5;"
52 "p0 -= C;"
53 "p1 -= C;"
54 "p2 -= C;"
55
56
57 "float m = sqrt(max(max(dot(p0,p0), dot(p1,p1)), dot(p2,p2)));"
58
59
60 "float2 dp = fma(float2(-2.0 * w), p1, p0) + p2;"
61 "float dw = abs(fma(-2.0, w, 2.0));"
62
63
64
65 "float rp_minus_1 = max(0.0, fma(m, _precision_, -1.0));"
66 "float numer = length(dp) * _precision_ + rp_minus_1 * dw;"
67 "float denom = 4 * min(w, 1.0);"
68
69 "return numer/denom;"
70"}"
71"float wangs_formula_conic(float _precision_, float2 p0, float2 p1, float2 p2, float w) {"
72 "float n2 = wangs_formula_conic_p2(_precision_, p0, p1, p2, w);"
73 "return max(ceil(sqrt(n2)), 1.0);"
74"}"
75"float wangs_formula_conic_log2(float _precision_, float2 p0, float2 p1, float2 p2, float w) {"
76 "float n2 = wangs_formula_conic_p2(_precision_, p0, p1, p2, w);"
77 "return ceil(log2(max(n2, 1.0)) * .5);"
78"}"
79;
80}