deck.gl-raster icon indicating copy to clipboard operation
deck.gl-raster copied to clipboard

Compute slope

Open kylebarron opened this issue 5 years ago • 0 comments

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 https://github.com/kylebarron/serverless-slope/issues/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 #20.

kylebarron avatar Jun 01 '20 04:06 kylebarron