-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
A more accurate algorithm for approximating round line joins #8275
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mourner IS there a way to quantify the improvements from this change? Should render tests get updated, or can we show whether amount of buffer data has reduced for a synthetic case?
@asheemmamoowala render tests should stay the same I think — these changes should be mostly not noticeable by design. I measured the impact locally with a debug page. How would you like to measure this instead? |
cc @mapbox/gl-native — will need a port to native if we land this. |
The OP for this PR states that:
I think it would be enough to document the approximate/average reduction in vertices or buffer size as part of the PR, until we have an automated way to measure that. |
@asheemmamoowala still confused by what you mean by "document" — there's the following bit in the PR description:
|
D'oh! I didnt see that. Sorry for the trouble! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good but I'm wondering about the default value for degrees per vertex.
A 30px wide line results in some artifacts that are pretty visible:
Ideally we could make accuracy depend on the width of the line but I know we don't have access to that right now and getting it would be hard.
Trying to think about other ways we could reduce artifacts without increasing the number of total triangles. Would the total number of geometry vertices in a layer be something we could branch on? If there are a lot of vertices reduce the quality. If there are fewer, increase it?
Do you have a sense of how much switching to 20 or 15 degrees would impact the buffer size?
0aeafdc
to
858e45a
Compare
@ansis on my local test of streets-v11 with line layers only (less is better):
So if we want to be close to original precision for the 90 degrees case while not regressing on the buffer size, we could change the value to 20 degrees for now, and look at ways to make that adaptive in a future PR.
It might be hard to come up with a good heuristic for basing precision on number of points in a layer, since it depends on the style and data so much, but at least we can assume that if there are a lot of vertices, the lines are unlikely to have long straight segments where approximation differences would be very visible. Perhaps we could come up with a heuristic based on max distance between points in a particular line? Anyway, I think it's better to merge the PR without a heuristic and then explore this in a different PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! Thanks for the measurements. Merge with whichever value you feel is best!
The algorithm we used for approximating round joins with triangles had several issues:
These issues combined meant that we 1) generated more triangles than needed overall, 2) had inconsistent quality of approximation.
This PR changes the algorithm to use a more mathematically correct spherical interpolation, solving both issues. To avoid trigonometric calculations in this perf-sensitive section of the code, I adopted polynomial curve fitting approximation demonstrated here. The quality of approximation is now controlled by the constant
DEG_PER_TRIANGLE
, which is 30 degrees by default — this seems to be an OK value quality-wise, and reduces the number of GPU buffer size on a typical streets z11 view by ~4-5% (#8243). We could definitely tweak this though. Here's how this looks for oversized lines at the moment (3 triangles on the left, 2 on the right):Pending benchmark results, review and a discussion of the constant.
Launch Checklist
write tests for all new functionalitycovered by render testsdocument any changes to public APIsno changes