Next gen renderer
abey79 opened this issue · comments
Lots of thinking going on on what should be the next gen renderer for vpype/vsketch.
Main issue: geometry shaders are basically bad, which makes the vpype 1.x approach problematic. For example, WGSL don't support them.
I current see the following approaches.
1) CPU-based non-overlapping triangulation
This basically re-implements vpype 1's approach, i.e. generating non-overlapping triangles covering the fat line and using SDF for round ending/joins + AA rendering.
I've made an initial implementation in 8274167 and following.
Issues:
- I'm reusing vertices and using an index buffer, but that's likely a dead-end as tex coord cannot be reused (unless I'm missing something).
- The triangle count is hard to predict for a given path, because of the bonus triangles in 90+° joints. This makes pre-allocation and parallel processing more difficult.
- The line width must be adjusted to account for AA, and this is scale-dependent. This means that the triangulation might have to be redone during zoom-in/zoom-out.
1b) GPU compute of the same
No idea how good an idea this would be.
2) Instanced drawing and SDF-based overlap control
This needs to be prototyped. The idea is to have a simple 2-triangle primitive instanced for all segment point pairs, and address over-draw at the SDF level. This probably requires precomputing the miter vectors, to be used as half-plan separator for the SDF.
Advantages:
- Instance buffer has predictable size (basically same as segment count).
- AA scale-depend thickness adjustment would happen on GPU side, so no CPU computation nor memory transfer.
- All points (but extremities) would be duplicated in instance buffer (that that must happen anyways for (1) due to tex coord)
- Instance buffer smaller than corresponding triangle buffer.
vsvg-viewer
now has GPU-based implementation for (2) working pretty well 🎉