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

Make tangents at subpath end watertight #695

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions vello_shaders/shader/flatten.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,10 @@ fn read_neighboring_segment(ix: u32) -> NeighboringSegment {
let is_closed = (tag.tag_byte & PATH_TAG_SEG_TYPE) == PATH_TAG_LINETO;
let is_stroke_cap_marker = (tag.tag_byte & PATH_TAG_SUBPATH_END) != 0u;
let do_join = !is_stroke_cap_marker || is_closed;
let tangent = cubic_start_tangent(pts.p0, pts.p1, pts.p2, pts.p3);
var tangent = pts.p3 - pts.p0;
if !is_stroke_cap_marker {
tangent = cubic_start_tangent(pts.p0, pts.p1, pts.p2, pts.p3);
}
return NeighboringSegment(do_join, tangent);
}

Expand Down Expand Up @@ -844,7 +847,7 @@ fn main(
if is_stroke_cap_marker {
if is_open {
// Draw start cap
let tangent = cubic_start_tangent(pts.p0, pts.p1, pts.p2, pts.p3);
let tangent = pts.p3 - pts.p0;
let offset_tangent = offset * normalize(tangent);
let n = offset_tangent.yx * vec2f(-1., 1.);
draw_cap(path_ix, (style_flags & STYLE_FLAGS_START_CAP_MASK) >> 2u,
Expand Down
8 changes: 6 additions & 2 deletions vello_shaders/src/cpu/flatten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,11 @@ fn read_neighboring_segment(
let is_closed = (tag.tag_byte & PATH_TAG_SEG_TYPE) == PATH_TAG_LINETO;
let is_stroke_cap_marker = (tag.tag_byte & PathTag::SUBPATH_END_BIT) != 0;
let do_join = !is_stroke_cap_marker || is_closed;
let tangent = cubic_start_tangent(pts.p0, pts.p1, pts.p2, pts.p3);
let tangent = if is_stroke_cap_marker {
pts.p3 - pts.p0
} else {
cubic_start_tangent(pts.p0, pts.p1, pts.p2, pts.p3)
};
NeighboringSegment { do_join, tangent }
}

Expand Down Expand Up @@ -704,7 +708,7 @@ fn flatten_main(
if is_stroke_cap_marker {
if is_open {
// Draw start cap
let tangent = cubic_start_tangent(pts.p0, pts.p1, pts.p2, pts.p3);
let tangent = pts.p3 - pts.p0;
let offset_tangent = offset * tangent.normalize();
let n = Vec2::new(-offset_tangent.y, offset_tangent.x);
draw_cap(
Expand Down