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

Reproject DataTiles using WebGL instead of 2d canvas. #15860

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

sweepline
Copy link

I have made an implementation of the ol/src/reproj:render() function using webgl instead of 2d canvas. This solves three problems:

  • Doing 4band reprojection in a single step instead of 3-bytes per pixel.
  • Linear interpolation of data instead of only nearest neighbor.
  • An issue in firefox described here means that a few pixels are mangled when using a 2d-canvas for reprojection.

Since this will be used for datatiles, it should be okay to do it in webgl, as datatiles are used for webgl based rendering anyway.

It does all the work for a datatile reprojection using a single WebGLRenderingContext. Whereas the current implementation computes an affine transformation from the source to the target explicitly, this is not needed when doing the work in WebGL as the transformation is built-in.

This makes it possible to do up 4band f32/u8 reprojection in 1 pass which means that you never need to do multiple passes as that is what a tiletexture can hold as well as far as I understand. It produces the same output in examples/numpytile for example which is supposedly 5-bands. I have not A/B tested the speed difference.

This means you can do interpolation when reprojection instead of always having to do nearest neighbour. It is even possible for f32 data if the webgl extension is available. Below is a comparison on some elevation-data. You can still see some artifacts because reprojected tiles have no gutter (also on the main branch), which I intend to fix in a future pull-request.
withartifacts
withoutartifacts

This fixes the same reprojection artifacts in Firefox as #14099, as well as the ones that could not be fixed in that PR.

This makes it possible to do 4band f32 reprojection in 1 pass which means that you never need to do multiple passes as that is what a tiletexture can hold as well

This means you can do F32 interpolation when reprojection instead of always having to do nearest neighbour

This fixes reprojection artifacts in Firefox
Copy link

📦 Preview the website for this branch here: https://deploy-preview-15860--ol-site.netlify.app/.

@tschaub
Copy link
Member

tschaub commented May 23, 2024

Awesome! Thank you for this contribution, @sweepline. It has been on my list for a while to rework our raster reprojection. I look forward to making time to dig into this, but just wanted to express my gratitude for your work.

*/
export class WebGLCanvas {
/**
* @param {WebGLRenderingContext} [gl] Context to render in.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param {WebGLRenderingContext} [gl] Context to render in.
* @param {WebGLRenderingContext} gl Context to render in.

@mike-000
Copy link
Contributor

mike-000 commented May 30, 2024

The webgl-reproj-no-wrap rendering test is passing at the center and resolution used. However if you move to the pole and zoom in slightly an error occurs in your code:

image

This seems unrelated to the failing tests where source.getTileSize(z) does not match source.getTileGrid().getTileSize(z).

Also https://deploy-preview-15860--ol-site.netlify.app/en/latest/examples/geotiff-reprojection.html and https://deploy-preview-15860--ol-site.netlify.app/en/latest/examples/multiple-cogs.html are not working for me (Windows 10 and Android) due to Too many active WebGL contexts. Oldest context will be lost. warnings. If I restrict the first example to 4 bands including added alpha by specifying bands: [1, 2, 3], it does work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants