diff --git a/src/render/draw_hillshade.js b/src/render/draw_hillshade.js index 03955fae95f..d5eb809f4ed 100644 --- a/src/render/draw_hillshade.js +++ b/src/render/draw_hillshade.js @@ -17,6 +17,7 @@ function drawHillshade(painter: Painter, sourceCache: SourceCache, layer: Hillsh if (painter.renderPass !== 'offscreen' && painter.renderPass !== 'translucent') return; const context = painter.context; + const sourceMaxZoom = sourceCache.getSource().maxzoom; context.setDepthMode(painter.depthModeForSublayer(0, DepthMode.ReadOnly)); context.setStencilMode(StencilMode.disabled); @@ -25,7 +26,7 @@ function drawHillshade(painter: Painter, sourceCache: SourceCache, layer: Hillsh for (const tileID of tileIDs) { const tile = sourceCache.getTile(tileID); if (tile.needsHillshadePrepare && painter.renderPass === 'offscreen') { - prepareHillshade(painter, tile); + prepareHillshade(painter, tile, sourceMaxZoom); continue; } else if (painter.renderPass === 'translucent') { renderHillshade(painter, tile, layer); @@ -95,7 +96,7 @@ function renderHillshade(painter, tile, layer) { // hillshade rendering is done in two steps. the prepare step first calculates the slope of the terrain in the x and y // directions for each pixel, and saves those values to a framebuffer texture in the r and g channels. -function prepareHillshade(painter, tile) { +function prepareHillshade(painter, tile, sourceMaxZoom) { const context = painter.context; const gl = context.gl; // decode rgba levels by using integer overflow to convert each Uint32Array element -> 4 Uint8Array elements. @@ -154,6 +155,7 @@ function prepareHillshade(painter, tile) { gl.uniform1f(program.uniforms.u_zoom, tile.tileID.overscaledZ); gl.uniform2fv(program.uniforms.u_dimension, [tileSize * 2, tileSize * 2]); gl.uniform1i(program.uniforms.u_image, 1); + gl.uniform1f(program.uniforms.u_maxzoom, sourceMaxZoom); const buffer = painter.rasterBoundsBuffer; const vao = painter.rasterBoundsVAO; diff --git a/src/shaders/hillshade_prepare.fragment.glsl b/src/shaders/hillshade_prepare.fragment.glsl index fd9e5613610..9c9866c34f5 100644 --- a/src/shaders/hillshade_prepare.fragment.glsl +++ b/src/shaders/hillshade_prepare.fragment.glsl @@ -6,6 +6,7 @@ uniform sampler2D u_image; varying vec2 v_pos; uniform vec2 u_dimension; uniform float u_zoom; +uniform float u_maxzoom; float getElevation(vec2 coord, float bias) { // Convert encoded elevation value to meters @@ -48,16 +49,16 @@ void main() { // which can be reduced to: pow(2, 19.25619978527 - u_zoom) // we want to vertically exaggerate the hillshading though, because otherwise // it is barely noticeable at low zooms. to do this, we multiply this by some - // scale factor pow(2, (u_zoom - 14) * a) where a is an arbitrary value and 14 is the - // maxzoom of the tile source. here we use a=0.3 which works out to the - // expression below. see nickidlugash's awesome breakdown for more info + // scale factor pow(2, (u_zoom - u_maxzoom) * a) where a is an arbitrary value + // Here we use a=0.3 which works out to the expression below. see + // nickidlugash's awesome breakdown for more info // https://github.com/mapbox/mapbox-gl-js/pull/5286#discussion_r148419556 float exaggeration = u_zoom < 2.0 ? 0.4 : u_zoom < 4.5 ? 0.35 : 0.3; vec2 deriv = vec2( (c + f + f + i) - (a + d + d + g), (g + h + h + i) - (a + b + b + c) - ) / pow(2.0, (u_zoom - 14.0) * exaggeration + 19.2562 - u_zoom); + ) / pow(2.0, (u_zoom - u_maxzoom) * exaggeration + 19.2562 - u_zoom); gl_FragColor = clamp(vec4( deriv.x / 2.0 + 0.5, diff --git a/test/integration/render-tests/combinations/background-opaque--hillshade-translucent/expected.png b/test/integration/render-tests/combinations/background-opaque--hillshade-translucent/expected.png index a500fe6d155..076c77bea21 100644 Binary files a/test/integration/render-tests/combinations/background-opaque--hillshade-translucent/expected.png and b/test/integration/render-tests/combinations/background-opaque--hillshade-translucent/expected.png differ diff --git a/test/integration/render-tests/combinations/background-translucent--hillshade-translucent/expected.png b/test/integration/render-tests/combinations/background-translucent--hillshade-translucent/expected.png index cb6fdf5573e..25f0109db66 100644 Binary files a/test/integration/render-tests/combinations/background-translucent--hillshade-translucent/expected.png and b/test/integration/render-tests/combinations/background-translucent--hillshade-translucent/expected.png differ diff --git a/test/integration/render-tests/combinations/circle-translucent--hillshade-translucent/expected.png b/test/integration/render-tests/combinations/circle-translucent--hillshade-translucent/expected.png index 7c31e1c1462..52f27b9ab98 100644 Binary files a/test/integration/render-tests/combinations/circle-translucent--hillshade-translucent/expected.png and b/test/integration/render-tests/combinations/circle-translucent--hillshade-translucent/expected.png differ diff --git a/test/integration/render-tests/combinations/fill-extrusion-translucent--hillshade-translucent/expected.png b/test/integration/render-tests/combinations/fill-extrusion-translucent--hillshade-translucent/expected.png index 6485e5b2bec..a5e43a94546 100644 Binary files a/test/integration/render-tests/combinations/fill-extrusion-translucent--hillshade-translucent/expected.png and b/test/integration/render-tests/combinations/fill-extrusion-translucent--hillshade-translucent/expected.png differ diff --git a/test/integration/render-tests/combinations/fill-opaque--hillshade-translucent/expected.png b/test/integration/render-tests/combinations/fill-opaque--hillshade-translucent/expected.png index e62d9e78226..e48b7a76e42 100644 Binary files a/test/integration/render-tests/combinations/fill-opaque--hillshade-translucent/expected.png and b/test/integration/render-tests/combinations/fill-opaque--hillshade-translucent/expected.png differ diff --git a/test/integration/render-tests/combinations/fill-translucent--hillshade-translucent/expected.png b/test/integration/render-tests/combinations/fill-translucent--hillshade-translucent/expected.png index c0e3736c2eb..1ed345667ab 100644 Binary files a/test/integration/render-tests/combinations/fill-translucent--hillshade-translucent/expected.png and b/test/integration/render-tests/combinations/fill-translucent--hillshade-translucent/expected.png differ diff --git a/test/integration/render-tests/combinations/heatmap-translucent--hillshade-translucent/expected.png b/test/integration/render-tests/combinations/heatmap-translucent--hillshade-translucent/expected.png index 68aeda8ec9f..66cdf386b67 100644 Binary files a/test/integration/render-tests/combinations/heatmap-translucent--hillshade-translucent/expected.png and b/test/integration/render-tests/combinations/heatmap-translucent--hillshade-translucent/expected.png differ diff --git a/test/integration/render-tests/combinations/hillshade-translucent--background-translucent/expected.png b/test/integration/render-tests/combinations/hillshade-translucent--background-translucent/expected.png index 02e5c7f2321..a196f72ceaf 100644 Binary files a/test/integration/render-tests/combinations/hillshade-translucent--background-translucent/expected.png and b/test/integration/render-tests/combinations/hillshade-translucent--background-translucent/expected.png differ diff --git a/test/integration/render-tests/combinations/hillshade-translucent--circle-translucent/expected.png b/test/integration/render-tests/combinations/hillshade-translucent--circle-translucent/expected.png index 69e6c3ea7bf..f8ec63fafc8 100644 Binary files a/test/integration/render-tests/combinations/hillshade-translucent--circle-translucent/expected.png and b/test/integration/render-tests/combinations/hillshade-translucent--circle-translucent/expected.png differ diff --git a/test/integration/render-tests/combinations/hillshade-translucent--fill-extrusion-translucent/expected.png b/test/integration/render-tests/combinations/hillshade-translucent--fill-extrusion-translucent/expected.png index 7cddbb4fda0..50f2daaf8a9 100644 Binary files a/test/integration/render-tests/combinations/hillshade-translucent--fill-extrusion-translucent/expected.png and b/test/integration/render-tests/combinations/hillshade-translucent--fill-extrusion-translucent/expected.png differ diff --git a/test/integration/render-tests/combinations/hillshade-translucent--fill-opaque/expected.png b/test/integration/render-tests/combinations/hillshade-translucent--fill-opaque/expected.png index 7d8a3ae1a62..d81e56a1137 100644 Binary files a/test/integration/render-tests/combinations/hillshade-translucent--fill-opaque/expected.png and b/test/integration/render-tests/combinations/hillshade-translucent--fill-opaque/expected.png differ diff --git a/test/integration/render-tests/combinations/hillshade-translucent--fill-translucent/expected.png b/test/integration/render-tests/combinations/hillshade-translucent--fill-translucent/expected.png index d9bbe0dded4..35dae7c7bea 100644 Binary files a/test/integration/render-tests/combinations/hillshade-translucent--fill-translucent/expected.png and b/test/integration/render-tests/combinations/hillshade-translucent--fill-translucent/expected.png differ diff --git a/test/integration/render-tests/combinations/hillshade-translucent--heatmap-translucent/expected.png b/test/integration/render-tests/combinations/hillshade-translucent--heatmap-translucent/expected.png index c0ffbb33534..2bdd39872ee 100644 Binary files a/test/integration/render-tests/combinations/hillshade-translucent--heatmap-translucent/expected.png and b/test/integration/render-tests/combinations/hillshade-translucent--heatmap-translucent/expected.png differ diff --git a/test/integration/render-tests/combinations/hillshade-translucent--hillshade-translucent/expected.png b/test/integration/render-tests/combinations/hillshade-translucent--hillshade-translucent/expected.png index 3de853ee948..0777b76e6e3 100644 Binary files a/test/integration/render-tests/combinations/hillshade-translucent--hillshade-translucent/expected.png and b/test/integration/render-tests/combinations/hillshade-translucent--hillshade-translucent/expected.png differ diff --git a/test/integration/render-tests/combinations/hillshade-translucent--line-translucent/expected.png b/test/integration/render-tests/combinations/hillshade-translucent--line-translucent/expected.png index 1fea6951ab4..5b77530360f 100644 Binary files a/test/integration/render-tests/combinations/hillshade-translucent--line-translucent/expected.png and b/test/integration/render-tests/combinations/hillshade-translucent--line-translucent/expected.png differ diff --git a/test/integration/render-tests/combinations/hillshade-translucent--raster-translucent/expected.png b/test/integration/render-tests/combinations/hillshade-translucent--raster-translucent/expected.png index ae61cc01805..319d6fe32c2 100644 Binary files a/test/integration/render-tests/combinations/hillshade-translucent--raster-translucent/expected.png and b/test/integration/render-tests/combinations/hillshade-translucent--raster-translucent/expected.png differ diff --git a/test/integration/render-tests/combinations/hillshade-translucent--symbol-translucent/expected.png b/test/integration/render-tests/combinations/hillshade-translucent--symbol-translucent/expected.png index 06d9f074a88..b668b2c56b3 100644 Binary files a/test/integration/render-tests/combinations/hillshade-translucent--symbol-translucent/expected.png and b/test/integration/render-tests/combinations/hillshade-translucent--symbol-translucent/expected.png differ diff --git a/test/integration/render-tests/combinations/line-translucent--hillshade-translucent/expected.png b/test/integration/render-tests/combinations/line-translucent--hillshade-translucent/expected.png index 71a48679705..73402b93b32 100644 Binary files a/test/integration/render-tests/combinations/line-translucent--hillshade-translucent/expected.png and b/test/integration/render-tests/combinations/line-translucent--hillshade-translucent/expected.png differ diff --git a/test/integration/render-tests/combinations/raster-translucent--hillshade-translucent/expected.png b/test/integration/render-tests/combinations/raster-translucent--hillshade-translucent/expected.png index d439aa3af1e..d64bd953284 100644 Binary files a/test/integration/render-tests/combinations/raster-translucent--hillshade-translucent/expected.png and b/test/integration/render-tests/combinations/raster-translucent--hillshade-translucent/expected.png differ diff --git a/test/integration/render-tests/combinations/symbol-translucent--hillshade-translucent/expected.png b/test/integration/render-tests/combinations/symbol-translucent--hillshade-translucent/expected.png index 7e07d51d304..2d48194bf14 100644 Binary files a/test/integration/render-tests/combinations/symbol-translucent--hillshade-translucent/expected.png and b/test/integration/render-tests/combinations/symbol-translucent--hillshade-translucent/expected.png differ diff --git a/test/integration/render-tests/hillshade-accent-color/default/expected.png b/test/integration/render-tests/hillshade-accent-color/default/expected.png index 751c59fa97c..658143518c5 100644 Binary files a/test/integration/render-tests/hillshade-accent-color/default/expected.png and b/test/integration/render-tests/hillshade-accent-color/default/expected.png differ diff --git a/test/integration/render-tests/hillshade-accent-color/literal/expected.png b/test/integration/render-tests/hillshade-accent-color/literal/expected.png index b18e72bba54..026283bef32 100644 Binary files a/test/integration/render-tests/hillshade-accent-color/literal/expected.png and b/test/integration/render-tests/hillshade-accent-color/literal/expected.png differ diff --git a/test/integration/render-tests/hillshade-accent-color/zoom-function/expected.png b/test/integration/render-tests/hillshade-accent-color/zoom-function/expected.png index 6606c3e7242..6eeac3cce5d 100644 Binary files a/test/integration/render-tests/hillshade-accent-color/zoom-function/expected.png and b/test/integration/render-tests/hillshade-accent-color/zoom-function/expected.png differ diff --git a/test/integration/render-tests/hillshade-highlight-color/default/expected.png b/test/integration/render-tests/hillshade-highlight-color/default/expected.png index 751c59fa97c..658143518c5 100644 Binary files a/test/integration/render-tests/hillshade-highlight-color/default/expected.png and b/test/integration/render-tests/hillshade-highlight-color/default/expected.png differ diff --git a/test/integration/render-tests/hillshade-highlight-color/literal/expected.png b/test/integration/render-tests/hillshade-highlight-color/literal/expected.png index a5734406d1b..1d963735e7d 100644 Binary files a/test/integration/render-tests/hillshade-highlight-color/literal/expected.png and b/test/integration/render-tests/hillshade-highlight-color/literal/expected.png differ diff --git a/test/integration/render-tests/hillshade-highlight-color/zoom-function/expected.png b/test/integration/render-tests/hillshade-highlight-color/zoom-function/expected.png index 7eaaef17d06..fa134e2ed5f 100644 Binary files a/test/integration/render-tests/hillshade-highlight-color/zoom-function/expected.png and b/test/integration/render-tests/hillshade-highlight-color/zoom-function/expected.png differ diff --git a/test/integration/render-tests/hillshade-shadow-color/default/expected.png b/test/integration/render-tests/hillshade-shadow-color/default/expected.png index 751c59fa97c..658143518c5 100644 Binary files a/test/integration/render-tests/hillshade-shadow-color/default/expected.png and b/test/integration/render-tests/hillshade-shadow-color/default/expected.png differ diff --git a/test/integration/render-tests/hillshade-shadow-color/literal/expected.png b/test/integration/render-tests/hillshade-shadow-color/literal/expected.png index 1097b1de4db..cc3aad56ba1 100644 Binary files a/test/integration/render-tests/hillshade-shadow-color/literal/expected.png and b/test/integration/render-tests/hillshade-shadow-color/literal/expected.png differ diff --git a/test/integration/render-tests/hillshade-shadow-color/zoom-function/expected.png b/test/integration/render-tests/hillshade-shadow-color/zoom-function/expected.png index 09cf48f16c9..945c411d06e 100644 Binary files a/test/integration/render-tests/hillshade-shadow-color/zoom-function/expected.png and b/test/integration/render-tests/hillshade-shadow-color/zoom-function/expected.png differ