Skip to content

Commit

Permalink
DDS heatmap-radius
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Dec 20, 2017
1 parent 61fd7e6 commit 45de446
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 9 deletions.
1 change: 0 additions & 1 deletion src/render/draw_heatmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ function drawHeatmap(painter: Painter, sourceCache: SourceCache, layer: HeatmapS
programConfiguration.setUniforms(painter.context, program, layer.paint, {zoom});
first = false;
}
gl.uniform1f(program.uniforms.u_radius, layer.paint.get('heatmap-radius'));

gl.uniform1f(program.uniforms.u_extrude_scale, pixelsToTileUnits(tile, 1, zoom));

Expand Down
1 change: 0 additions & 1 deletion src/shaders/heatmap.fragment.glsl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma mapbox: define highp float weight

uniform highp float u_intensity;
uniform highp float u_radius;
varying vec2 v_extrude;

// Gaussian kernel coefficient: 1 / sqrt(2 * PI)
Expand Down
9 changes: 5 additions & 4 deletions src/shaders/heatmap.vertex.glsl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma mapbox: define highp float weight
#pragma mapbox: define mediump float radius

uniform mat4 u_matrix;
uniform float u_extrude_scale;
uniform float u_radius;
uniform float u_opacity;
uniform float u_intensity;

Expand All @@ -20,6 +20,7 @@ const highp float ZERO = 1.0 / 255.0 / 16.0;

void main(void) {
#pragma mapbox: initialize highp float weight
#pragma mapbox: initialize mediump float radius

// unencode the extrusion vector that we snuck into the a_pos vector
vec2 unscaled_extrude = vec2(mod(a_pos, 2.0) * 2.0 - 1.0);
Expand All @@ -37,12 +38,12 @@ void main(void) {
// S = sqrt(-2.0 * log(ZERO / (weight * u_intensity * GAUSS_COEF))) / 3.0
float S = sqrt(-2.0 * log(ZERO / weight / u_intensity / GAUSS_COEF)) / 3.0;

// Pass the varying in units of u_radius
// Pass the varying in units of radius
v_extrude = S * unscaled_extrude;

// Scale by u_radius and the zoom-based scale factor to produce actual
// Scale by radius and the zoom-based scale factor to produce actual
// mesh position
vec2 extrude = v_extrude * u_radius * u_extrude_scale;
vec2 extrude = v_extrude * radius * u_extrude_scale;

// multiply a_pos by 0.5, since we had it * 2 in order to sneak
// in extrusion data
Expand Down
2 changes: 1 addition & 1 deletion src/style-spec/reference/v8.json
Original file line number Diff line number Diff line change
Expand Up @@ -3215,7 +3215,7 @@
"minimum": 1,
"function": "interpolated",
"zoom-function": true,
"property-function": false,
"property-function": true,
"transition": true,
"units": "pixels",
"doc": "Radius of influence of one heatmap point in pixels. Increasing the value makes the heatmap smoother, but less detailed.",
Expand Down
4 changes: 2 additions & 2 deletions src/style/style_layer/heatmap_style_layer_properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ import type Color from '../../style-spec/util/color';


export type PaintProps = {|
"heatmap-radius": DataConstantProperty<number>,
"heatmap-radius": DataDrivenProperty<number>,
"heatmap-weight": DataDrivenProperty<number>,
"heatmap-intensity": DataConstantProperty<number>,
"heatmap-color": HeatmapColorProperty,
"heatmap-opacity": DataConstantProperty<number>,
|};

const paint: Properties<PaintProps> = new Properties({
"heatmap-radius": new DataConstantProperty(styleSpec["paint_heatmap"]["heatmap-radius"]),
"heatmap-radius": new DataDrivenProperty(styleSpec["paint_heatmap"]["heatmap-radius"]),
"heatmap-weight": new DataDrivenProperty(styleSpec["paint_heatmap"]["heatmap-weight"]),
"heatmap-intensity": new DataConstantProperty(styleSpec["paint_heatmap"]["heatmap-intensity"]),
"heatmap-color": new HeatmapColorProperty(styleSpec["paint_heatmap"]["heatmap-color"]),
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"version": 8,
"metadata": {
"test": {
"height": 64,
"width": 64
}
},
"sources": {
"geojson": {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"radius": 5
},
"geometry": {
"type": "Point",
"coordinates": [
-10,
0
]
}
},
{
"type": "Feature",
"properties": {
"radius": 10
},
"geometry": {
"type": "Point",
"coordinates": [
10,
0
]
}
}
]
}
}
},
"layers": [
{
"id": "heatmap",
"type": "heatmap",
"source": "geojson",
"paint": {
"heatmap-radius": [
"get",
"radius"
]
}
}
]
}

0 comments on commit 45de446

Please sign in to comment.