Merge pull request #9745 from fredj/misc_webgl

Simplify heatmap's shaders
This commit is contained in:
Frédéric Junod
2019-07-05 08:27:08 +02:00
committed by GitHub
2 changed files with 4 additions and 19 deletions

View File

@@ -183,31 +183,24 @@ class Heatmap extends VectorLayer {
precision mediump float; precision mediump float;
attribute vec2 a_position; attribute vec2 a_position;
attribute vec2 a_texCoord; attribute vec2 a_texCoord;
attribute float a_rotateWithView;
attribute vec2 a_offsets; attribute vec2 a_offsets;
attribute float a_opacity; attribute float a_opacity;
uniform mat4 u_projectionMatrix; uniform mat4 u_projectionMatrix;
uniform mat4 u_offsetScaleMatrix; uniform mat4 u_offsetScaleMatrix;
uniform mat4 u_offsetRotateMatrix;
uniform float u_size; uniform float u_size;
varying vec2 v_texCoord; varying vec2 v_texCoord;
varying float v_opacity; varying float v_opacity;
void main(void) { void main(void) {
mat4 offsetMatrix = u_offsetScaleMatrix; vec4 offsets = u_offsetScaleMatrix * vec4(a_offsets, 0.0, 0.0);
if (a_rotateWithView == 1.0) {
offsetMatrix = u_offsetScaleMatrix * u_offsetRotateMatrix;
}
vec4 offsets = offsetMatrix * vec4(a_offsets, 0.0, 0.0);
gl_Position = u_projectionMatrix * vec4(a_position, 0.0, 1.0) + offsets * u_size; gl_Position = u_projectionMatrix * vec4(a_position, 0.0, 1.0) + offsets * u_size;
v_texCoord = a_texCoord; v_texCoord = a_texCoord;
v_opacity = a_opacity; v_opacity = a_opacity;
}`, }`,
fragmentShader: ` fragmentShader: `
precision mediump float; precision mediump float;
uniform float u_resolution;
uniform float u_blurSlope; uniform float u_blurSlope;
varying vec2 v_texCoord; varying vec2 v_texCoord;
@@ -226,10 +219,7 @@ class Heatmap extends VectorLayer {
}.bind(this), }.bind(this),
u_blurSlope: function() { u_blurSlope: function() {
return this.get(Property.RADIUS) / Math.max(1, this.get(Property.BLUR)); return this.get(Property.RADIUS) / Math.max(1, this.get(Property.BLUR));
}.bind(this), }.bind(this)
u_resolution: function(frameState) {
return frameState.viewState.resolution;
}
}, },
postProcesses: [ postProcesses: [
{ {
@@ -240,7 +230,6 @@ class Heatmap extends VectorLayer {
uniform sampler2D u_gradientTexture; uniform sampler2D u_gradientTexture;
varying vec2 v_texCoord; varying vec2 v_texCoord;
varying vec2 v_screenCoord;
void main() { void main() {
vec4 color = texture2D(u_image, v_texCoord); vec4 color = texture2D(u_image, v_texCoord);

View File

@@ -111,7 +111,7 @@ const HIT_FRAGMENT_SHADER = `
* source to compute the opacity of the quad on screen (from 0 to 1). This is only done on source change. * source to compute the opacity of the quad on screen (from 0 to 1). This is only done on source change.
* Note: this is multiplied with the color of the point which can also have an alpha value < 1. * Note: this is multiplied with the color of the point which can also have an alpha value < 1.
* @property {function(import("../../Feature").default):boolean} [rotateWithViewCallback] Will be called on every feature in the * @property {function(import("../../Feature").default):boolean} [rotateWithViewCallback] Will be called on every feature in the
* source to compute whether the quad on screen must stay upwards (`false`) or follow the view rotation (`true`). * source to compute whether the quad on screen must stay upwards (`false`) or follow the view rotation (`true`). Default is `false`.
* This is only done on source change. * This is only done on source change.
* @property {HTMLCanvasElement|HTMLImageElement|ImageData} [texture] Texture to use on points. `texCoordCallback` and `sizeCallback` * @property {HTMLCanvasElement|HTMLImageElement|ImageData} [texture] Texture to use on points. `texCoordCallback` and `sizeCallback`
* must be defined for this to have any effect. * must be defined for this to have any effect.
@@ -544,11 +544,7 @@ class WebGLPointsLayerRenderer extends WebGLLayerRenderer {
* @param {import("../../PluggableMap.js").FrameState} frameState current frame state * @param {import("../../PluggableMap.js").FrameState} frameState current frame state
*/ */
renderHitDetection(frameState) { renderHitDetection(frameState) {
const width = frameState.size[0]; this.hitRenderTarget_.setSize(frameState.size);
const height = frameState.size[1];
const size = [width, height];
this.hitRenderTarget_.setSize(size);
this.helper.useProgram(this.hitProgram_); this.helper.useProgram(this.hitProgram_);
this.helper.prepareDrawToRenderTarget(frameState, this.hitRenderTarget_, true); this.helper.prepareDrawToRenderTarget(frameState, this.hitRenderTarget_, true);