nical / lyon

2D graphics rendering on the GPU in rust using path tessellation.
Other
2.3k stars 141 forks source link

Stroke Tessellation: `advancement` does not give accurate UV coordinates #915

Open timmb opened 1 month ago

timmb commented 1 month ago

I'm trying to get UV coordinates on a tessellated stroke by using the path advancement.

It nearly works, but where there are straight line segments joining other segments with tight angles, the tesselation creates large triangles. The inside and outside parts of the line are different lengths and the UVs end up drifting as we go along the path.

Path showing advancement

This image shows 10 cycles of the normalized advancement along the path.

Wireframe of path This wireframe shows how the tessellation contributes to this.

For correct UV, I'd want the UV values to be equal along a line normal to the path. This happens in the curved segments because they're tessellated with a lot more triangles.

Some possible ways to resolve this issue would be:

nical commented 2 weeks ago

Hi, yeah that's a bit tricky unfortunately (depending on what you expect the correct behavior to be). Increasing the tessellation of straight lines in a way that distributes the stretching introduced by a sharp turn would look better, but it would still stretch the uvs (it wouldn't look quite right if you draw, say, a road texture along it). and it would not address the same problem happening with two curves meeting at a sharp turn. One might argue that the best behavior should be to only introduce distortion near the join.

In any case I agree that the current behavior is not very good for shapes that aren't smooth.

Unfortunately I am very short on spare time to dedicate to improving the stroke tessellator at the moment. If you or someone else feel adventurous, I'd be happy to review contributions.