Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sweep gradients #435

Merged
merged 6 commits into from
Mar 6, 2024
Merged

Sweep gradients #435

merged 6 commits into from
Mar 6, 2024

Conversation

dfrg
Copy link
Collaborator

@dfrg dfrg commented Feb 13, 2024

Implements support for rendering sweep gradients. Just had an itch to get this done, mostly to support COLRv1 fonts.

Based on Skia's SkSweepGradient shader.

Here's a comparison of a sweep gradient with the three extend modes. Skia on top and Vello on bottom.
skia-vello-sweep

Implements support for rendering sweep gradients. Based on Skia's SkSweepGradient shader.
@dfrg
Copy link
Collaborator Author

dfrg commented Feb 13, 2024

For reviewers:

0x254 = 0b001001_0_101_00
sizeof(DrawSweepGradient) = 20
uses 9 words of draw info

@DJMcNab DJMcNab self-requested a review February 29, 2024 16:38
Copy link
Member

@DJMcNab DJMcNab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this also be added to the fine cpu shader (on a best-effort basis, given we can't really test it)? We probably should have a coherent policy on that (see also #386)

Otherwise, I've checked code quality. Haven't checked the maths, but it works in the test scenes you've created, on both CPU and GPU

let is_radial = y & 1 != 0;
for (y, kind) in [Kind::Linear, Kind::Radial, Kind::Sweep]
.into_iter()
.enumerate()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These now go off-screen in the default resolution. I think the resolution field of params can be set to counteract this (see #453)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't aware this existed! Added to this scene and made sure it scales properly.

Comment on lines 118 to 129
let z = xform.0;
let inv_det = (z[0] * z[3] - z[1] * z[2]).recip();
let inv_mat = [
z[3] * inv_det,
-z[1] * inv_det,
-z[2] * inv_det,
z[0] * inv_det,
];
let inv_tr = [
-(inv_mat[0] * z[4] + inv_mat[2] * z[5]),
-(inv_mat[1] * z[4] + inv_mat[3] * z[5]),
];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth adding the inverse method to Transform directly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely. I considered this but side-stepped it when adding the code.

Done.

dfrg added 2 commits March 6, 2024 12:46
- use params.resolution to fit test scene to current viewport
- move repeated inverse calculation to Transform::inverse() method

Also add CPU implementation of radial gradients in draw_leaf.rs
@dfrg
Copy link
Collaborator Author

dfrg commented Mar 6, 2024

Should this also be added to the fine cpu shader (on a best-effort basis, given we can't really test it)? We probably should have a coherent policy on that (see also #386)

Since we're still missing texture bindings in the CPU pipeline, we can't do much with this and my preference is to defer until that is more fully fleshed out.

I did however go ahead and sneak the CPU-side radial gradient fixes into this PR.

@dfrg dfrg added this pull request to the merge queue Mar 6, 2024
Merged via the queue into main with commit b3f429a Mar 6, 2024
9 checks passed
@xStrom xStrom deleted the sweepgrad branch March 6, 2024 20:03
@raphlinus raphlinus mentioned this pull request Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants