maplibre-gl 6.2.0 → 6.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/maplibre-gl-dev.mjs +522 -223
- package/dist/maplibre-gl-dev.mjs.map +1 -1
- package/dist/maplibre-gl-shared-dev.mjs +103 -58
- package/dist/maplibre-gl-shared-dev.mjs.map +1 -1
- package/dist/maplibre-gl-shared.mjs +2 -2
- package/dist/maplibre-gl-shared.mjs.map +1 -1
- package/dist/maplibre-gl-worker-dev.mjs +23 -49
- package/dist/maplibre-gl-worker-dev.mjs.map +1 -1
- package/dist/maplibre-gl-worker.mjs +2 -2
- package/dist/maplibre-gl-worker.mjs.map +1 -1
- package/dist/maplibre-gl.css +1 -1
- package/dist/maplibre-gl.d.ts +214 -59
- package/dist/maplibre-gl.mjs +44 -44
- package/dist/maplibre-gl.mjs.map +1 -1
- package/package.json +10 -20
- package/src/data/feature_index.bench.ts +21 -0
- package/src/data/segment.test.ts +2 -2
- package/src/geo/edge_insets.test.ts +1 -1
- package/src/geo/lng_lat.test.ts +7 -7
- package/src/geo/lng_lat_bounds.test.ts +4 -4
- package/src/geo/mercator_coordinate.test.ts +2 -2
- package/src/geo/projection/camera_helper.ts +5 -0
- package/src/geo/projection/globe_transform.test.ts +25 -0
- package/src/geo/projection/globe_transform.ts +7 -3
- package/src/geo/projection/mercator_camera_helper.ts +1 -1
- package/src/geo/projection/mercator_transform.ts +21 -5
- package/src/geo/projection/vertical_perspective_camera_helper.ts +60 -31
- package/src/geo/projection/vertical_perspective_transform.ts +7 -1
- package/src/geo/transform_interface.ts +13 -1
- package/src/index.ts +7 -2
- package/src/render/image_atlas.test.ts +72 -0
- package/src/render/image_atlas.ts +17 -2
- package/src/render/image_manager.test.ts +46 -0
- package/src/render/image_manager.ts +9 -2
- package/src/render/painter.ts +1 -12
- package/src/render/update_pattern_positions_in_program.test.ts +1 -1
- package/src/shaders/glsl/_prelude.vertex.glsl +2 -3
- package/src/shaders/glsl/_prelude.vertex.glsl.g.ts +1 -1
- package/src/shaders/glsl/circle.vertex.glsl +4 -4
- package/src/shaders/glsl/circle.vertex.glsl.g.ts +1 -1
- package/src/shaders/glsl/fill_extrusion.vertex.glsl +3 -3
- package/src/shaders/glsl/fill_extrusion.vertex.glsl.g.ts +1 -1
- package/src/shaders/glsl/fill_extrusion_pattern.vertex.glsl +5 -5
- package/src/shaders/glsl/fill_extrusion_pattern.vertex.glsl.g.ts +1 -1
- package/src/shaders/glsl/heatmap.vertex.glsl +4 -4
- package/src/shaders/glsl/heatmap.vertex.glsl.g.ts +1 -1
- package/src/shaders/glsl/line.vertex.glsl +7 -7
- package/src/shaders/glsl/line.vertex.glsl.g.ts +1 -1
- package/src/shaders/glsl/line_gradient.vertex.glsl +6 -6
- package/src/shaders/glsl/line_gradient.vertex.glsl.g.ts +1 -1
- package/src/shaders/glsl/line_gradient_sdf.vertex.glsl +7 -7
- package/src/shaders/glsl/line_gradient_sdf.vertex.glsl.g.ts +1 -1
- package/src/shaders/glsl/line_pattern.vertex.glsl +7 -7
- package/src/shaders/glsl/line_pattern.vertex.glsl.g.ts +1 -1
- package/src/shaders/glsl/line_sdf.vertex.glsl +7 -7
- package/src/shaders/glsl/line_sdf.vertex.glsl.g.ts +1 -1
- package/src/shaders/glsl/raster.fragment.glsl +4 -4
- package/src/shaders/glsl/raster.fragment.glsl.g.ts +1 -1
- package/src/shaders/glsl/raster.vertex.glsl +11 -6
- package/src/shaders/glsl/raster.vertex.glsl.g.ts +1 -1
- package/src/shaders/glsl/symbol_icon.vertex.glsl +5 -5
- package/src/shaders/glsl/symbol_icon.vertex.glsl.g.ts +1 -1
- package/src/shaders/glsl/symbol_sdf.vertex.glsl +5 -5
- package/src/shaders/glsl/symbol_sdf.vertex.glsl.g.ts +1 -1
- package/src/shaders/glsl/symbol_text_and_icon.vertex.glsl +6 -6
- package/src/shaders/glsl/symbol_text_and_icon.vertex.glsl.g.ts +1 -1
- package/src/source/canvas_source.test.ts +31 -0
- package/src/source/canvas_source.ts +2 -1
- package/src/source/geojson_worker_source.test.ts +88 -0
- package/src/source/geojson_worker_source.ts +22 -39
- package/src/source/image_source.test.ts +205 -7
- package/src/source/image_source.ts +118 -4
- package/src/source/raster_dem_tile_worker_source.test.ts +1 -1
- package/src/source/vector_tile_worker_source.test.ts +94 -2
- package/src/source/vector_tile_worker_source.ts +18 -27
- package/src/source/video_source.test.ts +12 -8
- package/src/source/worker_tile.bench.ts +10 -0
- package/src/source/worker_tile.ts +0 -3
- package/src/style/create_style_layer.bench.ts +15 -0
- package/src/style/properties.bench.ts +81 -0
- package/src/style/style.test.ts +11 -10
- package/src/style/style_image.ts +67 -9
- package/src/style/style_layer.bench.ts +65 -0
- package/src/style/style_layer.test.ts +1 -1
- package/src/style/style_layer.ts +2 -2
- package/src/style/validate_style.bench.ts +11 -0
- package/src/style/validate_style.test.ts +2 -2
- package/src/symbol/anchor.test.ts +2 -2
- package/src/symbol/collision_index.bench.ts +116 -0
- package/src/symbol/cross_tile_symbol_index.bench.ts +49 -0
- package/src/symbol/shaping.test.ts +2 -1
- package/src/symbol/symbol_layout.bench.ts +30 -0
- package/src/tile/tile_id.test.ts +1 -1
- package/src/tile/tile_manager.ts +2 -2
- package/src/ui/control/fullscreen_control.test.ts +10 -10
- package/src/ui/control/geolocate_control.test.ts +3 -5
- package/src/ui/control/globe_control.test.ts +6 -6
- package/src/ui/events.ts +1 -1
- package/src/ui/handler/scroll_zoom.test.ts +50 -0
- package/src/ui/handler/two_fingers_touch.test.ts +3 -3
- package/src/ui/handler_manager.test.ts +243 -3
- package/src/ui/handler_manager.ts +79 -16
- package/src/ui/map.ts +17 -3
- package/src/ui/map_tests/map_cross_window.test.ts +2 -2
- package/src/ui/map_tests/map_events.test.ts +3 -3
- package/src/ui/map_tests/map_images.test.ts +29 -0
- package/src/ui/map_tests/map_style.test.ts +9 -8
- package/src/ui/map_tests/map_webgl.test.ts +29 -0
- package/src/ui/marker.test.ts +26 -42
- package/src/ui/popup.test.ts +14 -14
- package/src/util/evented.test.ts +33 -28
- package/src/util/evented.ts +69 -43
- package/src/util/test/null_gl.ts +10 -0
- package/src/util/test/util.ts +2 -1
- package/src/util/util.test.ts +1 -1
- package/src/util/web_worker_transfer.test.ts +5 -5
- package/src/webgl/context.ts +20 -0
- package/src/webgl/draw/draw_raster.ts +11 -6
- package/src/webgl/program/raster_program.ts +11 -0
- package/src/webgl/program.ts +31 -16
- package/src/webgl/texture.test.ts +16 -1
- package/src/webgl/texture.ts +3 -0
- package/src/webgl/vertex_buffer.test.ts +17 -2
- package/src/webgl/vertex_buffer.ts +24 -13
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import {test, expect, vi} from 'vitest';
|
|
2
|
+
import {ImageAtlas, ImagePosition, IMAGE_PADDING} from './image_atlas.ts';
|
|
3
|
+
import {Context} from '../webgl/context.ts';
|
|
4
|
+
import {Texture} from '../webgl/texture.ts';
|
|
5
|
+
import {createNullGL} from '../util/test/null_gl.ts';
|
|
6
|
+
import {RGBAImage} from '../util/image.ts';
|
|
7
|
+
|
|
8
|
+
import type {StyleImage} from '../style/style_image.ts';
|
|
9
|
+
|
|
10
|
+
const webGLImage = (renderWithWebGL: () => void): StyleImage => ({
|
|
11
|
+
data: new RGBAImage({width: 2, height: 2}),
|
|
12
|
+
version: 1,
|
|
13
|
+
pixelRatio: 1,
|
|
14
|
+
sdf: false,
|
|
15
|
+
isWebGLImage: true,
|
|
16
|
+
userImage: {width: 2, height: 2, data: {renderWithWebGL}}
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('a WebGL image is packed into the atlas without copying its blank pixels', () => {
|
|
20
|
+
const copy = vi.spyOn(RGBAImage, 'copy');
|
|
21
|
+
const icon = (isWebGLImage?: boolean) => ({data: new RGBAImage({width: 2, height: 2}), version: 0, pixelRatio: 1, sdf: false, isWebGLImage});
|
|
22
|
+
|
|
23
|
+
const atlas = new ImageAtlas({webgl: icon(true), pixels: icon()}, {});
|
|
24
|
+
|
|
25
|
+
expect(atlas.iconPositions.webgl.paddedRect.w).toBe(2 + 2 * IMAGE_PADDING);
|
|
26
|
+
expect(copy).toHaveBeenCalledTimes(1);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('patchUpdatedImage lets a WebGL image render its own slot instead of uploading pixels', () => {
|
|
30
|
+
const renderWithWebGL = vi.fn();
|
|
31
|
+
const context = new Context(createNullGL());
|
|
32
|
+
const texture = new Texture(context, new RGBAImage({width: 16, height: 16}), context.gl.RGBA);
|
|
33
|
+
const position = new ImagePosition({x: 4, y: 8, w: 4, h: 4}, {version: 0} as StyleImage);
|
|
34
|
+
vi.spyOn(texture, 'update');
|
|
35
|
+
|
|
36
|
+
new ImageAtlas({}, {}).patchUpdatedImage(position, webGLImage(renderWithWebGL), texture);
|
|
37
|
+
|
|
38
|
+
expect(renderWithWebGL).toHaveBeenCalledWith({gl: context.gl, texture: texture.texture, x: 5, y: 9, width: 2, height: 2});
|
|
39
|
+
expect(texture.update).not.toHaveBeenCalled();
|
|
40
|
+
expect(position.version).toBe(1);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('a WebGL image starts out owing every atlas a render, whatever version it is at', () => {
|
|
44
|
+
const webgl = new ImagePosition({x: 0, y: 0, w: 4, h: 4}, {version: 7, isWebGLImage: true} as StyleImage);
|
|
45
|
+
expect([webgl.needsFirstWebGLRender, webgl.version]).toEqual([true, 7]);
|
|
46
|
+
expect(new ImagePosition({x: 0, y: 0, w: 4, h: 4}, {version: 7} as StyleImage).needsFirstWebGLRender).toBe(false);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('patchUpdatedImages resets WebGL state between images, so the second never trusts a cache the first invalidated', () => {
|
|
50
|
+
const context = new Context(createNullGL());
|
|
51
|
+
const texture = new Texture(context, new RGBAImage({width: 16, height: 16}), context.gl.RGBA);
|
|
52
|
+
vi.spyOn(context, 'setDirty');
|
|
53
|
+
vi.spyOn(context, 'setCustomLayerDefaults');
|
|
54
|
+
let rendered = 0;
|
|
55
|
+
const renderWithWebGL = vi.fn(() => {
|
|
56
|
+
expect(context.setDirty).toHaveBeenCalledTimes(rendered++);
|
|
57
|
+
expect(context.setCustomLayerDefaults).toHaveBeenCalledTimes(rendered);
|
|
58
|
+
});
|
|
59
|
+
const atlas = new ImageAtlas({}, {});
|
|
60
|
+
const imageManager = {
|
|
61
|
+
updatedImages: {a: true, b: true},
|
|
62
|
+
dispatchRenderCallbacks: vi.fn(),
|
|
63
|
+
getImage: () => webGLImage(renderWithWebGL)
|
|
64
|
+
} as any;
|
|
65
|
+
atlas.iconPositions.a = new ImagePosition({x: 0, y: 0, w: 4, h: 4}, {version: 0} as StyleImage);
|
|
66
|
+
atlas.iconPositions.b = new ImagePosition({x: 4, y: 0, w: 4, h: 4}, {version: 0} as StyleImage);
|
|
67
|
+
|
|
68
|
+
atlas.patchUpdatedImages(imageManager, texture);
|
|
69
|
+
|
|
70
|
+
expect(renderWithWebGL).toHaveBeenCalledTimes(2);
|
|
71
|
+
expect(context.setDirty).toHaveBeenCalledTimes(2);
|
|
72
|
+
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* eslint-disable key-spacing */
|
|
2
2
|
import {RGBAImage} from '../util/image.ts';
|
|
3
3
|
import {register} from '../util/web_worker_transfer.ts';
|
|
4
|
+
import {isStyleImageWebGLData} from '../style/style_image.ts';
|
|
4
5
|
import potpack from 'potpack';
|
|
5
6
|
|
|
6
7
|
import type {StyleImage} from '../style/style_image.ts';
|
|
@@ -17,6 +18,7 @@ export class ImagePosition {
|
|
|
17
18
|
paddedRect: Rect;
|
|
18
19
|
pixelRatio: number;
|
|
19
20
|
version: number;
|
|
21
|
+
needsFirstWebGLRender: boolean;
|
|
20
22
|
stretchY: Array<[number, number]>;
|
|
21
23
|
stretchX: Array<[number, number]>;
|
|
22
24
|
content: [number, number, number, number];
|
|
@@ -26,6 +28,7 @@ export class ImagePosition {
|
|
|
26
28
|
constructor(paddedRect: Rect, {
|
|
27
29
|
pixelRatio,
|
|
28
30
|
version,
|
|
31
|
+
isWebGLImage = false,
|
|
29
32
|
stretchX,
|
|
30
33
|
stretchY,
|
|
31
34
|
content,
|
|
@@ -38,6 +41,7 @@ export class ImagePosition {
|
|
|
38
41
|
this.stretchY = stretchY;
|
|
39
42
|
this.content = content;
|
|
40
43
|
this.version = version;
|
|
44
|
+
this.needsFirstWebGLRender = isWebGLImage;
|
|
41
45
|
this.textFitWidth = textFitWidth;
|
|
42
46
|
this.textFitHeight = textFitHeight;
|
|
43
47
|
}
|
|
@@ -92,6 +96,7 @@ export class ImageAtlas {
|
|
|
92
96
|
|
|
93
97
|
for (const id in icons) {
|
|
94
98
|
const src = icons[id];
|
|
99
|
+
if (src.isWebGLImage) continue;
|
|
95
100
|
const bin = iconPositions[id].paddedRect;
|
|
96
101
|
RGBAImage.copy(src.data, image, {x: 0, y: 0}, {x: bin.x + IMAGE_PADDING, y: bin.y + IMAGE_PADDING}, src.data);
|
|
97
102
|
}
|
|
@@ -146,11 +151,21 @@ export class ImageAtlas {
|
|
|
146
151
|
patchUpdatedImage(position: ImagePosition, image: StyleImage, texture: Texture): void {
|
|
147
152
|
if (!position || !image) return;
|
|
148
153
|
|
|
149
|
-
if (position.version === image.version) return;
|
|
154
|
+
if (!position.needsFirstWebGLRender && position.version === image.version) return;
|
|
150
155
|
|
|
156
|
+
position.needsFirstWebGLRender = false;
|
|
151
157
|
position.version = image.version;
|
|
152
158
|
const [x, y] = position.tl;
|
|
153
|
-
|
|
159
|
+
const data = image.userImage?.data;
|
|
160
|
+
if (!isStyleImageWebGLData(data)) {
|
|
161
|
+
texture.update(image.data, undefined, {x, y});
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const {width, height} = image.data;
|
|
166
|
+
texture.context.setCustomLayerDefaults();
|
|
167
|
+
data.renderWithWebGL({gl: texture.context.gl, texture: texture.texture, x, y, width, height});
|
|
168
|
+
texture.context.setDirty();
|
|
154
169
|
}
|
|
155
170
|
|
|
156
171
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {test, expect, vi} from 'vitest';
|
|
2
|
+
import {ImageManager} from './image_manager.ts';
|
|
3
|
+
import {RGBAImage} from '../util/image.ts';
|
|
4
|
+
|
|
5
|
+
import type {StyleImage} from '../style/style_image.ts';
|
|
6
|
+
|
|
7
|
+
function webGLImage(render?: () => boolean): StyleImage {
|
|
8
|
+
return {
|
|
9
|
+
data: new RGBAImage({width: 2, height: 2}),
|
|
10
|
+
version: 0,
|
|
11
|
+
pixelRatio: 1,
|
|
12
|
+
sdf: false,
|
|
13
|
+
isWebGLImage: true,
|
|
14
|
+
userImage: {width: 2, height: 2, data: {renderWithWebGL: vi.fn()}, render}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
test('a WebGL image owes every atlas a render as soon as it is added, even without a render callback', () => {
|
|
19
|
+
const manager = new ImageManager();
|
|
20
|
+
manager.addImage('webgl', webGLImage());
|
|
21
|
+
|
|
22
|
+
expect(manager.getImage('webgl').version).toBe(1);
|
|
23
|
+
expect(manager.updatedImages.webgl).toBe(true);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('a WebGL image is re-rendered when its render callback reports a change', () => {
|
|
27
|
+
const manager = new ImageManager();
|
|
28
|
+
manager.addImage('webgl', webGLImage(() => true));
|
|
29
|
+
const version = manager.getImage('webgl').version;
|
|
30
|
+
|
|
31
|
+
manager.beginFrame();
|
|
32
|
+
manager.dispatchRenderCallbacks(['webgl']);
|
|
33
|
+
|
|
34
|
+
expect(manager.getImage('webgl').version).toBe(version + 1);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('a WebGL image is left alone when its render callback reports no change', () => {
|
|
38
|
+
const manager = new ImageManager();
|
|
39
|
+
manager.addImage('webgl', webGLImage(() => false));
|
|
40
|
+
const version = manager.getImage('webgl').version;
|
|
41
|
+
|
|
42
|
+
manager.beginFrame();
|
|
43
|
+
manager.dispatchRenderCallbacks(['webgl']);
|
|
44
|
+
|
|
45
|
+
expect(manager.getImage('webgl').version).toBe(version);
|
|
46
|
+
});
|
|
@@ -29,6 +29,11 @@ type Pattern = {
|
|
|
29
29
|
*/
|
|
30
30
|
const padding = 1;
|
|
31
31
|
|
|
32
|
+
type ImageManagerEventType = {
|
|
33
|
+
error: ErrorEvent;
|
|
34
|
+
styleimagemissing: MapStyleImageMissingEvent;
|
|
35
|
+
};
|
|
36
|
+
|
|
32
37
|
/**
|
|
33
38
|
* ImageManager does three things:
|
|
34
39
|
*
|
|
@@ -40,7 +45,7 @@ const padding = 1;
|
|
|
40
45
|
* data-driven support for `*-pattern`, we'll likely use per-bucket pattern atlases, and that would be a good time
|
|
41
46
|
* to refactor this.
|
|
42
47
|
*/
|
|
43
|
-
export class ImageManager extends Evented {
|
|
48
|
+
export class ImageManager extends Evented<ImageManagerEventType> {
|
|
44
49
|
images: {[_: string]: StyleImage};
|
|
45
50
|
updatedImages: {[_: string]: boolean};
|
|
46
51
|
callbackDispatchedThisFrame: {[_: string]: boolean};
|
|
@@ -131,6 +136,7 @@ export class ImageManager extends Evented {
|
|
|
131
136
|
if (this.images[id]) throw new Error(`Image id ${id} already exist, use updateImage instead`);
|
|
132
137
|
if (this._validate(id, image)) {
|
|
133
138
|
this.images[id] = image;
|
|
139
|
+
if (image.isWebGLImage) this.updateImage(id, image, false);
|
|
134
140
|
}
|
|
135
141
|
}
|
|
136
142
|
|
|
@@ -252,7 +258,8 @@ export class ImageManager extends Evented {
|
|
|
252
258
|
content: image.content,
|
|
253
259
|
textFitWidth: image.textFitWidth,
|
|
254
260
|
textFitHeight: image.textFitHeight,
|
|
255
|
-
hasRenderCallback: Boolean(image.userImage?.render)
|
|
261
|
+
hasRenderCallback: Boolean(image.userImage?.render),
|
|
262
|
+
isWebGLImage: image.isWebGLImage
|
|
256
263
|
};
|
|
257
264
|
}
|
|
258
265
|
}
|
package/src/render/painter.ts
CHANGED
|
@@ -857,18 +857,7 @@ export class Painter {
|
|
|
857
857
|
* in custom layers.
|
|
858
858
|
*/
|
|
859
859
|
setCustomLayerDefaults(): void {
|
|
860
|
-
|
|
861
|
-
// All other state is state is restored on it's own, but for VAOs it's
|
|
862
|
-
// simpler to unbind so that we don't have to track the state of VAOs.
|
|
863
|
-
this.context.unbindVAO();
|
|
864
|
-
|
|
865
|
-
// The default values for this state is meaningful and often expected.
|
|
866
|
-
// Leaving this state dirty could cause a lot of confusion for users.
|
|
867
|
-
this.context.cullFace.setDefault();
|
|
868
|
-
this.context.activeTexture.setDefault();
|
|
869
|
-
this.context.pixelStoreUnpack.setDefault();
|
|
870
|
-
this.context.pixelStoreUnpackPremultiplyAlpha.setDefault();
|
|
871
|
-
this.context.pixelStoreUnpackFlipY.setDefault();
|
|
860
|
+
this.context.setCustomLayerDefaults();
|
|
872
861
|
}
|
|
873
862
|
|
|
874
863
|
/*
|
|
@@ -52,7 +52,7 @@ describe('updatePatternPositionsInProgram', () => {
|
|
|
52
52
|
const tile = new Tile(new OverscaledTileID(3, 0, 2, 1, 2), undefined);
|
|
53
53
|
tile.imageAtlas = {} as any;
|
|
54
54
|
tile.imageAtlas.patternPositions = {
|
|
55
|
-
'volcano_11': {paddedRect: {x: 0, y: 0, w: 0, h: 0}, version: 0, tl: [0, 0], pixelRatio: 1, br: [0, 0], tlbr: [0, 0, 0, 0], displaySize: [0, 0], stretchX: [], stretchY: [], content: [0, 0, 0, 0], textFitWidth: undefined, textFitHeight: undefined},
|
|
55
|
+
'volcano_11': {paddedRect: {x: 0, y: 0, w: 0, h: 0}, version: 0, needsFirstWebGLRender: false, tl: [0, 0], pixelRatio: 1, br: [0, 0], tlbr: [0, 0, 0, 0], displaySize: [0, 0], stretchX: [], stretchY: [], content: [0, 0, 0, 0], textFitWidth: undefined, textFitHeight: undefined},
|
|
56
56
|
};
|
|
57
57
|
const crossFadeResolveImage: CrossFaded<ResolvedImage> = {
|
|
58
58
|
from: {name: 'zoo_11', available: false, toString: () => 'zoo_11'},
|
|
@@ -26,9 +26,8 @@ vec2 unpack_float(const float packedValue) {
|
|
|
26
26
|
return vec2(v0, packedIntValue - v0 * 256);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
vec2 unpack_opacity(const
|
|
30
|
-
|
|
31
|
-
return vec2(float(intOpacity) / 127.0, mod(packedOpacity, 2.0));
|
|
29
|
+
vec2 unpack_opacity(const uint packedOpacity) {
|
|
30
|
+
return vec2(float(packedOpacity >> 1u) / 127.0, float(packedOpacity & 1u));
|
|
32
31
|
}
|
|
33
32
|
|
|
34
33
|
// To minimize the number of ins needed, we encode a 4-component
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// This file is generated. Edit build/generate-shaders.ts, then run `npm run codegen`.
|
|
2
|
-
export default '#ifdef GL_ES\nprecision highp float;\n#else\n#if !defined(lowp)\n#define lowp\n#endif\n#if !defined(mediump)\n#define mediump\n#endif\n#if !defined(highp)\n#define highp\n#endif\n#endif\nvec2 unpack_float(const float packedValue) {int packedIntValue=int(packedValue);int v0=packedIntValue/256;return vec2(v0,packedIntValue-v0*256);}vec2 unpack_opacity(const
|
|
2
|
+
export default '#ifdef GL_ES\nprecision highp float;\n#else\n#if !defined(lowp)\n#define lowp\n#endif\n#if !defined(mediump)\n#define mediump\n#endif\n#if !defined(highp)\n#define highp\n#endif\n#endif\nvec2 unpack_float(const float packedValue) {int packedIntValue=int(packedValue);int v0=packedIntValue/256;return vec2(v0,packedIntValue-v0*256);}vec2 unpack_opacity(const uint packedOpacity) {return vec2(float(packedOpacity >> 1u)/127.0,float(packedOpacity & 1u));}vec4 decode_color(const vec2 encodedColor) {return vec4(unpack_float(encodedColor[0])/255.0,unpack_float(encodedColor[1])/255.0\n);}float unpack_mix_vec2(const vec2 packedValue,const float t) {return mix(packedValue[0],packedValue[1],t);}vec4 unpack_mix_color(const vec4 packedColors,const float t) {vec4 minColor=decode_color(vec2(packedColors[0],packedColors[1]));vec4 maxColor=decode_color(vec2(packedColors[2],packedColors[3]));return mix(minColor,maxColor,t);}vec2 get_pattern_pos(const vec2 pixel_coord_upper,const vec2 pixel_coord_lower,const vec2 pattern_size,const float tile_units_to_pixels,const vec2 pos) {vec2 offset=mod(mod(mod(pixel_coord_upper,pattern_size)*256.0,pattern_size)*256.0+pixel_coord_lower,pattern_size);return (tile_units_to_pixels*pos+offset)/pattern_size;}mat3 rotationMatrixFromAxisAngle(vec3 u,float angle) {float c=cos(angle);float s=sin(angle);float c2=1.0-c;return mat3(u.x*u.x*c2+ c,u.x*u.y*c2-u.z*s,u.x*u.z*c2+u.y*s,u.y*u.x*c2+u.z*s,u.y*u.y*c2+ c,u.y*u.z*c2-u.x*s,u.z*u.x*c2-u.y*s,u.z*u.y*c2+u.x*s,u.z*u.z*c2+ c\n);}\n#ifdef TERRAIN3D\nuniform sampler2D u_terrain;uniform float u_terrain_dim;uniform mat4 u_terrain_matrix;uniform vec4 u_terrain_unpack;uniform float u_terrain_exaggeration;uniform highp sampler2D u_depth;\n#endif\nconst highp vec4 bitSh=vec4(256.*256.*256.,256.*256.,256.,1.);const highp vec4 bitShifts=vec4(1.)/bitSh;highp float unpack(highp vec4 color) {return dot(color,bitShifts);}highp float depthOpacity(vec3 frag) {\n#ifdef TERRAIN3D\nhighp float d=unpack(texture(u_depth,frag.xy*0.5+0.5))+0.0001-frag.z;return 1.0-max(0.0,min(1.0,-d*500.0));\n#else\nreturn 1.0;\n#endif\n}float calculate_visibility(vec4 pos) {\n#ifdef TERRAIN3D\nvec3 frag=pos.xyz/pos.w;highp float d=depthOpacity(frag);if (d > 0.95) return 1.0;return (d+depthOpacity(frag+vec3(0.0,0.01,0.0)))/2.0;\n#else\nreturn 1.0;\n#endif\n}float ele(vec2 pos) {\n#ifdef TERRAIN3D\nvec4 rgb=(texture(u_terrain,pos)*255.0)*u_terrain_unpack;return rgb.r+rgb.g+rgb.b-u_terrain_unpack.a;\n#else\nreturn 0.0;\n#endif\n}float get_elevation(vec2 pos) {\n#ifdef TERRAIN3D\n#ifdef GLOBE\nif ((pos.y <-32767.5) || (pos.y > 32766.5)) {return 0.0;}\n#endif\nvec2 coord=(u_terrain_matrix*vec4(pos,0.0,1.0)).xy*u_terrain_dim+1.0;vec2 f=fract(coord);vec2 c=(floor(coord)+0.5)/(u_terrain_dim+2.0);float d=1.0/(u_terrain_dim+2.0);float tl=ele(c);float tr=ele(c+vec2(d,0.0));float bl=ele(c+vec2(0.0,d));float br=ele(c+vec2(d,d));float elevation=mix(mix(tl,tr,f.x),mix(bl,br,f.x),f.y);return elevation*u_terrain_exaggeration;\n#else\nreturn 0.0;\n#endif\n}const float PI=3.141592653589793;uniform mat4 u_projection_matrix;';
|
|
@@ -6,7 +6,7 @@ uniform lowp float u_device_pixel_ratio;
|
|
|
6
6
|
uniform highp float u_camera_to_center_distance;
|
|
7
7
|
uniform vec2 u_translate;
|
|
8
8
|
|
|
9
|
-
layout(location = 0) in
|
|
9
|
+
layout(location = 0) in ivec2 a_pos;
|
|
10
10
|
|
|
11
11
|
out vec3 v_data;
|
|
12
12
|
flat out float v_visibility;
|
|
@@ -29,12 +29,12 @@ void main(void) {
|
|
|
29
29
|
#pragma maplibre: initialize lowp float stroke_opacity
|
|
30
30
|
|
|
31
31
|
// decode the extrusion vector that we snuck into the a_pos vector
|
|
32
|
-
|
|
33
|
-
vec2 extrude = vec2(
|
|
32
|
+
ivec2 pos_raw = a_pos + 32768;
|
|
33
|
+
vec2 extrude = vec2(pos_raw & 7) / 7.0 * 2.0 - 1.0;
|
|
34
34
|
|
|
35
35
|
// Divide a_pos by 8, since we had it * 8 in order to sneak
|
|
36
36
|
// in extrusion data
|
|
37
|
-
vec2 circle_center =
|
|
37
|
+
vec2 circle_center = vec2(pos_raw >> 3) + u_translate;
|
|
38
38
|
float ele = get_elevation(circle_center);
|
|
39
39
|
v_visibility = calculate_visibility(projectTileWithElevation(circle_center, ele));
|
|
40
40
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// This file is generated. Edit build/generate-shaders.ts, then run `npm run codegen`.
|
|
2
|
-
export default 'uniform bool u_scale_with_map;uniform bool u_pitch_with_map;uniform vec2 u_extrude_scale;uniform highp float u_globe_extrude_scale;uniform lowp float u_device_pixel_ratio;uniform highp float u_camera_to_center_distance;uniform vec2 u_translate;layout(location=0) in
|
|
2
|
+
export default 'uniform bool u_scale_with_map;uniform bool u_pitch_with_map;uniform vec2 u_extrude_scale;uniform highp float u_globe_extrude_scale;uniform lowp float u_device_pixel_ratio;uniform highp float u_camera_to_center_distance;uniform vec2 u_translate;layout(location=0) in ivec2 a_pos;out vec3 v_data;flat out float v_visibility;\n#pragma maplibre: define highp vec4 color\n#pragma maplibre: define mediump float radius\n#pragma maplibre: define lowp float blur\n#pragma maplibre: define lowp float opacity\n#pragma maplibre: define highp vec4 stroke_color\n#pragma maplibre: define mediump float stroke_width\n#pragma maplibre: define lowp float stroke_opacity\nvoid main(void) {\n#pragma maplibre: initialize highp vec4 color\n#pragma maplibre: initialize mediump float radius\n#pragma maplibre: initialize lowp float blur\n#pragma maplibre: initialize lowp float opacity\n#pragma maplibre: initialize highp vec4 stroke_color\n#pragma maplibre: initialize mediump float stroke_width\n#pragma maplibre: initialize lowp float stroke_opacity\nivec2 pos_raw=a_pos+32768;vec2 extrude=vec2(pos_raw & 7)/7.0*2.0-1.0;vec2 circle_center=vec2(pos_raw >> 3)+u_translate;float ele=get_elevation(circle_center);v_visibility=calculate_visibility(projectTileWithElevation(circle_center,ele));if (u_pitch_with_map) {\n#ifdef GLOBE\nvec3 center_vector=projectToSphere(circle_center);\n#endif\nfloat angle_scale=u_globe_extrude_scale;vec2 corner_position=circle_center;if (u_scale_with_map) {angle_scale*=(radius+stroke_width);corner_position+=extrude*u_extrude_scale*(radius+stroke_width);} else {\n#ifdef GLOBE\nvec4 projected_center=interpolateProjection(circle_center,center_vector,ele);\n#else\nvec4 projected_center=projectTileWithElevation(circle_center,ele);\n#endif\ncorner_position+=extrude*u_extrude_scale*(radius+stroke_width)*(projected_center.w/u_camera_to_center_distance);angle_scale*=(radius+stroke_width)*(projected_center.w/u_camera_to_center_distance);}\n#ifdef GLOBE\nvec2 angles=extrude*angle_scale;vec3 corner_vector=globeRotateVector(center_vector,angles);gl_Position=interpolateProjection(corner_position,corner_vector,ele);\n#else\ngl_Position=projectTileWithElevation(corner_position,ele);\n#endif\n} else {gl_Position=projectTileWithElevation(circle_center,ele);if (gl_Position.z/gl_Position.w > 1.0) {gl_Position.xy=vec2(10000.0);}if (u_scale_with_map) {gl_Position.xy+=extrude*(radius+stroke_width)*u_extrude_scale*u_camera_to_center_distance;} else {gl_Position.xy+=extrude*(radius+stroke_width)*u_extrude_scale*gl_Position.w;}}float antialiasblur=-max(1.0/u_device_pixel_ratio/(radius+stroke_width),blur);v_data=vec3(extrude.x,extrude.y,antialiasblur);}';
|
|
@@ -7,7 +7,7 @@ uniform lowp float u_opacity;
|
|
|
7
7
|
uniform vec2 u_fill_translate;
|
|
8
8
|
|
|
9
9
|
layout(location = 0) in vec2 a_pos;
|
|
10
|
-
layout(location = 1) in
|
|
10
|
+
layout(location = 1) in ivec4 a_normal_ed;
|
|
11
11
|
|
|
12
12
|
#ifdef TERRAIN3D
|
|
13
13
|
layout(location = 2) in vec2 a_centroid;
|
|
@@ -26,7 +26,7 @@ void main() {
|
|
|
26
26
|
#pragma maplibre: initialize highp float height
|
|
27
27
|
#pragma maplibre: initialize highp vec4 color
|
|
28
28
|
|
|
29
|
-
vec3 normal = a_normal_ed.xyz;
|
|
29
|
+
vec3 normal = vec3(a_normal_ed.xyz);
|
|
30
30
|
|
|
31
31
|
#ifdef TERRAIN3D
|
|
32
32
|
// Raise the "ceiling" of elements by the elevation of the centroid, in meters.
|
|
@@ -44,7 +44,7 @@ void main() {
|
|
|
44
44
|
base = max(0.0, base) + base_terrain3d_offset;
|
|
45
45
|
height = max(0.0, height) + height_terrain3d_offset;
|
|
46
46
|
|
|
47
|
-
float t =
|
|
47
|
+
float t = float(a_normal_ed.x & 1);
|
|
48
48
|
float elevation = t > 0.0 ? height : base;
|
|
49
49
|
vec2 posInTile = a_pos + u_fill_translate;
|
|
50
50
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// This file is generated. Edit build/generate-shaders.ts, then run `npm run codegen`.
|
|
2
|
-
export default 'uniform vec3 u_lightcolor;uniform lowp vec3 u_lightpos;uniform lowp vec3 u_lightpos_globe;uniform lowp float u_lightintensity;uniform float u_vertical_gradient;uniform lowp float u_opacity;uniform vec2 u_fill_translate;layout(location=0) in vec2 a_pos;layout(location=1) in
|
|
2
|
+
export default 'uniform vec3 u_lightcolor;uniform lowp vec3 u_lightpos;uniform lowp vec3 u_lightpos_globe;uniform lowp float u_lightintensity;uniform float u_vertical_gradient;uniform lowp float u_opacity;uniform vec2 u_fill_translate;layout(location=0) in vec2 a_pos;layout(location=1) in ivec4 a_normal_ed;\n#ifdef TERRAIN3D\nlayout(location=2) in vec2 a_centroid;\n#endif\nout vec4 v_color;\n#pragma maplibre: define highp float base\n#pragma maplibre: define highp float height\n#pragma maplibre: define highp vec4 color\nvoid main() {\n#pragma maplibre: initialize highp float base\n#pragma maplibre: initialize highp float height\n#pragma maplibre: initialize highp vec4 color\nvec3 normal=vec3(a_normal_ed.xyz);\n#ifdef TERRAIN3D\nfloat height_terrain3d_offset=get_elevation(a_centroid);float base_terrain3d_offset=height_terrain3d_offset-(base > 0.0 ? 0.0 : 10.0);\n#else\nfloat height_terrain3d_offset=0.0;float base_terrain3d_offset=0.0;\n#endif\nbase=max(0.0,base)+base_terrain3d_offset;height=max(0.0,height)+height_terrain3d_offset;float t=float(a_normal_ed.x & 1);float elevation=t > 0.0 ? height : base;vec2 posInTile=a_pos+u_fill_translate;\n#ifdef GLOBE\nvec3 spherePos=projectToSphere(posInTile,a_pos);gl_Position=interpolateProjectionFor3D(posInTile,spherePos,elevation);\n#else\ngl_Position=u_projection_matrix*vec4(posInTile,elevation,1.0);\n#endif\nfloat colorvalue=color.r*0.2126+color.g*0.7152+color.b*0.0722;v_color=vec4(0.0,0.0,0.0,1.0);vec4 ambientlight=vec4(0.03,0.03,0.03,1.0);color+=ambientlight;vec3 normalForLighting=normal/16384.0;float directional=clamp(dot(normalForLighting,u_lightpos),0.0,1.0);\n#ifdef GLOBE\nmat3 rotMatrix=globeGetRotationMatrix(spherePos);normalForLighting=rotMatrix*normalForLighting;directional=mix(directional,clamp(dot(normalForLighting,u_lightpos_globe),0.0,1.0),u_projection_transition);\n#endif\ndirectional=mix((1.0-u_lightintensity),max((1.0-colorvalue+u_lightintensity),1.0),directional);if (normal.y !=0.0) {directional*=((1.0-u_vertical_gradient)+(u_vertical_gradient*clamp((t+base)*pow(height/150.0,0.5),mix(0.7,0.98,1.0-u_lightintensity),1.0)));}v_color.r+=clamp(color.r*directional*u_lightcolor.r,mix(0.0,0.3,1.0-u_lightcolor.r),1.0);v_color.g+=clamp(color.g*directional*u_lightcolor.g,mix(0.0,0.3,1.0-u_lightcolor.g),1.0);v_color.b+=clamp(color.b*directional*u_lightcolor.b,mix(0.0,0.3,1.0-u_lightcolor.b),1.0);v_color*=u_opacity;}';
|
|
@@ -12,7 +12,7 @@ uniform lowp vec3 u_lightpos_globe;
|
|
|
12
12
|
uniform lowp float u_lightintensity;
|
|
13
13
|
|
|
14
14
|
layout(location = 0) in vec2 a_pos;
|
|
15
|
-
layout(location = 1) in
|
|
15
|
+
layout(location = 1) in ivec4 a_normal_ed;
|
|
16
16
|
|
|
17
17
|
#ifdef TERRAIN3D
|
|
18
18
|
layout(location = 2) in vec2 a_centroid;
|
|
@@ -50,8 +50,8 @@ void main() {
|
|
|
50
50
|
float fromScale = u_scale.y;
|
|
51
51
|
float toScale = u_scale.z;
|
|
52
52
|
|
|
53
|
-
vec3 normal = a_normal_ed.xyz;
|
|
54
|
-
float edgedistance = a_normal_ed.w;
|
|
53
|
+
vec3 normal = vec3(a_normal_ed.xyz);
|
|
54
|
+
float edgedistance = float(a_normal_ed.w);
|
|
55
55
|
|
|
56
56
|
vec2 display_size_a = (pattern_br_a - pattern_tl_a) / pixel_ratio_from;
|
|
57
57
|
vec2 display_size_b = (pattern_br_b - pattern_tl_b) / pixel_ratio_to;
|
|
@@ -72,7 +72,7 @@ void main() {
|
|
|
72
72
|
base = max(0.0, base) + base_terrain3d_offset;
|
|
73
73
|
height = max(0.0, height) + height_terrain3d_offset;
|
|
74
74
|
|
|
75
|
-
float t =
|
|
75
|
+
float t = float(a_normal_ed.x & 1);
|
|
76
76
|
float elevation = t > 0.0 ? height : base;
|
|
77
77
|
vec2 posInTile = a_pos + u_fill_translate;
|
|
78
78
|
|
|
@@ -85,7 +85,7 @@ void main() {
|
|
|
85
85
|
gl_Position = u_projection_matrix * vec4(posInTile, elevation, 1.0);
|
|
86
86
|
#endif
|
|
87
87
|
|
|
88
|
-
vec2 pos =
|
|
88
|
+
vec2 pos = a_normal_ed.x == 1 && a_normal_ed.y == 0 && a_normal_ed.z == 16384
|
|
89
89
|
? a_pos // extrusion top - note the lack of u_fill_translate, because translation should not affect the pattern
|
|
90
90
|
: vec2(edgedistance, elevation * u_height_factor); // extrusion side
|
|
91
91
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// This file is generated. Edit build/generate-shaders.ts, then run `npm run codegen`.
|
|
2
|
-
export default 'uniform vec2 u_pixel_coord_upper;uniform vec2 u_pixel_coord_lower;uniform float u_height_factor;uniform vec3 u_scale;uniform float u_vertical_gradient;uniform lowp float u_opacity;uniform vec2 u_fill_translate;uniform vec3 u_lightcolor;uniform lowp vec3 u_lightpos;uniform lowp vec3 u_lightpos_globe;uniform lowp float u_lightintensity;layout(location=0) in vec2 a_pos;layout(location=1) in
|
|
2
|
+
export default 'uniform vec2 u_pixel_coord_upper;uniform vec2 u_pixel_coord_lower;uniform float u_height_factor;uniform vec3 u_scale;uniform float u_vertical_gradient;uniform lowp float u_opacity;uniform vec2 u_fill_translate;uniform vec3 u_lightcolor;uniform lowp vec3 u_lightpos;uniform lowp vec3 u_lightpos_globe;uniform lowp float u_lightintensity;layout(location=0) in vec2 a_pos;layout(location=1) in ivec4 a_normal_ed;\n#ifdef TERRAIN3D\nlayout(location=2) in vec2 a_centroid;\n#endif\n#ifdef GLOBE\nout vec3 v_sphere_pos;\n#endif\nout vec2 v_pos_a;out vec2 v_pos_b;out vec4 v_lighting;\n#pragma maplibre: define lowp float base\n#pragma maplibre: define lowp float height\n#pragma maplibre: define lowp vec4 pattern_from\n#pragma maplibre: define lowp vec4 pattern_to\n#pragma maplibre: define lowp float pixel_ratio_from\n#pragma maplibre: define lowp float pixel_ratio_to\nvoid main() {\n#pragma maplibre: initialize lowp float base\n#pragma maplibre: initialize lowp float height\n#pragma maplibre: initialize mediump vec4 pattern_from\n#pragma maplibre: initialize mediump vec4 pattern_to\n#pragma maplibre: initialize lowp float pixel_ratio_from\n#pragma maplibre: initialize lowp float pixel_ratio_to\nvec2 pattern_tl_a=pattern_from.xy;vec2 pattern_br_a=pattern_from.zw;vec2 pattern_tl_b=pattern_to.xy;vec2 pattern_br_b=pattern_to.zw;float tileRatio=u_scale.x;float fromScale=u_scale.y;float toScale=u_scale.z;vec3 normal=vec3(a_normal_ed.xyz);float edgedistance=float(a_normal_ed.w);vec2 display_size_a=(pattern_br_a-pattern_tl_a)/pixel_ratio_from;vec2 display_size_b=(pattern_br_b-pattern_tl_b)/pixel_ratio_to;\n#ifdef TERRAIN3D\nfloat height_terrain3d_offset=get_elevation(a_centroid);float base_terrain3d_offset=height_terrain3d_offset-(base > 0.0 ? 0.0 : 10.0);\n#else\nfloat height_terrain3d_offset=0.0;float base_terrain3d_offset=0.0;\n#endif\nbase=max(0.0,base)+base_terrain3d_offset;height=max(0.0,height)+height_terrain3d_offset;float t=float(a_normal_ed.x & 1);float elevation=t > 0.0 ? height : base;vec2 posInTile=a_pos+u_fill_translate;\n#ifdef GLOBE\nvec3 spherePos=projectToSphere(posInTile,a_pos);vec3 elevatedPos=spherePos*(1.0+elevation/GLOBE_RADIUS);v_sphere_pos=elevatedPos;gl_Position=interpolateProjectionFor3D(posInTile,spherePos,elevation);\n#else\ngl_Position=u_projection_matrix*vec4(posInTile,elevation,1.0);\n#endif\nvec2 pos=a_normal_ed.x==1 && a_normal_ed.y==0 && a_normal_ed.z==16384\n? a_pos\n: vec2(edgedistance,elevation*u_height_factor);v_pos_a=get_pattern_pos(u_pixel_coord_upper,u_pixel_coord_lower,fromScale*display_size_a,tileRatio,pos);v_pos_b=get_pattern_pos(u_pixel_coord_upper,u_pixel_coord_lower,toScale*display_size_b,tileRatio,pos);v_lighting=vec4(0.0,0.0,0.0,1.0);float directional=clamp(dot(normal/16383.0,u_lightpos),0.0,1.0);directional=mix((1.0-u_lightintensity),max((0.5+u_lightintensity),1.0),directional);if (normal.y !=0.0) {directional*=((1.0-u_vertical_gradient)+(u_vertical_gradient*clamp((t+base)*pow(height/150.0,0.5),mix(0.7,0.98,1.0-u_lightintensity),1.0)));}v_lighting.rgb+=clamp(directional*u_lightcolor,mix(vec3(0.0),vec3(0.3),1.0-u_lightcolor),vec3(1.0));v_lighting*=u_opacity;}';
|
|
@@ -4,7 +4,7 @@ uniform float u_opacity;
|
|
|
4
4
|
uniform float u_intensity;
|
|
5
5
|
uniform highp float u_globe_extrude_scale;
|
|
6
6
|
|
|
7
|
-
layout(location = 0) in
|
|
7
|
+
layout(location = 0) in ivec2 a_pos;
|
|
8
8
|
|
|
9
9
|
out vec2 v_extrude;
|
|
10
10
|
|
|
@@ -24,8 +24,8 @@ void main(void) {
|
|
|
24
24
|
#pragma maplibre: initialize mediump float radius
|
|
25
25
|
|
|
26
26
|
// decode the extrusion vector that we snuck into the a_pos vector
|
|
27
|
-
|
|
28
|
-
vec2 unscaled_extrude = vec2(
|
|
27
|
+
ivec2 pos_raw = a_pos + 32768;
|
|
28
|
+
vec2 unscaled_extrude = vec2(pos_raw & 7) / 7.0 * 2.0 - 1.0;
|
|
29
29
|
|
|
30
30
|
// This 'extrude' comes in ranging from [-1, -1], to [1, 1]. We'll use
|
|
31
31
|
// it to produce the vertices of a square mesh framing the point feature
|
|
@@ -49,7 +49,7 @@ void main(void) {
|
|
|
49
49
|
|
|
50
50
|
// Divide a_pos by 8, since we had it * 8 in order to sneak
|
|
51
51
|
// in extrusion data
|
|
52
|
-
vec2 circle_center =
|
|
52
|
+
vec2 circle_center = vec2(pos_raw >> 3);
|
|
53
53
|
|
|
54
54
|
#ifdef GLOBE
|
|
55
55
|
vec2 angles = v_extrude * radius * u_globe_extrude_scale;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// This file is generated. Edit build/generate-shaders.ts, then run `npm run codegen`.
|
|
2
|
-
export default 'uniform float u_extrude_scale;uniform float u_opacity;uniform float u_intensity;uniform highp float u_globe_extrude_scale;layout(location=0) in
|
|
2
|
+
export default 'uniform float u_extrude_scale;uniform float u_opacity;uniform float u_intensity;uniform highp float u_globe_extrude_scale;layout(location=0) in ivec2 a_pos;out vec2 v_extrude;\n#pragma maplibre: define highp float weight\n#pragma maplibre: define mediump float radius\nconst highp float ZERO=1.0/255.0/16.0;\n#define GAUSS_COEF 0.3989422804014327\nvoid main(void) {\n#pragma maplibre: initialize highp float weight\n#pragma maplibre: initialize mediump float radius\nivec2 pos_raw=a_pos+32768;vec2 unscaled_extrude=vec2(pos_raw & 7)/7.0*2.0-1.0;float S=sqrt(-2.0*log(ZERO/weight/u_intensity/GAUSS_COEF))/3.0;v_extrude=S*unscaled_extrude;vec2 extrude=v_extrude*radius*u_extrude_scale;vec2 circle_center=vec2(pos_raw >> 3);\n#ifdef GLOBE\nvec2 angles=v_extrude*radius*u_globe_extrude_scale;vec3 center_vector=projectToSphere(circle_center);vec3 corner_vector=globeRotateVector(center_vector,angles);gl_Position=interpolateProjection(circle_center+extrude,corner_vector,0.0);\n#else\ngl_Position=projectTileFor3D(circle_center+extrude,get_elevation(circle_center));\n#endif\n}';
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
// #define scale 63.0
|
|
7
7
|
#define scale 0.015873016
|
|
8
8
|
|
|
9
|
-
layout(location = 0) in
|
|
10
|
-
layout(location = 1) in
|
|
9
|
+
layout(location = 0) in ivec2 a_pos_normal;
|
|
10
|
+
layout(location = 1) in uvec4 a_data;
|
|
11
11
|
|
|
12
12
|
uniform vec2 u_translation;
|
|
13
13
|
uniform mediump float u_ratio;
|
|
@@ -47,17 +47,17 @@ void main() {
|
|
|
47
47
|
// Retina devices need a smaller distance to avoid aliasing.
|
|
48
48
|
float ANTIALIASING = 1.0 / u_device_pixel_ratio / 2.0;
|
|
49
49
|
|
|
50
|
-
vec2 a_extrude = a_data.xy - 128
|
|
51
|
-
float a_direction =
|
|
50
|
+
vec2 a_extrude = vec2(ivec2(a_data.xy) - 128);
|
|
51
|
+
float a_direction = float(int(a_data.z & 3u) - 1);
|
|
52
52
|
|
|
53
|
-
v_linesofar = (
|
|
53
|
+
v_linesofar = float((a_data.z >> 2u) + a_data.w * 64u) * 2.0;
|
|
54
54
|
|
|
55
|
-
vec2 pos =
|
|
55
|
+
vec2 pos = vec2(a_pos_normal >> 1);
|
|
56
56
|
|
|
57
57
|
// x is 1 if it's a round cap, 0 otherwise
|
|
58
58
|
// y is 1 if the normal points up, and -1 if it points down
|
|
59
59
|
// We store these in the least significant bit of a_pos_normal
|
|
60
|
-
mediump vec2 normal = a_pos_normal
|
|
60
|
+
mediump vec2 normal = vec2(a_pos_normal & 1);
|
|
61
61
|
normal.y = normal.y * 2.0 - 1.0;
|
|
62
62
|
v_normal = normal;
|
|
63
63
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// This file is generated. Edit build/generate-shaders.ts, then run `npm run codegen`.
|
|
2
|
-
export default '\n#define scale 0.015873016\nlayout(location=0) in
|
|
2
|
+
export default '\n#define scale 0.015873016\nlayout(location=0) in ivec2 a_pos_normal;layout(location=1) in uvec4 a_data;uniform vec2 u_translation;uniform mediump float u_ratio;uniform vec2 u_units_to_pixels;uniform lowp float u_device_pixel_ratio;out vec2 v_normal;flat out vec2 v_width2;out float v_gamma_scale;out highp float v_linesofar;\n#ifdef GLOBE\nout float v_depth;\n#endif\n#pragma maplibre: define highp vec4 color\n#pragma maplibre: define lowp float blur\n#pragma maplibre: define lowp float opacity\n#pragma maplibre: define mediump float gapwidth\n#pragma maplibre: define lowp float offset\n#pragma maplibre: define mediump float width\nvoid main() {\n#pragma maplibre: initialize highp vec4 color\n#pragma maplibre: initialize lowp float blur\n#pragma maplibre: initialize lowp float opacity\n#pragma maplibre: initialize mediump float gapwidth\n#pragma maplibre: initialize lowp float offset\n#pragma maplibre: initialize mediump float width\nif (opacity < 0.01) {gl_Position=vec4(-2.0,-2.0,-2.0,1.0);return;}float ANTIALIASING=1.0/u_device_pixel_ratio/2.0;vec2 a_extrude=vec2(ivec2(a_data.xy)-128);float a_direction=float(int(a_data.z & 3u)-1);v_linesofar=float((a_data.z >> 2u)+a_data.w*64u)*2.0;vec2 pos=vec2(a_pos_normal >> 1);mediump vec2 normal=vec2(a_pos_normal & 1);normal.y=normal.y*2.0-1.0;v_normal=normal;gapwidth=gapwidth/2.0;float halfwidth=width/2.0;offset=-1.0*offset;float inset=gapwidth+(gapwidth > 0.0 ? ANTIALIASING : 0.0);float outset=gapwidth+halfwidth*(gapwidth > 0.0 ? 2.0 : 1.0)+(halfwidth==0.0 ? 0.0 : ANTIALIASING);mediump vec2 dist=outset*a_extrude*scale;mediump float u=0.5*a_direction;mediump float t=1.0-abs(u);mediump vec2 offset2=offset*a_extrude*scale*normal.y*mat2(t,-u,u,t);float adjustedThickness=projectLineThickness(pos.y);vec4 projected_no_extrude=projectTile(pos+offset2/u_ratio*adjustedThickness+u_translation);vec4 projected_with_extrude=projectTile(pos+offset2/u_ratio*adjustedThickness+u_translation+dist/u_ratio*adjustedThickness);gl_Position=projected_with_extrude;\n#ifdef GLOBE\nv_depth=gl_Position.z/gl_Position.w;\n#endif\n#ifdef TERRAIN3D\nv_gamma_scale=1.0;\n#else\nfloat extrude_length_without_perspective=length(dist);float extrude_length_with_perspective=length((projected_with_extrude.xy-projected_no_extrude.xy)/projected_with_extrude.w*u_units_to_pixels);v_gamma_scale=extrude_length_without_perspective/extrude_length_with_perspective;\n#endif\nv_width2=vec2(outset,inset);}';
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
// #define scale 63.0
|
|
7
7
|
#define scale 0.015873016
|
|
8
8
|
|
|
9
|
-
layout(location = 0) in
|
|
10
|
-
layout(location = 1) in
|
|
9
|
+
layout(location = 0) in ivec2 a_pos_normal;
|
|
10
|
+
layout(location = 1) in uvec4 a_data;
|
|
11
11
|
layout(location = 2) in float a_uv_x;
|
|
12
12
|
layout(location = 3) in float a_split_index;
|
|
13
13
|
|
|
@@ -48,19 +48,19 @@ void main() {
|
|
|
48
48
|
// Retina devices need a smaller distance to avoid aliasing.
|
|
49
49
|
float ANTIALIASING = 1.0 / u_device_pixel_ratio / 2.0;
|
|
50
50
|
|
|
51
|
-
vec2 a_extrude = a_data.xy - 128
|
|
52
|
-
float a_direction =
|
|
51
|
+
vec2 a_extrude = vec2(ivec2(a_data.xy) - 128);
|
|
52
|
+
float a_direction = float(int(a_data.z & 3u) - 1);
|
|
53
53
|
|
|
54
54
|
highp float texel_height = 1.0 / u_image_height;
|
|
55
55
|
highp float half_texel_height = 0.5 * texel_height;
|
|
56
56
|
v_uv = vec2(a_uv_x, a_split_index * texel_height - half_texel_height);
|
|
57
57
|
|
|
58
|
-
vec2 pos =
|
|
58
|
+
vec2 pos = vec2(a_pos_normal >> 1);
|
|
59
59
|
|
|
60
60
|
// x is 1 if it's a round cap, 0 otherwise
|
|
61
61
|
// y is 1 if the normal points up, and -1 if it points down
|
|
62
62
|
// We store these in the least significant bit of a_pos_normal
|
|
63
|
-
mediump vec2 normal = a_pos_normal
|
|
63
|
+
mediump vec2 normal = vec2(a_pos_normal & 1);
|
|
64
64
|
normal.y = normal.y * 2.0 - 1.0;
|
|
65
65
|
v_normal = normal;
|
|
66
66
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// This file is generated. Edit build/generate-shaders.ts, then run `npm run codegen`.
|
|
2
|
-
export default '\n#define scale 0.015873016\nlayout(location=0) in
|
|
2
|
+
export default '\n#define scale 0.015873016\nlayout(location=0) in ivec2 a_pos_normal;layout(location=1) in uvec4 a_data;layout(location=2) in float a_uv_x;layout(location=3) in float a_split_index;uniform vec2 u_translation;uniform mediump float u_ratio;uniform lowp float u_device_pixel_ratio;uniform vec2 u_units_to_pixels;uniform float u_image_height;out vec2 v_normal;flat out vec2 v_width2;out float v_gamma_scale;out highp vec2 v_uv;\n#ifdef GLOBE\nout float v_depth;\n#endif\n#pragma maplibre: define lowp float blur\n#pragma maplibre: define lowp float opacity\n#pragma maplibre: define mediump float gapwidth\n#pragma maplibre: define lowp float offset\n#pragma maplibre: define mediump float width\nvoid main() {\n#pragma maplibre: initialize lowp float blur\n#pragma maplibre: initialize lowp float opacity\n#pragma maplibre: initialize mediump float gapwidth\n#pragma maplibre: initialize lowp float offset\n#pragma maplibre: initialize mediump float width\nif (opacity < 0.01) {gl_Position=vec4(-2.0,-2.0,-2.0,1.0);return;}float ANTIALIASING=1.0/u_device_pixel_ratio/2.0;vec2 a_extrude=vec2(ivec2(a_data.xy)-128);float a_direction=float(int(a_data.z & 3u)-1);highp float texel_height=1.0/u_image_height;highp float half_texel_height=0.5*texel_height;v_uv=vec2(a_uv_x,a_split_index*texel_height-half_texel_height);vec2 pos=vec2(a_pos_normal >> 1);mediump vec2 normal=vec2(a_pos_normal & 1);normal.y=normal.y*2.0-1.0;v_normal=normal;gapwidth=gapwidth/2.0;float halfwidth=width/2.0;offset=-1.0*offset;float inset=gapwidth+(gapwidth > 0.0 ? ANTIALIASING : 0.0);float outset=gapwidth+halfwidth*(gapwidth > 0.0 ? 2.0 : 1.0)+(halfwidth==0.0 ? 0.0 : ANTIALIASING);mediump vec2 dist=outset*a_extrude*scale;mediump float u=0.5*a_direction;mediump float t=1.0-abs(u);mediump vec2 offset2=offset*a_extrude*scale*normal.y*mat2(t,-u,u,t);float adjustedThickness=projectLineThickness(pos.y);vec4 projected_no_extrude=projectTile(pos+offset2/u_ratio*adjustedThickness+u_translation);vec4 projected_with_extrude=projectTile(pos+offset2/u_ratio*adjustedThickness+u_translation+dist/u_ratio*adjustedThickness);gl_Position=projected_with_extrude;\n#ifdef GLOBE\nv_depth=gl_Position.z/gl_Position.w;\n#endif\n#ifdef TERRAIN3D\nv_gamma_scale=1.0;\n#else\nfloat extrude_length_without_perspective=length(dist);float extrude_length_with_perspective=length((projected_with_extrude.xy-projected_no_extrude.xy)/projected_with_extrude.w*u_units_to_pixels);v_gamma_scale=extrude_length_without_perspective/extrude_length_with_perspective;\n#endif\nv_width2=vec2(outset,inset);}';
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
// long distances for long segments. Use this value to unscale the distance.
|
|
11
11
|
#define LINE_DISTANCE_SCALE 2.0
|
|
12
12
|
|
|
13
|
-
layout(location = 0) in
|
|
14
|
-
layout(location = 1) in
|
|
13
|
+
layout(location = 0) in ivec2 a_pos_normal;
|
|
14
|
+
layout(location = 1) in uvec4 a_data;
|
|
15
15
|
layout(location = 2) in float a_uv_x;
|
|
16
16
|
layout(location = 3) in float a_split_index;
|
|
17
17
|
|
|
@@ -64,21 +64,21 @@ void main() {
|
|
|
64
64
|
// Retina devices need a smaller distance to avoid aliasing.
|
|
65
65
|
float ANTIALIASING = 1.0 / u_device_pixel_ratio / 2.0;
|
|
66
66
|
|
|
67
|
-
vec2 a_extrude = a_data.xy - 128
|
|
68
|
-
float a_direction =
|
|
69
|
-
float a_linesofar = (
|
|
67
|
+
vec2 a_extrude = vec2(ivec2(a_data.xy) - 128);
|
|
68
|
+
float a_direction = float(int(a_data.z & 3u) - 1);
|
|
69
|
+
float a_linesofar = float((a_data.z >> 2u) + a_data.w * 64u) * LINE_DISTANCE_SCALE;
|
|
70
70
|
|
|
71
71
|
// Gradient UV computation
|
|
72
72
|
float texel_height = 1.0 / u_image_height;
|
|
73
73
|
float half_texel_height = 0.5 * texel_height;
|
|
74
74
|
v_uv = vec2(a_uv_x, a_split_index * texel_height - half_texel_height);
|
|
75
75
|
|
|
76
|
-
vec2 pos =
|
|
76
|
+
vec2 pos = vec2(a_pos_normal >> 1);
|
|
77
77
|
|
|
78
78
|
// x is 1 if it's a round cap, 0 otherwise
|
|
79
79
|
// y is 1 if the normal points up, and -1 if it points down
|
|
80
80
|
// We store these in the least significant bit of a_pos_normal
|
|
81
|
-
mediump vec2 normal = a_pos_normal
|
|
81
|
+
mediump vec2 normal = vec2(a_pos_normal & 1);
|
|
82
82
|
normal.y = normal.y * 2.0 - 1.0;
|
|
83
83
|
v_normal = normal;
|
|
84
84
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// This file is generated. Edit build/generate-shaders.ts, then run `npm run codegen`.
|
|
2
|
-
export default '\n#define scale 0.015873016\n#define LINE_DISTANCE_SCALE 2.0\nlayout(location=0) in
|
|
2
|
+
export default '\n#define scale 0.015873016\n#define LINE_DISTANCE_SCALE 2.0\nlayout(location=0) in ivec2 a_pos_normal;layout(location=1) in uvec4 a_data;layout(location=2) in float a_uv_x;layout(location=3) in float a_split_index;uniform vec2 u_translation;uniform mediump float u_ratio;uniform lowp float u_device_pixel_ratio;uniform vec2 u_units_to_pixels;uniform float u_image_height;uniform float u_tileratio;uniform float u_crossfade_from;uniform float u_crossfade_to;uniform float u_lineatlas_height;out vec2 v_normal;flat out vec2 v_width2;out float v_gamma_scale;out highp vec2 v_uv;out vec2 v_tex_a;out vec2 v_tex_b;\n#ifdef GLOBE\nout float v_depth;\n#endif\n#pragma maplibre: define lowp float blur\n#pragma maplibre: define lowp float opacity\n#pragma maplibre: define mediump float gapwidth\n#pragma maplibre: define lowp float offset\n#pragma maplibre: define mediump float width\n#pragma maplibre: define lowp float floorwidth\n#pragma maplibre: define mediump vec4 dasharray_from\n#pragma maplibre: define mediump vec4 dasharray_to\nvoid main() {\n#pragma maplibre: initialize lowp float blur\n#pragma maplibre: initialize lowp float opacity\n#pragma maplibre: initialize mediump float gapwidth\n#pragma maplibre: initialize lowp float offset\n#pragma maplibre: initialize mediump float width\n#pragma maplibre: initialize lowp float floorwidth\n#pragma maplibre: initialize mediump vec4 dasharray_from\n#pragma maplibre: initialize mediump vec4 dasharray_to\nif (opacity < 0.01) {gl_Position=vec4(-2.0,-2.0,-2.0,1.0);return;}float ANTIALIASING=1.0/u_device_pixel_ratio/2.0;vec2 a_extrude=vec2(ivec2(a_data.xy)-128);float a_direction=float(int(a_data.z & 3u)-1);float a_linesofar=float((a_data.z >> 2u)+a_data.w*64u)*LINE_DISTANCE_SCALE;float texel_height=1.0/u_image_height;float half_texel_height=0.5*texel_height;v_uv=vec2(a_uv_x,a_split_index*texel_height-half_texel_height);vec2 pos=vec2(a_pos_normal >> 1);mediump vec2 normal=vec2(a_pos_normal & 1);normal.y=normal.y*2.0-1.0;v_normal=normal;gapwidth=gapwidth/2.0;float halfwidth=width/2.0;offset=-1.0*offset;float inset=gapwidth+(gapwidth > 0.0 ? ANTIALIASING : 0.0);float outset=gapwidth+halfwidth*(gapwidth > 0.0 ? 2.0 : 1.0)+(halfwidth==0.0 ? 0.0 : ANTIALIASING);mediump vec2 dist=outset*a_extrude*scale;mediump float u=0.5*a_direction;mediump float t=1.0-abs(u);mediump vec2 offset2=offset*a_extrude*scale*normal.y*mat2(t,-u,u,t);float adjustedThickness=projectLineThickness(pos.y);vec4 projected_no_extrude=projectTile(pos+offset2/u_ratio*adjustedThickness+u_translation);vec4 projected_with_extrude=projectTile(pos+offset2/u_ratio*adjustedThickness+u_translation+dist/u_ratio*adjustedThickness);gl_Position=projected_with_extrude;\n#ifdef GLOBE\nv_depth=gl_Position.z/gl_Position.w;\n#endif\n#ifdef TERRAIN3D\nv_gamma_scale=1.0;\n#else\nfloat extrude_length_without_perspective=length(dist);float extrude_length_with_perspective=length((projected_with_extrude.xy-projected_no_extrude.xy)/projected_with_extrude.w*u_units_to_pixels);v_gamma_scale=extrude_length_without_perspective/extrude_length_with_perspective;\n#endif\nfloat u_patternscale_a_x=u_tileratio/dasharray_from.w/u_crossfade_from;float u_patternscale_a_y=-dasharray_from.z/2.0/u_lineatlas_height;float u_patternscale_b_x=u_tileratio/dasharray_to.w/u_crossfade_to;float u_patternscale_b_y=-dasharray_to.z/2.0/u_lineatlas_height;v_tex_a=vec2(a_linesofar*u_patternscale_a_x/floorwidth,normal.y*u_patternscale_a_y+(float(dasharray_from.y)+0.5)/u_lineatlas_height);v_tex_b=vec2(a_linesofar*u_patternscale_b_x/floorwidth,normal.y*u_patternscale_b_y+(float(dasharray_to.y)+0.5)/u_lineatlas_height);v_width2=vec2(outset,inset);}';
|