Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] add maxzoom uniform for raster-dem tilesets (#11134)
Browse files Browse the repository at this point in the history
* add maxzoom uniform to support external tilesets

* update git sha for gl-js

* try and fix android crash

* name default maxzoom constant
  • Loading branch information
mollymerp authored Feb 14, 2018
1 parent d4df044 commit a386cac
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion mapbox-gl-js
Submodule mapbox-gl-js updated 35 files
+2 −0 .stylelintrc
+177 −46 dist/mapbox-gl.css
+2 −1 package.json
+4 −2 src/render/draw_hillshade.js
+5 −4 src/shaders/hillshade_prepare.fragment.glsl
+ test/integration/render-tests/combinations/background-opaque--hillshade-translucent/expected.png
+ test/integration/render-tests/combinations/background-translucent--hillshade-translucent/expected.png
+ test/integration/render-tests/combinations/circle-translucent--hillshade-translucent/expected.png
+ test/integration/render-tests/combinations/fill-extrusion-translucent--hillshade-translucent/expected.png
+ test/integration/render-tests/combinations/fill-opaque--hillshade-translucent/expected.png
+ test/integration/render-tests/combinations/fill-translucent--hillshade-translucent/expected.png
+ test/integration/render-tests/combinations/heatmap-translucent--hillshade-translucent/expected.png
+ test/integration/render-tests/combinations/hillshade-translucent--background-translucent/expected.png
+ test/integration/render-tests/combinations/hillshade-translucent--circle-translucent/expected.png
+ test/integration/render-tests/combinations/hillshade-translucent--fill-extrusion-translucent/expected.png
+ test/integration/render-tests/combinations/hillshade-translucent--fill-opaque/expected.png
+ test/integration/render-tests/combinations/hillshade-translucent--fill-translucent/expected.png
+ test/integration/render-tests/combinations/hillshade-translucent--heatmap-translucent/expected.png
+ test/integration/render-tests/combinations/hillshade-translucent--hillshade-translucent/expected.png
+ test/integration/render-tests/combinations/hillshade-translucent--line-translucent/expected.png
+ test/integration/render-tests/combinations/hillshade-translucent--raster-translucent/expected.png
+ test/integration/render-tests/combinations/hillshade-translucent--symbol-translucent/expected.png
+ test/integration/render-tests/combinations/line-translucent--hillshade-translucent/expected.png
+ test/integration/render-tests/combinations/raster-translucent--hillshade-translucent/expected.png
+ test/integration/render-tests/combinations/symbol-translucent--hillshade-translucent/expected.png
+ test/integration/render-tests/hillshade-accent-color/default/expected.png
+ test/integration/render-tests/hillshade-accent-color/literal/expected.png
+ test/integration/render-tests/hillshade-accent-color/zoom-function/expected.png
+ test/integration/render-tests/hillshade-highlight-color/default/expected.png
+ test/integration/render-tests/hillshade-highlight-color/literal/expected.png
+ test/integration/render-tests/hillshade-highlight-color/zoom-function/expected.png
+ test/integration/render-tests/hillshade-shadow-color/default/expected.png
+ test/integration/render-tests/hillshade-shadow-color/literal/expected.png
+ test/integration/render-tests/hillshade-shadow-color/zoom-function/expected.png
+340 −315 yarn.lock
2 changes: 2 additions & 0 deletions src/mbgl/programs/hillshade_prepare_program.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand All @@ -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:
Expand Down
8 changes: 7 additions & 1 deletion src/mbgl/renderer/layers/render_hillshade_layer.cpp
Original file line number Diff line number Diff line change
@@ -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>
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/renderer/layers/render_hillshade_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class RenderHillshadeLayer: public RenderLayer {
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;

Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/renderer/sources/render_raster_dem_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions src/mbgl/renderer/sources/render_raster_dem_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,16 @@ class RenderRasterDEMSource : public RenderSource {
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;
Expand Down
9 changes: 5 additions & 4 deletions src/mbgl/shaders/hillshade_prepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit a386cac

Please sign in to comment.