Add perspective correction for image, canvas and video sources #11292
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #9158. Currently, our image, canvas and video sources do simple linear interpolation when mapping a texture to a quad for the layer. This only works if the quad is exactly a rectangle — in other cases, the texture is distorted:
This PR introduces perspective correction, calculating a perspective transform matrix given the four coordinates (based on this brilliant StackOverflow answer by @gagern 🙏), and then passing a part of it as a uniform to the raster vertex shader so that it can properly calculate the
w
component (used by WebGL for texture mapping correction) for each of the four vertices.Launch Checklist
mapbox-gl-js
changelog:<changelog>Add perspective correction for non-rectangular image, canvas and video sources</changelog>