summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
m---------mapbox-gl-js0
-rw-r--r--src/mbgl/programs/hillshade_prepare_program.hpp2
-rw-r--r--src/mbgl/renderer/layers/render_hillshade_layer.cpp8
-rw-r--r--src/mbgl/renderer/layers/render_hillshade_layer.hpp2
-rw-r--r--src/mbgl/renderer/sources/render_raster_dem_source.cpp2
-rw-r--r--src/mbgl/renderer/sources/render_raster_dem_source.hpp5
-rw-r--r--src/mbgl/shaders/hillshade_prepare.cpp9
7 files changed, 21 insertions, 7 deletions
diff --git a/mapbox-gl-js b/mapbox-gl-js
-Subproject 063fdebeaffbf6bc3ffff32233ed6248f42f3c5
+Subproject 920de235a7257f1042ff9a0eb0f39404d4724bc
diff --git a/src/mbgl/programs/hillshade_prepare_program.hpp b/src/mbgl/programs/hillshade_prepare_program.hpp
index 0f31a22df5..76638afddd 100644
--- a/src/mbgl/programs/hillshade_prepare_program.hpp
+++ b/src/mbgl/programs/hillshade_prepare_program.hpp
@@ -10,6 +10,7 @@ namespace mbgl {
namespace uniforms {
MBGL_DEFINE_UNIFORM_VECTOR(uint16_t, 2, u_dimension);
+MBGL_DEFINE_UNIFORM_SCALAR(float, u_maxzoom);
} // namespace uniforms
class HillshadePrepareProgram : public Program<
@@ -22,6 +23,7 @@ class HillshadePrepareProgram : public Program<
uniforms::u_matrix,
uniforms::u_dimension,
uniforms::u_zoom,
+ uniforms::u_maxzoom,
uniforms::u_image>,
style::Properties<>> {
public:
diff --git a/src/mbgl/renderer/layers/render_hillshade_layer.cpp b/src/mbgl/renderer/layers/render_hillshade_layer.cpp
index 55702849df..bcfd4ffe99 100644
--- a/src/mbgl/renderer/layers/render_hillshade_layer.cpp
+++ b/src/mbgl/renderer/layers/render_hillshade_layer.cpp
@@ -1,6 +1,7 @@
#include <mbgl/renderer/layers/render_hillshade_layer.hpp>
#include <mbgl/renderer/buckets/hillshade_bucket.hpp>
#include <mbgl/renderer/render_tile.hpp>
+#include <mbgl/renderer/sources/render_raster_dem_source.hpp>
#include <mbgl/renderer/paint_parameters.hpp>
#include <mbgl/renderer/render_static_data.hpp>
#include <mbgl/programs/programs.hpp>
@@ -55,10 +56,14 @@ bool RenderHillshadeLayer::hasTransition() const {
return unevaluated.hasTransition();
}
-void RenderHillshadeLayer::render(PaintParameters& parameters, RenderSource*) {
+void RenderHillshadeLayer::render(PaintParameters& parameters, RenderSource* src) {
if (parameters.pass != RenderPass::Translucent && parameters.pass != RenderPass::Pass3D)
return;
+ RenderRasterDEMSource* demsrc = dynamic_cast<RenderRasterDEMSource*>(src);
+ const uint8_t TERRAIN_RGB_MAXZOOM = 15;
+ const uint8_t maxzoom = demsrc != nullptr ? demsrc->getMaxZoom() : TERRAIN_RGB_MAXZOOM;
+
auto draw = [&] (const mat4& matrix,
const auto& vertexBuffer,
const auto& indexBuffer,
@@ -118,6 +123,7 @@ void RenderHillshadeLayer::render(PaintParameters& parameters, RenderSource*) {
uniforms::u_matrix::Value { mat },
uniforms::u_dimension::Value { {{uint16_t(tilesize * 2), uint16_t(tilesize * 2) }} },
uniforms::u_zoom::Value{ float(tile.id.canonical.z) },
+ uniforms::u_maxzoom::Value{ float(maxzoom) },
uniforms::u_image::Value{ 0 }
},
parameters.staticData.rasterVertexBuffer,
diff --git a/src/mbgl/renderer/layers/render_hillshade_layer.hpp b/src/mbgl/renderer/layers/render_hillshade_layer.hpp
index e9b9db1ec3..13093ee7ef 100644
--- a/src/mbgl/renderer/layers/render_hillshade_layer.hpp
+++ b/src/mbgl/renderer/layers/render_hillshade_layer.hpp
@@ -16,7 +16,7 @@ public:
void evaluate(const PropertyEvaluationParameters&) override;
bool hasTransition() const override;
- void render(PaintParameters&, RenderSource*) override;
+ void render(PaintParameters&, RenderSource* src) override;
std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const RenderLayer*>&) const override;
diff --git a/src/mbgl/renderer/sources/render_raster_dem_source.cpp b/src/mbgl/renderer/sources/render_raster_dem_source.cpp
index fb8f2c69d4..b3153622c3 100644
--- a/src/mbgl/renderer/sources/render_raster_dem_source.cpp
+++ b/src/mbgl/renderer/sources/render_raster_dem_source.cpp
@@ -36,7 +36,7 @@ void RenderRasterDEMSource::update(Immutable<style::Source::Impl> baseImpl_,
if (tileset != _tileset) {
tileset = _tileset;
-
+ maxzoom = tileset->zoomRange.max;
// TODO: this removes existing buckets, and will cause flickering.
// Should instead refresh tile data in place.
tilePyramid.tiles.clear();
diff --git a/src/mbgl/renderer/sources/render_raster_dem_source.hpp b/src/mbgl/renderer/sources/render_raster_dem_source.hpp
index 3c2a90c37f..741214a14d 100644
--- a/src/mbgl/renderer/sources/render_raster_dem_source.hpp
+++ b/src/mbgl/renderer/sources/render_raster_dem_source.hpp
@@ -36,11 +36,16 @@ public:
void reduceMemoryUse() final;
void dumpDebugLogs() const final;
+ uint8_t getMaxZoom() const {
+ return maxzoom;
+ };
+
private:
const style::RasterSource::Impl& impl() const;
TilePyramid tilePyramid;
optional<Tileset> tileset;
+ uint8_t maxzoom = 15;
protected:
void onTileChanged(Tile&) final;
diff --git a/src/mbgl/shaders/hillshade_prepare.cpp b/src/mbgl/shaders/hillshade_prepare.cpp
index 733658435e..8d0571f6a4 100644
--- a/src/mbgl/shaders/hillshade_prepare.cpp
+++ b/src/mbgl/shaders/hillshade_prepare.cpp
@@ -29,6 +29,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
@@ -71,16 +72,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,