mirror of
https://github.com/italicsjenga/vello.git
synced 2025-01-10 20:51:29 +11:00
Merge pull request #108 from linebender/path_hang2
Retain subdivision results
This commit is contained in:
commit
3af033f71f
|
@ -30,6 +30,7 @@ layout(set = 0, binding = 1) readonly buffer ConfigBuf {
|
||||||
#define Q_ACCURACY (ACCURACY * 0.1)
|
#define Q_ACCURACY (ACCURACY * 0.1)
|
||||||
#define REM_ACCURACY (ACCURACY - Q_ACCURACY)
|
#define REM_ACCURACY (ACCURACY - Q_ACCURACY)
|
||||||
#define MAX_HYPOT2 (432.0 * Q_ACCURACY * Q_ACCURACY)
|
#define MAX_HYPOT2 (432.0 * Q_ACCURACY * Q_ACCURACY)
|
||||||
|
#define MAX_QUADS 16
|
||||||
|
|
||||||
vec2 eval_quad(vec2 p0, vec2 p1, vec2 p2, float t) {
|
vec2 eval_quad(vec2 p0, vec2 p1, vec2 p2, float t) {
|
||||||
float mt = 1.0 - t;
|
float mt = 1.0 - t;
|
||||||
|
@ -113,6 +114,8 @@ void main() {
|
||||||
float err = err_v.x * err_v.x + err_v.y * err_v.y;
|
float err = err_v.x * err_v.x + err_v.y * err_v.y;
|
||||||
// The number of quadratics.
|
// The number of quadratics.
|
||||||
uint n_quads = max(uint(ceil(pow(err * (1.0 / MAX_HYPOT2), 1.0 / 6.0))), 1);
|
uint n_quads = max(uint(ceil(pow(err * (1.0 / MAX_HYPOT2), 1.0 / 6.0))), 1);
|
||||||
|
n_quads = min(n_quads, MAX_QUADS);
|
||||||
|
SubdivResult keep_params[MAX_QUADS];
|
||||||
// Iterate over quadratics and tote up the estimated number of segments.
|
// Iterate over quadratics and tote up the estimated number of segments.
|
||||||
float val = 0.0;
|
float val = 0.0;
|
||||||
vec2 qp0 = cubic.p0;
|
vec2 qp0 = cubic.p0;
|
||||||
|
@ -123,6 +126,7 @@ void main() {
|
||||||
vec2 qp1 = eval_cubic(cubic.p0, cubic.p1, cubic.p2, cubic.p3, t - 0.5 * step);
|
vec2 qp1 = eval_cubic(cubic.p0, cubic.p1, cubic.p2, cubic.p3, t - 0.5 * step);
|
||||||
qp1 = 2.0 * qp1 - 0.5 * (qp0 + qp2);
|
qp1 = 2.0 * qp1 - 0.5 * (qp0 + qp2);
|
||||||
SubdivResult params = estimate_subdiv(qp0, qp1, qp2, sqrt(REM_ACCURACY));
|
SubdivResult params = estimate_subdiv(qp0, qp1, qp2, sqrt(REM_ACCURACY));
|
||||||
|
keep_params[i] = params;
|
||||||
val += params.val;
|
val += params.val;
|
||||||
|
|
||||||
qp0 = qp2;
|
qp0 = qp2;
|
||||||
|
@ -144,7 +148,7 @@ void main() {
|
||||||
vec2 qp2 = eval_cubic(cubic.p0, cubic.p1, cubic.p2, cubic.p3, t);
|
vec2 qp2 = eval_cubic(cubic.p0, cubic.p1, cubic.p2, cubic.p3, t);
|
||||||
vec2 qp1 = eval_cubic(cubic.p0, cubic.p1, cubic.p2, cubic.p3, t - 0.5 * step);
|
vec2 qp1 = eval_cubic(cubic.p0, cubic.p1, cubic.p2, cubic.p3, t - 0.5 * step);
|
||||||
qp1 = 2.0 * qp1 - 0.5 * (qp0 + qp2);
|
qp1 = 2.0 * qp1 - 0.5 * (qp0 + qp2);
|
||||||
SubdivResult params = estimate_subdiv(qp0, qp1, qp2, sqrt(REM_ACCURACY));
|
SubdivResult params = keep_params[i];
|
||||||
float u0 = approx_parabola_inv_integral(params.a0);
|
float u0 = approx_parabola_inv_integral(params.a0);
|
||||||
float u2 = approx_parabola_inv_integral(params.a2);
|
float u2 = approx_parabola_inv_integral(params.a2);
|
||||||
float uscale = 1.0 / (u2 - u0);
|
float uscale = 1.0 / (u2 - u0);
|
||||||
|
|
Binary file not shown.
Loading…
Reference in a new issue