diff --git a/src/render/draw_hillshade.js b/src/render/draw_hillshade.js index 24e47427dbb..73224685ef5 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 5261e97ab7d..8b306ae7d46 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 f35be6e2d25..958982d7d3a 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 1275c54f90e..1d61551b4c2 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 31526816877..6512b1bef2f 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 289ec25c420..24c40bf3e3c 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 177cdb1b252..b565c2dceb4 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 a67f1fc8267..5df1a210ac9 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 213a5e55e8e..cd74bba9153 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 0938be2181a..f7f6a3eb1f5 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 e24fced77f9..d3e5c935c8c 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 48d0439f2c2..144562b8edb 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 22e5ad02186..3dfd3f4afa8 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 2594d7728ff..ecc145cdee2 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 23e47c83cda..d094c3e80d9 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 55583ed39ae..c7649c64451 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 744e5ee108c..40aa234bb03 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 1ae9e92fa12..adfeaef88e7 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 bedc52c75d7..f2c5fc81c7d 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 4ce26449394..d83fb97b996 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 8c16eca14f5..305d7696e96 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 7a62ee900a4..f54cbbd4bcf 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 e235f57f5bb..b27fc1ef472 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 090f30b6c46..f057baf3b25 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 7a62ee900a4..f54cbbd4bcf 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 cf9abe37711..25b97968103 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 ed87d3edb7d..dcc5e2c8870 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 7a62ee900a4..f54cbbd4bcf 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 21e91777fa1..217678779f5 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 279f98d1638..fa5ee817abc 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