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

Compute slope #21

Open
kylebarron opened this issue Jun 1, 2020 · 0 comments
Open

Compute slope #21

kylebarron opened this issue Jun 1, 2020 · 0 comments

Comments

@kylebarron
Copy link
Owner

Handle 260px input

In order to compute slope, you use the surrounding 8 pixels. Mapbox GL JS assembles this by backfilling from neighboring tiles. This is annoying and tricky, so instead I'll just handle exporting 260px/516px tiles from dem-mosaic-tiler

https://github.com/mapbox/mapbox-gl-js/blob/cfeff87b2f16fdd8480d7b760d9c19f4accb7485/src/shaders/hillshade_prepare.vertex.glsl#L9-L15

void main() {
    gl_Position = u_matrix * vec4(a_pos, 0, 1);

    highp vec2 epsilon = 1.0 / u_dimension;
    float scale = (u_dimension.x - 2.0) / u_dimension.x;
    v_pos = (a_texture_pos / 8192.0) * scale + epsilon;
}

Algorithm

See kylebarron/serverless-slope#6 for a working pure-numpy implementation. See also the Mapbox GL JS hillshading shader code.

  • Latitude correction
  • Don't forget you need the pixel size (meters per pixel). In the linked issue I got that from rasterio, but you need to compute it based solely on the zoom level. Look to Mapbox's code.

Mipmaps?

Mipmaps don't work for non-power-of-2 textures I think. So

  • Do you need mipmaps for rendering? Not sure exactly what mipmaps do... just make it faster to render?
  • If so, it might be ideal to pass the 260x260px texture to the initial framebuffer pass, and then copy (blit?) the inner 256x256px to the next texture for rendering. Ref Explore using Framebuffers #20.
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

No branches or pull requests

1 participant