[core, ios, macos, android, node] Heatmap layer (#11046)
Co-Authored-By: Konstantin Käfer <mail@kkaefer.com> Co-Authored-By: Anand Thakker <anandthakker@users.noreply.github.com> Co-Authored-By: Minh Nguyễn <1ec5@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
1fdec7a5c1
commit
82de856c94
@@ -30,7 +30,7 @@ MBGL_DEFINE_ATTRIBUTE(int16_t, 2, a_anchor_pos);
|
||||
MBGL_DEFINE_ATTRIBUTE(uint16_t, 2, a_texture_pos);
|
||||
MBGL_DEFINE_ATTRIBUTE(int16_t, 4, a_normal_ed);
|
||||
MBGL_DEFINE_ATTRIBUTE(uint8_t, 1, a_fade_opacity);
|
||||
MBGL_DEFINE_ATTRIBUTE(uint8_t, 2, a_placed);
|
||||
MBGL_DEFINE_ATTRIBUTE(uint8_t, 2, a_placed);
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
struct a_data {
|
||||
@@ -142,6 +142,11 @@ struct a_halo_blur {
|
||||
using Type = gl::Attribute<float, 1>;
|
||||
};
|
||||
|
||||
struct a_weight {
|
||||
static auto name() { return "a_weight"; }
|
||||
using Type = gl::Attribute<float, 1>;
|
||||
};
|
||||
|
||||
} // namespace attributes
|
||||
|
||||
struct PositionOnlyLayoutAttributes : gl::Attributes<
|
||||
|
||||
7
src/mbgl/programs/heatmap_program.cpp
Normal file
7
src/mbgl/programs/heatmap_program.cpp
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <mbgl/programs/heatmap_program.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
static_assert(sizeof(HeatmapLayoutVertex) == 4, "expected HeatmapLayoutVertex size");
|
||||
|
||||
} // namespace mbgl
|
||||
49
src/mbgl/programs/heatmap_program.hpp
Normal file
49
src/mbgl/programs/heatmap_program.hpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/programs/program.hpp>
|
||||
#include <mbgl/programs/attributes.hpp>
|
||||
#include <mbgl/programs/uniforms.hpp>
|
||||
#include <mbgl/shaders/heatmap.hpp>
|
||||
#include <mbgl/util/geometry.hpp>
|
||||
#include <mbgl/style/layers/heatmap_layer_properties.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
namespace uniforms {
|
||||
MBGL_DEFINE_UNIFORM_SCALAR(float, u_intensity);
|
||||
} // namespace uniforms
|
||||
|
||||
class HeatmapProgram : public Program<
|
||||
shaders::heatmap,
|
||||
gl::Triangle,
|
||||
gl::Attributes<
|
||||
attributes::a_pos>,
|
||||
gl::Uniforms<
|
||||
uniforms::u_intensity,
|
||||
uniforms::u_matrix,
|
||||
uniforms::heatmap::u_extrude_scale>,
|
||||
style::HeatmapPaintProperties>
|
||||
{
|
||||
public:
|
||||
using Program::Program;
|
||||
|
||||
/*
|
||||
* @param {number} x vertex position
|
||||
* @param {number} y vertex position
|
||||
* @param {number} ex extrude normal
|
||||
* @param {number} ey extrude normal
|
||||
*/
|
||||
static LayoutVertex vertex(Point<int16_t> p, float ex, float ey) {
|
||||
return LayoutVertex {
|
||||
{{
|
||||
static_cast<int16_t>((p.x * 2) + ((ex + 1) / 2)),
|
||||
static_cast<int16_t>((p.y * 2) + ((ey + 1) / 2))
|
||||
}}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
using HeatmapLayoutVertex = HeatmapProgram::LayoutVertex;
|
||||
using HeatmapAttributes = HeatmapProgram::Attributes;
|
||||
|
||||
} // namespace mbgl
|
||||
7
src/mbgl/programs/heatmap_texture_program.cpp
Normal file
7
src/mbgl/programs/heatmap_texture_program.cpp
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <mbgl/programs/heatmap_texture_program.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
static_assert(sizeof(HeatmapTextureLayoutVertex) == 4, "expected HeatmapTextureLayoutVertex size");
|
||||
|
||||
} // namespace mbgl
|
||||
43
src/mbgl/programs/heatmap_texture_program.hpp
Normal file
43
src/mbgl/programs/heatmap_texture_program.hpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/programs/program.hpp>
|
||||
#include <mbgl/programs/attributes.hpp>
|
||||
#include <mbgl/programs/uniforms.hpp>
|
||||
#include <mbgl/shaders/heatmap_texture.hpp>
|
||||
#include <mbgl/style/properties.hpp>
|
||||
#include <mbgl/util/geometry.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
namespace uniforms {
|
||||
MBGL_DEFINE_UNIFORM_SCALAR(gl::TextureUnit, u_color_ramp);
|
||||
} // namespace uniforms
|
||||
|
||||
class HeatmapTextureProgram : public Program<
|
||||
shaders::heatmap_texture,
|
||||
gl::Triangle,
|
||||
gl::Attributes<attributes::a_pos>,
|
||||
gl::Uniforms<
|
||||
uniforms::u_matrix,
|
||||
uniforms::u_world,
|
||||
uniforms::u_image,
|
||||
uniforms::u_color_ramp,
|
||||
uniforms::u_opacity>,
|
||||
style::Properties<>> {
|
||||
public:
|
||||
using Program::Program;
|
||||
|
||||
static LayoutVertex layoutVertex(Point<int16_t> p) {
|
||||
return LayoutVertex{
|
||||
{{
|
||||
p.x,
|
||||
p.y
|
||||
}}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
using HeatmapTextureLayoutVertex = HeatmapTextureProgram::LayoutVertex;
|
||||
using HeatmapTextureAttributes = HeatmapTextureProgram::Attributes;
|
||||
|
||||
} // namespace mbgl
|
||||
@@ -6,6 +6,8 @@
|
||||
#include <mbgl/programs/extrusion_texture_program.hpp>
|
||||
#include <mbgl/programs/fill_program.hpp>
|
||||
#include <mbgl/programs/fill_extrusion_program.hpp>
|
||||
#include <mbgl/programs/heatmap_program.hpp>
|
||||
#include <mbgl/programs/heatmap_texture_program.hpp>
|
||||
#include <mbgl/programs/hillshade_program.hpp>
|
||||
#include <mbgl/programs/hillshade_prepare_program.hpp>
|
||||
#include <mbgl/programs/line_program.hpp>
|
||||
@@ -30,6 +32,8 @@ public:
|
||||
fillPattern(context, programParameters),
|
||||
fillOutline(context, programParameters),
|
||||
fillOutlinePattern(context, programParameters),
|
||||
heatmap(context, programParameters),
|
||||
heatmapTexture(context, programParameters),
|
||||
hillshade(context, programParameters),
|
||||
hillshadePrepare(context, programParameters),
|
||||
line(context, programParameters),
|
||||
@@ -55,6 +59,8 @@ public:
|
||||
ProgramMap<FillPatternProgram> fillPattern;
|
||||
ProgramMap<FillOutlineProgram> fillOutline;
|
||||
ProgramMap<FillOutlinePatternProgram> fillOutlinePattern;
|
||||
ProgramMap<HeatmapProgram> heatmap;
|
||||
HeatmapTextureProgram heatmapTexture;
|
||||
HillshadeProgram hillshade;
|
||||
HillshadePrepareProgram hillshadePrepare;
|
||||
ProgramMap<LineProgram> line;
|
||||
|
||||
@@ -37,9 +37,14 @@ MBGL_DEFINE_UNIFORM_SCALAR(Size, u_texsize);
|
||||
MBGL_DEFINE_UNIFORM_SCALAR(bool, u_pitch_with_map);
|
||||
MBGL_DEFINE_UNIFORM_SCALAR(float, u_camera_to_center_distance);
|
||||
MBGL_DEFINE_UNIFORM_SCALAR(float, u_fade_change);
|
||||
MBGL_DEFINE_UNIFORM_SCALAR(float, u_weight);
|
||||
|
||||
MBGL_DEFINE_UNIFORM_VECTOR(float, 2, u_extrude_scale);
|
||||
|
||||
namespace heatmap {
|
||||
MBGL_DEFINE_UNIFORM_SCALAR(float, u_extrude_scale);
|
||||
} // namespace heatmap
|
||||
|
||||
MBGL_DEFINE_UNIFORM_VECTOR(uint16_t, 2, u_pattern_tl_a);
|
||||
MBGL_DEFINE_UNIFORM_VECTOR(uint16_t, 2, u_pattern_br_a);
|
||||
MBGL_DEFINE_UNIFORM_VECTOR(uint16_t, 2, u_pattern_tl_b);
|
||||
|
||||
Reference in New Issue
Block a user