@antv/l7-layers 2.22.5 → 2.22.7
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/es/core/BaseLayer.d.ts +19 -0
- package/es/core/BaseLayer.js +56 -0
- package/es/core/interface.d.ts +4 -3
- package/es/earth/models/atmosphere.js +1 -1
- package/es/earth/models/base.js +1 -1
- package/es/earth/models/bloomsphere.js +1 -1
- package/es/earth/shaders/atmosphere/atmosphere_frag.glsl +6 -9
- package/es/earth/shaders/base/base_frag.glsl +3 -3
- package/es/earth/shaders/bloomshpere/bloomsphere_frag.glsl +5 -6
- package/es/geometry/models/billboard.js +1 -1
- package/es/geometry/models/sprite.js +1 -1
- package/es/geometry/shaders/billboard_frag.glsl +4 -4
- package/es/geometry/shaders/sprite_frag.glsl +2 -4
- package/es/heatmap/models/heatmap.js +3 -3
- package/es/heatmap/shaders/heatmap/heatmap_3d_frag.glsl +6 -7
- package/es/heatmap/shaders/heatmap/heatmap_frag.glsl +24 -36
- package/es/heatmap/shaders/heatmap/heatmap_framebuffer_frag.glsl +5 -5
- package/es/line/models/flow.js +1 -1
- package/es/line/shaders/flow/flow_line_frag.glsl +0 -1
- package/es/plugins/LayerMaskPlugin.js +1 -1
- package/es/plugins/ShaderUniformPlugin.js +26 -8
- package/es/point/models/billboard_point.js +1 -1
- package/es/point/models/extrude.js +1 -1
- package/es/point/models/fill.js +1 -1
- package/es/point/models/image.js +1 -1
- package/es/point/models/normal.js +1 -1
- package/es/point/shaders/billboard/billboard_point_frag.glsl +6 -8
- package/es/point/shaders/extrude/extrude_frag.glsl +1 -3
- package/es/point/shaders/fill/fill_frag.glsl +14 -17
- package/es/point/shaders/image/image_frag.glsl +15 -12
- package/es/point/shaders/normal/normal_frag.glsl +1 -1
- package/es/polygon/models/extrude.js +3 -3
- package/es/polygon/models/extrusion.js +1 -1
- package/es/polygon/models/fill.js +1 -1
- package/es/polygon/models/ocean.js +1 -1
- package/es/polygon/models/water.js +1 -1
- package/es/polygon/shaders/extrude/polygon_extrude_frag.glsl +5 -6
- package/es/polygon/shaders/extrude/polygon_extrude_picklight_frag.glsl +7 -8
- package/es/polygon/shaders/extrude/polygon_extrudetex_frag.glsl +4 -3
- package/es/polygon/shaders/extrusion/polygon_extrusion_frag.glsl +0 -2
- package/es/polygon/shaders/fill/fill_linear_frag.glsl +4 -2
- package/es/polygon/shaders/ocean/ocean_frag.glsl +212 -182
- package/es/polygon/shaders/water/polygon_water_frag.glsl +25 -20
- package/es/raster/index.js +2 -1
- package/es/raster/models/raster.js +1 -1
- package/es/raster/models/rasterRgb.js +1 -1
- package/es/raster/models/rasterTerrainRgb.js +1 -1
- package/es/raster/shaders/raster/raster_2d_frag.glsl +10 -7
- package/es/raster/shaders/rgb/raster_rgb_frag.glsl +16 -13
- package/es/raster/shaders/terrain/terrain_rgb_frag.glsl +18 -21
- package/lib/core/BaseLayer.d.ts +19 -0
- package/lib/core/BaseLayer.js +56 -0
- package/lib/core/interface.d.ts +4 -3
- package/lib/earth/models/atmosphere.js +1 -1
- package/lib/earth/models/base.js +1 -1
- package/lib/earth/models/bloomsphere.js +1 -1
- package/lib/earth/shaders/atmosphere/atmosphere_frag.glsl +6 -9
- package/lib/earth/shaders/base/base_frag.glsl +3 -3
- package/lib/earth/shaders/bloomshpere/bloomsphere_frag.glsl +5 -6
- package/lib/geometry/models/billboard.js +1 -1
- package/lib/geometry/models/sprite.js +1 -1
- package/lib/geometry/shaders/billboard_frag.glsl +4 -4
- package/lib/geometry/shaders/sprite_frag.glsl +2 -4
- package/lib/heatmap/models/heatmap.js +3 -3
- package/lib/heatmap/shaders/heatmap/heatmap_3d_frag.glsl +6 -7
- package/lib/heatmap/shaders/heatmap/heatmap_frag.glsl +24 -36
- package/lib/heatmap/shaders/heatmap/heatmap_framebuffer_frag.glsl +5 -5
- package/lib/line/models/flow.js +1 -1
- package/lib/line/shaders/flow/flow_line_frag.glsl +0 -1
- package/lib/plugins/LayerMaskPlugin.js +1 -1
- package/lib/plugins/ShaderUniformPlugin.js +26 -8
- package/lib/point/models/billboard_point.js +1 -1
- package/lib/point/models/extrude.js +1 -1
- package/lib/point/models/fill.js +1 -1
- package/lib/point/models/image.js +1 -1
- package/lib/point/models/normal.js +1 -1
- package/lib/point/shaders/billboard/billboard_point_frag.glsl +6 -8
- package/lib/point/shaders/extrude/extrude_frag.glsl +1 -3
- package/lib/point/shaders/fill/fill_frag.glsl +14 -17
- package/lib/point/shaders/image/image_frag.glsl +15 -12
- package/lib/point/shaders/normal/normal_frag.glsl +1 -1
- package/lib/polygon/models/extrude.js +3 -3
- package/lib/polygon/models/extrusion.js +1 -1
- package/lib/polygon/models/fill.js +1 -1
- package/lib/polygon/models/ocean.js +1 -1
- package/lib/polygon/models/water.js +1 -1
- package/lib/polygon/shaders/extrude/polygon_extrude_frag.glsl +5 -6
- package/lib/polygon/shaders/extrude/polygon_extrude_picklight_frag.glsl +7 -8
- package/lib/polygon/shaders/extrude/polygon_extrudetex_frag.glsl +4 -3
- package/lib/polygon/shaders/extrusion/polygon_extrusion_frag.glsl +0 -2
- package/lib/polygon/shaders/fill/fill_linear_frag.glsl +4 -2
- package/lib/polygon/shaders/ocean/ocean_frag.glsl +212 -182
- package/lib/polygon/shaders/water/polygon_water_frag.glsl +25 -20
- package/lib/raster/index.js +2 -1
- package/lib/raster/models/raster.js +1 -1
- package/lib/raster/models/rasterRgb.js +1 -1
- package/lib/raster/models/rasterTerrainRgb.js +1 -1
- package/lib/raster/shaders/raster/raster_2d_frag.glsl +10 -7
- package/lib/raster/shaders/rgb/raster_rgb_frag.glsl +16 -13
- package/lib/raster/shaders/terrain/terrain_rgb_frag.glsl +18 -21
- package/package.json +6 -6
package/es/core/BaseLayer.d.ts
CHANGED
|
@@ -78,6 +78,9 @@ export default class BaseLayer<ChildLayerStyleOptions = {}> extends EventEmitter
|
|
|
78
78
|
postProcessingPassFactory: (name: string) => IPostProcessingPass<unknown>;
|
|
79
79
|
get normalPassFactory(): (name: string) => import("@antv/l7-core").IPass<unknown>;
|
|
80
80
|
protected animateOptions: IAnimateOption;
|
|
81
|
+
protected relativeOrigin: [number, number];
|
|
82
|
+
protected originalExtent: [number, number, number, number];
|
|
83
|
+
protected absoluteDataArray: IParseDataItem[];
|
|
81
84
|
/**
|
|
82
85
|
* 图层容器
|
|
83
86
|
*/
|
|
@@ -235,6 +238,22 @@ export default class BaseLayer<ChildLayerStyleOptions = {}> extends EventEmitter
|
|
|
235
238
|
processData(filterData: IParseDataItem[]): IParseDataItem[];
|
|
236
239
|
getModelType(): string;
|
|
237
240
|
protected getDefaultConfig(): {};
|
|
241
|
+
/**
|
|
242
|
+
* 处理相对坐标转换
|
|
243
|
+
*/
|
|
244
|
+
protected processRelativeCoordinates(): void;
|
|
245
|
+
/**
|
|
246
|
+
* 获取绝对坐标数据(用于交互计算)
|
|
247
|
+
*/
|
|
248
|
+
getAbsoluteData(): IParseDataItem[];
|
|
249
|
+
/**
|
|
250
|
+
* 获取相对坐标原点
|
|
251
|
+
*/
|
|
252
|
+
getRelativeOrigin(): [number, number];
|
|
253
|
+
/**
|
|
254
|
+
* 获取原始数据范围
|
|
255
|
+
*/
|
|
256
|
+
getOriginalExtent(): [number, number, number, number];
|
|
238
257
|
protected sourceEvent: () => void;
|
|
239
258
|
protected initLayerModels(): Promise<void>;
|
|
240
259
|
getPickingUniformBuffer(): IBuffer;
|
package/es/core/BaseLayer.js
CHANGED
|
@@ -7,6 +7,7 @@ const _excluded = ["passes"],
|
|
|
7
7
|
// @ts-ignore
|
|
8
8
|
import { AsyncSeriesBailHook, AsyncWaterfallHook, SyncBailHook, SyncHook } from '@antv/async-hook';
|
|
9
9
|
import { BlendType, IDebugLog, ILayerStage, globalConfigService } from '@antv/l7-core';
|
|
10
|
+
import { processRelativeCoordinates } from '@antv/l7-source';
|
|
10
11
|
import { encodePickingColor, lodashUtil } from '@antv/l7-utils';
|
|
11
12
|
import { EventEmitter } from 'eventemitter3';
|
|
12
13
|
import { createPlugins } from "../plugins";
|
|
@@ -140,6 +141,11 @@ export default class BaseLayer extends EventEmitter {
|
|
|
140
141
|
_defineProperty(this, "animateOptions", {
|
|
141
142
|
enable: false
|
|
142
143
|
});
|
|
144
|
+
// 相对坐标系支持
|
|
145
|
+
_defineProperty(this, "relativeOrigin", [0, 0]);
|
|
146
|
+
_defineProperty(this, "originalExtent", [0, 0, 0, 0]);
|
|
147
|
+
_defineProperty(this, "absoluteDataArray", []);
|
|
148
|
+
// 保存绝对坐标数据用于交互
|
|
143
149
|
/**
|
|
144
150
|
* 图层容器
|
|
145
151
|
*/
|
|
@@ -166,6 +172,8 @@ export default class BaseLayer extends EventEmitter {
|
|
|
166
172
|
_defineProperty(this, "encodeDataLength", 0);
|
|
167
173
|
_defineProperty(this, "sourceEvent", () => {
|
|
168
174
|
this.dataState.dataSourceNeedUpdate = true;
|
|
175
|
+
// 处理相对坐标转换
|
|
176
|
+
this.processRelativeCoordinates();
|
|
169
177
|
const layerConfig = this.getLayerConfig();
|
|
170
178
|
if (layerConfig && layerConfig.autoFit) {
|
|
171
179
|
this.fitBounds(layerConfig.fitBoundsOptions);
|
|
@@ -931,6 +939,9 @@ export default class BaseLayer extends EventEmitter {
|
|
|
931
939
|
// source 初始化不需要处理
|
|
932
940
|
this.sourceEvent();
|
|
933
941
|
}
|
|
942
|
+
if (type === 'inited') {
|
|
943
|
+
this.processRelativeCoordinates();
|
|
944
|
+
}
|
|
934
945
|
});
|
|
935
946
|
}
|
|
936
947
|
getSource() {
|
|
@@ -1215,6 +1226,51 @@ export default class BaseLayer extends EventEmitter {
|
|
|
1215
1226
|
getDefaultConfig() {
|
|
1216
1227
|
return {};
|
|
1217
1228
|
}
|
|
1229
|
+
|
|
1230
|
+
/**
|
|
1231
|
+
* 处理相对坐标转换
|
|
1232
|
+
*/
|
|
1233
|
+
processRelativeCoordinates() {
|
|
1234
|
+
const layerConfig = this.getLayerConfig();
|
|
1235
|
+
const enableRelativeCoordinates = layerConfig.enableRelativeCoordinates;
|
|
1236
|
+
if (!enableRelativeCoordinates || !this.layerSource || !this.layerSource.data) {
|
|
1237
|
+
return;
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
// 保存原始绝对坐标数据用于交互
|
|
1241
|
+
this.absoluteDataArray = [...this.layerSource.data.dataArray];
|
|
1242
|
+
|
|
1243
|
+
// 处理相对坐标转换
|
|
1244
|
+
const result = processRelativeCoordinates(this.layerSource.data.dataArray, {
|
|
1245
|
+
enableRelativeCoordinates: true
|
|
1246
|
+
});
|
|
1247
|
+
|
|
1248
|
+
// 更新source数据为相对坐标
|
|
1249
|
+
this.layerSource.data.dataArray = result.dataArray;
|
|
1250
|
+
this.relativeOrigin = result.relativeOrigin;
|
|
1251
|
+
this.originalExtent = result.originalExtent;
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
/**
|
|
1255
|
+
* 获取绝对坐标数据(用于交互计算)
|
|
1256
|
+
*/
|
|
1257
|
+
getAbsoluteData() {
|
|
1258
|
+
return this.absoluteDataArray;
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
/**
|
|
1262
|
+
* 获取相对坐标原点
|
|
1263
|
+
*/
|
|
1264
|
+
getRelativeOrigin() {
|
|
1265
|
+
return this.relativeOrigin;
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
/**
|
|
1269
|
+
* 获取原始数据范围
|
|
1270
|
+
*/
|
|
1271
|
+
getOriginalExtent() {
|
|
1272
|
+
return this.originalExtent;
|
|
1273
|
+
}
|
|
1218
1274
|
initLayerModels() {
|
|
1219
1275
|
var _this5 = this;
|
|
1220
1276
|
return _asyncToGenerator(function* () {
|
package/es/core/interface.d.ts
CHANGED
|
@@ -26,11 +26,12 @@ export interface IBaseLayerStyleOptions {
|
|
|
26
26
|
zIndex?: number;
|
|
27
27
|
mask?: boolean;
|
|
28
28
|
maskInside?: boolean;
|
|
29
|
+
enableRelativeCoordinates?: boolean;
|
|
29
30
|
color?: string;
|
|
30
31
|
size?: number;
|
|
31
32
|
}
|
|
32
33
|
export interface ILineLayerStyleOptions extends IBaseLayerStyleOptions {
|
|
33
|
-
|
|
34
|
+
relativeOrigin?: number[];
|
|
34
35
|
coord?: string;
|
|
35
36
|
lineType?: keyof typeof lineStyleType;
|
|
36
37
|
dashArray?: [number, number];
|
|
@@ -63,7 +64,7 @@ export declare enum SizeUnitType {
|
|
|
63
64
|
meter = 1
|
|
64
65
|
}
|
|
65
66
|
export interface IPointLayerStyleOptions extends IBaseLayerStyleOptions {
|
|
66
|
-
|
|
67
|
+
relativeOrigin?: number[];
|
|
67
68
|
coord?: string;
|
|
68
69
|
strokeOpacity: number;
|
|
69
70
|
strokeWidth: number;
|
|
@@ -95,7 +96,7 @@ export interface IPointLayerStyleOptions extends IBaseLayerStyleOptions {
|
|
|
95
96
|
sourceLayer?: string;
|
|
96
97
|
}
|
|
97
98
|
export interface IPolygonLayerStyleOptions extends IBaseLayerStyleOptions {
|
|
98
|
-
|
|
99
|
+
relativeOrigin?: number[];
|
|
99
100
|
coord?: string;
|
|
100
101
|
opacityLinear?: {
|
|
101
102
|
enable: boolean;
|
|
@@ -4,7 +4,7 @@ import { lodashUtil } from '@antv/l7-utils';
|
|
|
4
4
|
import BaseModel from "../../core/BaseModel";
|
|
5
5
|
import { earthTriangulation } from "../../core/triangulation";
|
|
6
6
|
/* babel-plugin-inline-import '../shaders/atmosphere/atmosphere_frag.glsl' */
|
|
7
|
-
const atmoSphereFrag = "
|
|
7
|
+
const atmoSphereFrag = "layout(std140) uniform commonUniforms {\n float u_opacity;\n};\nin vec3 vVertexNormal;\nin float v_offset;\nin vec4 v_Color;\n\n#pragma include \"scene_uniforms\"\nout vec4 outputColor;\nvoid main() {\n // float intensity = pow(0.5 + dot(normalize(vVertexNormal), normalize(u_CameraPosition)), 3.0);\n float intensity = pow(v_offset + dot(normalize(vVertexNormal), normalize(u_CameraPosition)), 3.0);\n // \u53BB\u9664\u80CC\u9762\n if (intensity > 1.0) intensity = 0.0;\n\n outputColor = vec4(v_Color.rgb, v_Color.a * intensity * u_opacity);\n}\n";
|
|
8
8
|
/* babel-plugin-inline-import '../shaders/atmosphere/atmosphere_vert.glsl' */
|
|
9
9
|
const atmoSphereVert = "layout(location = ATTRIBUTE_LOCATION_POSITION) in vec3 a_Position;\nlayout(location = ATTRIBUTE_LOCATION_COLOR) vec4 a_Color;\nlayout(location = ATTRIBUTE_LOCATION_NORMAL) in vec3 a_Normal;\nlayout(location = ATTRIBUTE_LOCATION_UV) in vec2 a_Uv;\n\nlayout(std140) uniform commonUniforms {\n float u_opacity;\n};\n\n#pragma include \"scene_uniforms\"\nout vec3 vVertexNormal;\nout vec4 v_Color;\nout float v_offset;\n\nvoid main() {\n float EARTH_RADIUS = 100.0;\n\n v_Color = a_Color;\n\n v_offset = min(((length(u_CameraPosition) - EARTH_RADIUS)/600.0) * 0.5 + 0.4, 1.0);\n vVertexNormal = a_Normal;\n\n gl_Position = u_ViewProjectionMatrix * u_ModelMatrix * vec4(a_Position, 1.0);\n}\n";
|
|
10
10
|
const {
|
package/es/earth/models/base.js
CHANGED
|
@@ -4,7 +4,7 @@ import { AttributeType, gl } from '@antv/l7-core';
|
|
|
4
4
|
import BaseModel from "../../core/BaseModel";
|
|
5
5
|
import { earthTriangulation } from "../../core/triangulation";
|
|
6
6
|
/* babel-plugin-inline-import '../shaders/base/base_frag.glsl' */
|
|
7
|
-
const baseFrag = "uniform sampler2D u_texture;\n\nin vec2 v_texCoord;\nin float v_lightWeight;\nout vec4 outputColor;\n\nvoid main() {\n
|
|
7
|
+
const baseFrag = "uniform sampler2D u_texture;\n\nin vec2 v_texCoord;\nin float v_lightWeight;\nout vec4 outputColor;\n\nvoid main() {\n vec4 color = texture(SAMPLER_2D(u_texture), vec2(v_texCoord.x, v_texCoord.y));\n color.xyz = color.xyz * v_lightWeight;\n outputColor = color;\n}\n";
|
|
8
8
|
/* babel-plugin-inline-import '../shaders/base/base_vert.glsl' */
|
|
9
9
|
const baseVert = "// attribute vec4 a_Color;\nlayout(location = ATTRIBUTE_LOCATION_POSITION) in vec3 a_Position;\nlayout(location = ATTRIBUTE_LOCATION_NORMAL) in vec3 a_Normal;\nlayout(location = ATTRIBUTE_LOCATION_UV) in vec2 a_Uv;\n\n// attribute vec2 a_Extrude;\n// attribute float a_Size;\n// attribute float a_Shape;\n\nlayout(std140) uniform commonUniforms {\n\tvec4 u_sunLight: [1.0, -10.5, 12.0,0.0];\n\tfloat u_ambientRatio : 0.5;\n\tfloat u_diffuseRatio : 0.3;\n\tfloat u_specularRatio : 0.2;\n};\n\n#pragma include \"scene_uniforms\"\n\nout vec2 v_texCoord;\nout float v_lightWeight;\n\nfloat calc_lighting(vec4 pos) {\n\n\tvec3 worldPos = vec3(pos * u_ModelMatrix);\n\n\tvec3 worldNormal = a_Normal;\n\n\t// cal light weight\n\tvec3 viewDir = normalize(u_CameraPosition - worldPos);\n\n\tvec3 lightDir = normalize(u_sunLight.xyz);\n\n\tvec3 halfDir = normalize(viewDir+lightDir);\n\t// lambert\n\tfloat lambert = dot(worldNormal, lightDir);\n\t// specular\n\tfloat specular = pow(max(0.0, dot(worldNormal, halfDir)), 32.0);\n\t//sum to light weight\n\tfloat lightWeight = u_ambientRatio + u_diffuseRatio * lambert + u_specularRatio * specular;\n\n\treturn lightWeight;\n}\n\nvoid main() {\n\n\tv_texCoord = a_Uv;\n\n\tfloat lightWeight = calc_lighting(vec4(a_Position, 1.0));\n\tv_lightWeight = lightWeight;\n\n\tgl_Position = u_ViewProjectionMatrix * u_ModelMatrix * vec4(a_Position, 1.0);\n}\n";
|
|
10
10
|
export default class BaseEarthModel extends BaseModel {
|
|
@@ -4,7 +4,7 @@ import { lodashUtil } from '@antv/l7-utils';
|
|
|
4
4
|
import BaseModel from "../../core/BaseModel";
|
|
5
5
|
import { earthOuterTriangulation } from "../../core/triangulation";
|
|
6
6
|
/* babel-plugin-inline-import '../shaders/bloomshpere/bloomsphere_frag.glsl' */
|
|
7
|
-
const bloomSphereFrag = "
|
|
7
|
+
const bloomSphereFrag = "in vec3 vVertexNormal;\nin vec4 v_Color;\n\nlayout(std140) uniform commonUniforms {\n float u_opacity;\n};\nout vec4 outputColor;\n#pragma include \"scene_uniforms\"\nvoid main() {\n float intensity = -dot(normalize(vVertexNormal), normalize(u_CameraPosition));\n // \u53BB\u9664\u80CC\u9762\n if (intensity > 1.0) intensity = 0.0;\n\n outputColor = vec4(v_Color.rgb, v_Color.a * intensity * u_opacity);\n}\n";
|
|
8
8
|
/* babel-plugin-inline-import '../shaders/bloomshpere/bloomsphere_vert.glsl' */
|
|
9
9
|
const bloomSphereVert = "layout(location = ATTRIBUTE_LOCATION_POSITION) in vec3 a_Position;\nlayout(location = ATTRIBUTE_LOCATION_COLOR) vec4 a_Color;\nlayout(location = ATTRIBUTE_LOCATION_NORMAL) in vec3 a_Normal;\nlayout(location = ATTRIBUTE_LOCATION_UV) in vec2 a_Uv;\n\nlayout(std140) uniform commonUniforms {\n float u_opacity;\n};\n#pragma include \"scene_uniforms\"\n\nout vec3 vVertexNormal;\nout vec4 v_Color;\n\nvoid main() {\n v_Color = a_Color;\n\n vVertexNormal = a_Normal;\n\n gl_Position = u_ViewProjectionMatrix * u_ModelMatrix * vec4(a_Position, 1.0);\n}\n";
|
|
10
10
|
const {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
1
|
layout(std140) uniform commonUniforms {
|
|
3
|
-
|
|
2
|
+
float u_opacity;
|
|
4
3
|
};
|
|
5
4
|
in vec3 vVertexNormal;
|
|
6
5
|
in float v_offset;
|
|
@@ -9,12 +8,10 @@ in vec4 v_Color;
|
|
|
9
8
|
#pragma include "scene_uniforms"
|
|
10
9
|
out vec4 outputColor;
|
|
11
10
|
void main() {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
// 去除背面
|
|
17
|
-
if(intensity > 1.0) intensity = 0.0;
|
|
11
|
+
// float intensity = pow(0.5 + dot(normalize(vVertexNormal), normalize(u_CameraPosition)), 3.0);
|
|
12
|
+
float intensity = pow(v_offset + dot(normalize(vVertexNormal), normalize(u_CameraPosition)), 3.0);
|
|
13
|
+
// 去除背面
|
|
14
|
+
if (intensity > 1.0) intensity = 0.0;
|
|
18
15
|
|
|
19
|
-
|
|
16
|
+
outputColor = vec4(v_Color.rgb, v_Color.a * intensity * u_opacity);
|
|
20
17
|
}
|
|
@@ -5,7 +5,7 @@ in float v_lightWeight;
|
|
|
5
5
|
out vec4 outputColor;
|
|
6
6
|
|
|
7
7
|
void main() {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
vec4 color = texture(SAMPLER_2D(u_texture), vec2(v_texCoord.x, v_texCoord.y));
|
|
9
|
+
color.xyz = color.xyz * v_lightWeight;
|
|
10
|
+
outputColor = color;
|
|
11
11
|
}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
|
|
2
1
|
in vec3 vVertexNormal;
|
|
3
2
|
in vec4 v_Color;
|
|
4
3
|
|
|
5
4
|
layout(std140) uniform commonUniforms {
|
|
6
|
-
|
|
5
|
+
float u_opacity;
|
|
7
6
|
};
|
|
8
7
|
out vec4 outputColor;
|
|
9
8
|
#pragma include "scene_uniforms"
|
|
10
9
|
void main() {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
float intensity = -dot(normalize(vVertexNormal), normalize(u_CameraPosition));
|
|
11
|
+
// 去除背面
|
|
12
|
+
if (intensity > 1.0) intensity = 0.0;
|
|
14
13
|
|
|
15
|
-
|
|
14
|
+
outputColor = vec4(v_Color.rgb, v_Color.a * intensity * u_opacity);
|
|
16
15
|
}
|
|
@@ -4,7 +4,7 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
|
4
4
|
import { AttributeType, gl } from '@antv/l7-core';
|
|
5
5
|
import BaseModel from "../../core/BaseModel";
|
|
6
6
|
/* babel-plugin-inline-import '../shaders/billboard_frag.glsl' */
|
|
7
|
-
const planeFrag = "layout(std140) uniform commonUniforms {\n
|
|
7
|
+
const planeFrag = "layout(std140) uniform commonUniforms {\n vec2 u_size;\n float u_raisingHeight;\n float u_rotation;\n float u_opacity;\n};\n\nuniform sampler2D u_texture;\n\nin vec2 v_uv;\nout vec4 outputColor;\n\n#pragma include \"picking\"\nvoid main() {\n outputColor = texture(SAMPLER_2D(u_texture), vec2(v_uv.x, 1.0 - v_uv.y));\n outputColor.a *= u_opacity;\n outputColor = filterColor(outputColor);\n}\n";
|
|
8
8
|
/* babel-plugin-inline-import '../shaders/billboard_vert.glsl' */
|
|
9
9
|
const planeVert = "layout(location = ATTRIBUTE_LOCATION_POSITION) in vec3 a_Position;\nlayout(location = ATTRIBUTE_LOCATION_EXTRUDE) in vec3 a_Extrude;\nlayout(location = ATTRIBUTE_LOCATION_UV) in vec2 a_Uv;\n\nlayout(std140) uniform commonUniforms {\n vec2 u_size;\n float u_raisingHeight;\n float u_rotation;\n float u_opacity;\n};\n\nout vec2 v_uv;\n\n#pragma include \"projection\"\n#pragma include \"picking\"\n#pragma include \"rotation_2d\"\nvoid main() {\n vec3 extrude = a_Extrude;\n v_uv = a_Uv;\n float raiseHeight = u_raisingHeight;\n if (\n u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT ||\n u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT_OFFSET\n ) {\n float mapboxZoomScale = 4.0 / pow(2.0, 21.0 - u_Zoom);\n raiseHeight = u_raisingHeight * mapboxZoomScale;\n }\n\n // \u8BA1\u7B97\u7ECF\u7EAC\u5EA6\u70B9\u4F4D\u5750\u6807\n vec4 project_pos = project_position(vec4(a_Position.xy, 0.0, 1.0));\n\n // \u8BA1\u7B97\u7ED5 z \u8F74\u65CB\u8F6C\u540E\u7684\u504F\u79FB\n vec2 offsetXY = project_pixel(rotate_matrix(vec2(extrude.x * u_size.x, 0.0), u_rotation));\n // \u7ED5 z \u8F74\u65CB\u8F6C\n float x = project_pos.x + offsetXY.x;\n float y = project_pos.y + offsetXY.y;\n // z \u8F74\u4E0D\u53C2\u4E0E\u65CB\u8F6C\n float z = project_pixel(extrude.y * u_size.y + raiseHeight);\n\n gl_Position = project_common_position_to_clipspace(vec4(x, y, z, 1.0));\n\n setPickingColor(a_PickingColor);\n}\n";
|
|
10
10
|
export default class BillBoardModel extends BaseModel {
|
|
@@ -4,7 +4,7 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
|
4
4
|
import { gl } from '@antv/l7-core';
|
|
5
5
|
import BaseModel from "../../core/BaseModel";
|
|
6
6
|
/* babel-plugin-inline-import '../shaders/sprite_frag.glsl' */
|
|
7
|
-
const spriteFrag = "
|
|
7
|
+
const spriteFrag = "layout(std140) uniform commonUniforms {\n float u_opacity;\n float u_mapFlag;\n float u_Scale;\n};\nuniform sampler2D u_texture;\n\nin vec3 v_Color;\nin float v_d;\nout vec4 outputColor;\n\nvoid main() {\n if (v_d < 0.0) {\n discard;\n }\n\n if (u_mapFlag > 0.0) {\n outputColor = texture(SAMPLER_2D(u_texture), gl_PointCoord);\n outputColor.a *= u_opacity;\n } else {\n outputColor = vec4(v_Color, u_opacity);\n }\n}\n";
|
|
8
8
|
/* babel-plugin-inline-import '../shaders/sprite_vert.glsl' */
|
|
9
9
|
const spriteVert = "layout(location = ATTRIBUTE_LOCATION_POSITION) in vec3 a_Position;\nlayout(location = ATTRIBUTE_LOCATION_COLOR) in vec3 a_Color;\n\nlayout(std140) uniform commonUniforms {\n float u_opacity;\n float u_mapFlag;\n float u_Scale;\n};\n\nout vec3 v_Color;\nout float v_d;\n\n#pragma include \"projection\"\nvoid main() {\n v_Color = a_Color.xyz;\n v_d = a_Position.z;\n\n vec4 project_pos = project_position(vec4(a_Position, 1.0));\n gl_Position = project_common_position_to_clipspace(vec4(project_pos.xy, a_Position.z, 1.0));\n gl_PointSize = pow(u_Zoom - 1.0, 2.0) * u_Scale;\n}\n";
|
|
10
10
|
var SPRITE_ANIMATE_DIR = /*#__PURE__*/function (SPRITE_ANIMATE_DIR) {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
layout(std140) uniform commonUniforms {
|
|
3
2
|
float u_opacity;
|
|
4
3
|
float u_mapFlag;
|
|
@@ -11,12 +10,11 @@ in float v_d;
|
|
|
11
10
|
out vec4 outputColor;
|
|
12
11
|
|
|
13
12
|
void main() {
|
|
14
|
-
|
|
15
|
-
if(v_d < 0.0) {
|
|
13
|
+
if (v_d < 0.0) {
|
|
16
14
|
discard;
|
|
17
15
|
}
|
|
18
16
|
|
|
19
|
-
if(u_mapFlag > 0.0) {
|
|
17
|
+
if (u_mapFlag > 0.0) {
|
|
20
18
|
outputColor = texture(SAMPLER_2D(u_texture), gl_PointCoord);
|
|
21
19
|
outputColor.a *= u_opacity;
|
|
22
20
|
} else {
|
|
@@ -7,15 +7,15 @@ import { mat4 } from 'gl-matrix';
|
|
|
7
7
|
import BaseModel from "../../core/BaseModel";
|
|
8
8
|
import { HeatmapTriangulation } from "../../core/triangulation";
|
|
9
9
|
/* babel-plugin-inline-import '../shaders/heatmap/heatmap_3d_frag.glsl' */
|
|
10
|
-
const heatmap_3d_frag = "layout(std140) uniform commonUniforms {\n mat4 u_ViewProjectionMatrixUncentered;\n mat4 u_InverseViewProjectionMatrix;\n float u_opacity;\n float u_common_uniforms_padding1;\n float u_common_uniforms_padding2;\n float u_common_uniforms_padding3;\n};\n\nuniform sampler2D u_texture;\nuniform sampler2D u_colorTexture;\n\nin vec2 v_texCoord;\nin float v_intensity;\nout vec4 outputColor;\n\nvoid main(){\n
|
|
10
|
+
const heatmap_3d_frag = "layout(std140) uniform commonUniforms {\n mat4 u_ViewProjectionMatrixUncentered;\n mat4 u_InverseViewProjectionMatrix;\n float u_opacity;\n float u_common_uniforms_padding1;\n float u_common_uniforms_padding2;\n float u_common_uniforms_padding3;\n};\n\nuniform sampler2D u_texture;\nuniform sampler2D u_colorTexture;\n\nin vec2 v_texCoord;\nin float v_intensity;\nout vec4 outputColor;\n\nvoid main() {\n float intensity = texture(SAMPLER_2D(u_texture), v_texCoord).r;\n vec4 color = texture(SAMPLER_2D(u_colorTexture), vec2(intensity, 0));\n outputColor = color;\n // gl_FragColor.a = color.a * smoothstep(0.1,0.2,intensity)* u_opacity;\n outputColor.a = color.a * smoothstep(0.0, 0.1, intensity) * u_opacity;\n}\n";
|
|
11
11
|
/* babel-plugin-inline-import '../shaders/heatmap/heatmap_3d_vert.glsl' */
|
|
12
12
|
const heatmap_3d_vert = "layout(location = 0) in vec3 a_Position;\nlayout(location = 10) in vec2 a_Uv;\n\nlayout(std140) uniform commonUniforms {\n mat4 u_ViewProjectionMatrixUncentered;\n mat4 u_InverseViewProjectionMatrix;\n float u_opacity;\n float u_common_uniforms_padding1;\n float u_common_uniforms_padding2;\n float u_common_uniforms_padding3;\n};\n\nuniform sampler2D u_texture;\nuniform sampler2D u_colorTexture;\n\nout vec2 v_texCoord;\nout float v_intensity;\n\nvec2 toBezier(float t, vec2 P0, vec2 P1, vec2 P2, vec2 P3) {\n float t2 = t * t;\n float one_minus_t = 1.0 - t;\n float one_minus_t2 = one_minus_t * one_minus_t;\n return P0 * one_minus_t2 * one_minus_t +\n P1 * 3.0 * t * one_minus_t2 +\n P2 * 3.0 * t2 * one_minus_t +\n P3 * t2 * t;\n}\nvec2 toBezier(float t, vec4 p) {\n return toBezier(t, vec2(0.0, 0.0), vec2(p.x, p.y), vec2(p.z, p.w), vec2(1.0, 1.0));\n}\n\n#pragma include \"projection\"\n#pragma include \"project\"\n\nvoid main() {\n v_texCoord = a_Uv;\n\n vec2 pos = a_Uv * vec2(2.0) - vec2(1.0); // \u5C06\u539F\u672C 0 -> 1 \u7684 uv \u8F6C\u6362\u4E3A -1 -> 1 \u7684\u6807\u51C6\u5750\u6807\u7A7A\u95F4\uFF08NDC\uFF09\n\n vec4 p1 = vec4(pos, 0.0, 1.0); // x/y \u5E73\u9762\u4E0A\u7684\u70B9\uFF08z == 0\uFF09\u53EF\u4EE5\u8BA4\u4E3A\u662F\u4E09\u7EF4\u4E0A\u7684\u70B9\u88AB\u6295\u5F71\u5230\u5E73\u9762\u540E\u7684\u70B9\n vec4 p2 = vec4(pos, 1.0, 1.0); // \u5E73\u884C\u4E8Ex/y\u5E73\u9762\u3001z==1 \u7684\u5E73\u9762\u4E0A\u7684\u70B9\n\n vec4 inverseP1 = u_InverseViewProjectionMatrix * p1; // \u6839\u636E\u89C6\u56FE\u6295\u5F71\u77E9\u9635\u7684\u9006\u77E9\u9635\u5E73\u9762\u4E0A\u7684\u53CD\u7B97\u51FA\u4E09\u7EF4\u7A7A\u95F4\u4E2D\u7684\u70B9\uFF08p1\u5E73\u9762\u4E0A\u7684\u70B9\uFF09\n vec4 inverseP2 = u_InverseViewProjectionMatrix * p2;\n\n inverseP1 = inverseP1 / inverseP1.w; // \u5F52\u4E00\u5316\u64CD\u4F5C\uFF08\u5F52\u4E00\u5316\u540E\u4E3A\u4E16\u754C\u5750\u6807\uFF09\n inverseP2 = inverseP2 / inverseP2.w;\n\n float zPos = (0.0 - inverseP1.z) / (inverseP2.z - inverseP1.z); // ??\n vec4 position = inverseP1 + zPos * (inverseP2 - inverseP1);\n\n vec4 b = vec4(0.5, 0.0, 1.0, 0.5);\n float fh;\n\n v_intensity = texture(SAMPLER_2D(u_texture), v_texCoord).r;\n fh = toBezier(v_intensity, b).y;\n gl_Position = u_ViewProjectionMatrixUncentered * vec4(position.xy, fh * project_pixel(50.0), 1.0);\n\n}\n"; // 绘制平面热力的 shader
|
|
13
13
|
/* babel-plugin-inline-import '../shaders/heatmap/heatmap_frag.glsl' */
|
|
14
|
-
const heatmap_frag = "uniform sampler2D u_texture;
|
|
14
|
+
const heatmap_frag = "uniform sampler2D u_texture; // \u70ED\u529B\u5F3A\u5EA6\u56FE\nuniform sampler2D u_colorTexture; // \u6839\u636E\u5F3A\u5EA6\u5206\u5E03\u7684\u8272\u5E26\n\nlayout(std140) uniform commonUniforms {\n float u_opacity;\n float u_common_uniforms_padding1;\n float u_common_uniforms_padding2;\n float u_common_uniforms_padding3;\n};\nin vec2 v_texCoord;\nout vec4 outputColor;\n\n#pragma include \"scene_uniforms\"\n\nfloat getBlurIndusty() {\n float vW = 2.0 / u_ViewportSize.x;\n float vH = 2.0 / u_ViewportSize.y;\n vec2 vUv = v_texCoord;\n float i11 = texture(SAMPLER_2D(u_texture), vec2(vUv.x - 1.0 * vW, vUv.y + 1.0 * vH)).r;\n float i12 = texture(SAMPLER_2D(u_texture), vec2(vUv.x - 0.0 * vW, vUv.y + 1.0 * vH)).r;\n float i13 = texture(SAMPLER_2D(u_texture), vec2(vUv.x + 1.0 * vW, vUv.y + 1.0 * vH)).r;\n\n float i21 = texture(SAMPLER_2D(u_texture), vec2(vUv.x - 1.0 * vW, vUv.y)).r;\n float i22 = texture(SAMPLER_2D(u_texture), vec2(vUv.x, vUv.y)).r;\n float i23 = texture(SAMPLER_2D(u_texture), vec2(vUv.x + 1.0 * vW, vUv.y)).r;\n\n float i31 = texture(SAMPLER_2D(u_texture), vec2(vUv.x - 1.0 * vW, vUv.y - 1.0 * vH)).r;\n float i32 = texture(SAMPLER_2D(u_texture), vec2(vUv.x - 0.0 * vW, vUv.y - 1.0 * vH)).r;\n float i33 = texture(SAMPLER_2D(u_texture), vec2(vUv.x + 1.0 * vW, vUv.y - 1.0 * vH)).r;\n\n return (i11 + i12 + i13 + i21 + i21 + i22 + i23 + i31 + i32 + i33) / 9.0;\n}\n\nvoid main() {\n // float intensity = texture(u_texture, v_texCoord).r;\n float intensity = getBlurIndusty();\n vec4 color = texture(SAMPLER_2D(u_colorTexture), vec2(intensity, 0.0));\n outputColor = color;\n outputColor.a = color.a * smoothstep(0.0, 0.1, intensity) * u_opacity;\n}\n";
|
|
15
15
|
/* babel-plugin-inline-import '../shaders/heatmap/heatmap_vert.glsl' */
|
|
16
16
|
const heatmap_vert = "layout(location = 0) in vec3 a_Position;\nlayout(location = 10) in vec2 a_Uv;\n\nlayout(std140) uniform commonUniforms {\n float u_opacity;\n float u_common_uniforms_padding1;\n float u_common_uniforms_padding2;\n float u_common_uniforms_padding3;\n};\n\n#pragma include \"scene_uniforms\"\n\nout vec2 v_texCoord;\nvoid main() {\n v_texCoord = a_Uv;\n #ifdef VIEWPORT_ORIGIN_TL\n v_texCoord.y = 1.0 - v_texCoord.y;\n #endif\n\n gl_Position = vec4(a_Position.xy, 0, 1.0);\n}\n";
|
|
17
17
|
/* babel-plugin-inline-import '../shaders/heatmap/heatmap_framebuffer_frag.glsl' */
|
|
18
|
-
const heatmap_framebuffer_frag = "layout(std140) uniform commonUniforms {\n float u_radius;\n float u_intensity;\n float u_common_uniforms_padding1;\n float u_common_uniforms_padding2;\n};\n\nin vec2 v_extrude;\nin float v_weight;\nout vec4 outputColor;\n#define GAUSS_COEF
|
|
18
|
+
const heatmap_framebuffer_frag = "layout(std140) uniform commonUniforms {\n float u_radius;\n float u_intensity;\n float u_common_uniforms_padding1;\n float u_common_uniforms_padding2;\n};\n\nin vec2 v_extrude;\nin float v_weight;\nout vec4 outputColor;\n#define GAUSS_COEF (0.3989422804014327)\n\nvoid main() {\n float d = -0.5 * 3.0 * 3.0 * dot(v_extrude, v_extrude);\n float val = v_weight * u_intensity * GAUSS_COEF * exp(d);\n outputColor = vec4(val, 1.0, 1.0, 1.0);\n}\n";
|
|
19
19
|
/* babel-plugin-inline-import '../shaders/heatmap/heatmap_framebuffer_vert.glsl' */
|
|
20
20
|
const heatmap_framebuffer_vert = "layout(location = ATTRIBUTE_LOCATION_POSITION) in vec3 a_Position;\nlayout(location = ATTRIBUTE_LOCATION_SIZE) in float a_Size;\nlayout(location = ATTRIBUTE_LOCATION_DIR) in vec2 a_Dir;\n\nlayout(std140) uniform commonUniforms {\n float u_radius;\n float u_intensity;\n float u_common_uniforms_padding1;\n float u_common_uniforms_padding2;\n};\n\nout vec2 v_extrude;\nout float v_weight;\n\n#define GAUSS_COEF (0.3989422804014327)\n\n#pragma include \"projection\"\n#pragma include \"picking\"\n\nvoid main() {\n vec3 picking_color_placeholder = u_PickingColor;\n\n v_weight = a_Size;\n float ZERO = 1.0 / 255.0 / 16.0;\n float extrude_x = a_Dir.x * 2.0 - 1.0;\n float extrude_y = a_Dir.y * 2.0 - 1.0;\n vec2 extrude_dir = normalize(vec2(extrude_x, extrude_y));\n float S = sqrt(-2.0 * log(ZERO / a_Size / u_intensity / GAUSS_COEF)) / 2.5;\n v_extrude = extrude_dir * S;\n\n vec2 offset = project_pixel(v_extrude * u_radius);\n vec4 project_pos = project_position(vec4(a_Position.xy, 0.0, 1.0));\n\n gl_Position = project_common_position_to_clipspace(vec4(project_pos.xy + offset, 0.0, 1.0));\n\n}\n";
|
|
21
21
|
import { heatMap3DTriangulation } from "../triangulation";
|
|
@@ -14,11 +14,10 @@ in vec2 v_texCoord;
|
|
|
14
14
|
in float v_intensity;
|
|
15
15
|
out vec4 outputColor;
|
|
16
16
|
|
|
17
|
-
void main(){
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
outputColor.a = color.a * smoothstep(0.,0.1,intensity) * u_opacity;
|
|
17
|
+
void main() {
|
|
18
|
+
float intensity = texture(SAMPLER_2D(u_texture), v_texCoord).r;
|
|
19
|
+
vec4 color = texture(SAMPLER_2D(u_colorTexture), vec2(intensity, 0));
|
|
20
|
+
outputColor = color;
|
|
21
|
+
// gl_FragColor.a = color.a * smoothstep(0.1,0.2,intensity)* u_opacity;
|
|
22
|
+
outputColor.a = color.a * smoothstep(0.0, 0.1, intensity) * u_opacity;
|
|
24
23
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
uniform sampler2D u_texture;
|
|
2
|
-
uniform sampler2D u_colorTexture;
|
|
1
|
+
uniform sampler2D u_texture; // 热力强度图
|
|
2
|
+
uniform sampler2D u_colorTexture; // 根据强度分布的色带
|
|
3
3
|
|
|
4
4
|
layout(std140) uniform commonUniforms {
|
|
5
5
|
float u_opacity;
|
|
@@ -13,40 +13,28 @@ out vec4 outputColor;
|
|
|
13
13
|
#pragma include "scene_uniforms"
|
|
14
14
|
|
|
15
15
|
float getBlurIndusty() {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
i11 +
|
|
33
|
-
i12 +
|
|
34
|
-
i13 +
|
|
35
|
-
i21 +
|
|
36
|
-
i21 +
|
|
37
|
-
i22 +
|
|
38
|
-
i23 +
|
|
39
|
-
i31 +
|
|
40
|
-
i32 +
|
|
41
|
-
i33
|
|
42
|
-
)/9.0;
|
|
16
|
+
float vW = 2.0 / u_ViewportSize.x;
|
|
17
|
+
float vH = 2.0 / u_ViewportSize.y;
|
|
18
|
+
vec2 vUv = v_texCoord;
|
|
19
|
+
float i11 = texture(SAMPLER_2D(u_texture), vec2(vUv.x - 1.0 * vW, vUv.y + 1.0 * vH)).r;
|
|
20
|
+
float i12 = texture(SAMPLER_2D(u_texture), vec2(vUv.x - 0.0 * vW, vUv.y + 1.0 * vH)).r;
|
|
21
|
+
float i13 = texture(SAMPLER_2D(u_texture), vec2(vUv.x + 1.0 * vW, vUv.y + 1.0 * vH)).r;
|
|
22
|
+
|
|
23
|
+
float i21 = texture(SAMPLER_2D(u_texture), vec2(vUv.x - 1.0 * vW, vUv.y)).r;
|
|
24
|
+
float i22 = texture(SAMPLER_2D(u_texture), vec2(vUv.x, vUv.y)).r;
|
|
25
|
+
float i23 = texture(SAMPLER_2D(u_texture), vec2(vUv.x + 1.0 * vW, vUv.y)).r;
|
|
26
|
+
|
|
27
|
+
float i31 = texture(SAMPLER_2D(u_texture), vec2(vUv.x - 1.0 * vW, vUv.y - 1.0 * vH)).r;
|
|
28
|
+
float i32 = texture(SAMPLER_2D(u_texture), vec2(vUv.x - 0.0 * vW, vUv.y - 1.0 * vH)).r;
|
|
29
|
+
float i33 = texture(SAMPLER_2D(u_texture), vec2(vUv.x + 1.0 * vW, vUv.y - 1.0 * vH)).r;
|
|
30
|
+
|
|
31
|
+
return (i11 + i12 + i13 + i21 + i21 + i22 + i23 + i31 + i32 + i33) / 9.0;
|
|
43
32
|
}
|
|
44
33
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
outputColor.a = color.a * smoothstep(0.,0.1,intensity) * u_opacity;
|
|
34
|
+
void main() {
|
|
35
|
+
// float intensity = texture(u_texture, v_texCoord).r;
|
|
36
|
+
float intensity = getBlurIndusty();
|
|
37
|
+
vec4 color = texture(SAMPLER_2D(u_colorTexture), vec2(intensity, 0.0));
|
|
38
|
+
outputColor = color;
|
|
39
|
+
outputColor.a = color.a * smoothstep(0.0, 0.1, intensity) * u_opacity;
|
|
52
40
|
}
|
|
@@ -8,10 +8,10 @@ layout(std140) uniform commonUniforms {
|
|
|
8
8
|
in vec2 v_extrude;
|
|
9
9
|
in float v_weight;
|
|
10
10
|
out vec4 outputColor;
|
|
11
|
-
#define GAUSS_COEF
|
|
11
|
+
#define GAUSS_COEF (0.3989422804014327)
|
|
12
12
|
|
|
13
|
-
void main(){
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
void main() {
|
|
14
|
+
float d = -0.5 * 3.0 * 3.0 * dot(v_extrude, v_extrude);
|
|
15
|
+
float val = v_weight * u_intensity * GAUSS_COEF * exp(d);
|
|
16
|
+
outputColor = vec4(val, 1.0, 1.0, 1.0);
|
|
17
17
|
}
|
package/es/line/models/flow.js
CHANGED
|
@@ -4,7 +4,7 @@ import { fp64LowPart } from '@antv/l7-utils';
|
|
|
4
4
|
import BaseModel from "../../core/BaseModel";
|
|
5
5
|
import { FlowLineTriangulation } from "../../core/line_trangluation";
|
|
6
6
|
/* babel-plugin-inline-import '../shaders/flow/flow_line_frag.glsl' */
|
|
7
|
-
const flow_line_frag = "// #extension GL_OES_standard_derivatives : enable\n\nin vec4 v_color;\nout vec4 outputColor;\n\n
|
|
7
|
+
const flow_line_frag = "// #extension GL_OES_standard_derivatives : enable\n\nin vec4 v_color;\nout vec4 outputColor;\n\n// line texture\n\n#pragma include \"picking\"\n\nvoid main() {\n outputColor = v_color;\n outputColor = filterColor(outputColor);\n}\n";
|
|
8
8
|
/* babel-plugin-inline-import '../shaders/flow/flow_line_vert.glsl' */
|
|
9
9
|
const flow_line_vert = "layout(location = ATTRIBUTE_LOCATION_POSITION) in vec3 a_Position;\nlayout(location = ATTRIBUTE_LOCATION_COLOR) in vec4 a_Color;\nlayout(location = ATTRIBUTE_LOCATION_SIZE) in vec2 a_Size;\nlayout(location = ATTRIBUTE_LOCATION_INSTANCE) in vec4 a_Instance;\nlayout(location = ATTRIBUTE_LOCATION_INSTANCE_64LOW) in vec4 a_Instance64Low;\nlayout(location = ATTRIBUTE_LOCATION_NORMAL) in vec3 a_Normal;\n\nlayout(std140) uniform commonUniorm {\n float u_gap_width: 1.0;\n float u_stroke_width: 1.0;\n float u_stroke_opacity: 1.0;\n};\n\n#pragma include \"projection\"\n#pragma include \"project\"\n#pragma include \"picking\"\n\nout vec4 v_color;\n\nvec2 project_pixel_offset(vec2 offsets) {\n vec2 data = project_pixel(offsets);\n\n return vec2(data.x, -data.y);\n}\n\nvec2 line_dir(vec2 target, vec2 source) {\n return normalize(ProjectFlat(target) - ProjectFlat(source));\n}\n\n\nvoid main() {\n // \u900F\u660E\u5EA6\u8BA1\u7B97\n vec2 source_world = a_Instance.rg; // \u8D77\u70B9\n vec2 target_world = a_Instance.ba; // \u7EC8\u70B9\n vec2 flowlineDir = line_dir(target_world, source_world);\n vec2 perpendicularDir = vec2(-flowlineDir.y, flowlineDir.x);\n\n vec2 position = mix(source_world, target_world, a_Position.x);\n vec2 position64Low = mix(a_Instance64Low.rg, a_Instance64Low.ba, a_Position.x);\n\n float lengthCommon = length(\n project_position(vec4(target_world, 0, 1)) - project_position(vec4(source_world, 0, 1))\n );\n vec2 offsetDistances = a_Size.x * project_pixel_offset(vec2(a_Position.y, a_Position.z)); // Mapbox || \u9AD8\u5FB7\n vec2 limitedOffsetDistances = clamp(\n offsetDistances,\n project_pixel(-lengthCommon * 0.2),\n project_pixel(lengthCommon * 0.2)\n );\n\n float startOffsetCommon = project_pixel(offsets[0]);\n float endOffsetCommon = project_pixel(offsets[1]);\n float endpointOffset = mix(\n clamp(startOffsetCommon, 0.0, lengthCommon * 0.2),\n -clamp(endOffsetCommon, 0.0, lengthCommon * 0.2),\n a_Position.x\n );\n\n vec2 normalsCommon = u_stroke_width * project_pixel_offset(vec2(a_Normal.x, a_Normal.y));\n\n float gapCommon = -1. * project_pixel(u_gap_width);\n vec3 offsetCommon = vec3(\n flowlineDir * (limitedOffsetDistances[1] + normalsCommon.y + endpointOffset * 1.05) -\n perpendicularDir * (limitedOffsetDistances[0] + gapCommon + normalsCommon.x),\n 0.0\n );\n\n vec4 project_pos = project_position(vec4(position.xy, 0, 1.0), position64Low);\n\n vec4 fillColor = vec4(a_Color.rgb, a_Color.a * opacity);\n v_color = mix(fillColor, vec4(u_stroke.xyz, u_stroke.w * fillColor.w * u_stroke_opacity), a_Normal.z);\n\n gl_Position = project_common_position_to_clipspace(vec4(project_pos.xy + offsetCommon.xy, 0., 1.0));\n\n setPickingColor(a_PickingColor);\n}\n";
|
|
10
10
|
export default class FlowLineModel extends BaseModel {
|
|
@@ -32,18 +32,30 @@ export default class ShaderUniformPlugin {
|
|
|
32
32
|
let uniformBuffer;
|
|
33
33
|
if (!this.rendererService.uniformBuffers[0]) {
|
|
34
34
|
// Create a Uniform Buffer Object(UBO).
|
|
35
|
+
// Size calculation: 4 mat4 (64) + 1 vec4 (4) + 4 vec3->vec4 (16) + 3 vec4 packed (12) = 96 floats
|
|
35
36
|
uniformBuffer = this.rendererService.createBuffer({
|
|
36
|
-
data: new Float32Array(
|
|
37
|
+
data: new Float32Array(96),
|
|
37
38
|
isUBO: true,
|
|
38
39
|
label: 'renderUniformBuffer'
|
|
39
40
|
});
|
|
40
41
|
this.rendererService.uniformBuffers[0] = uniformBuffer;
|
|
41
42
|
}
|
|
42
43
|
layer.hooks.beforeRender.tap('ShaderUniformPlugin', () => {
|
|
43
|
-
//
|
|
44
|
-
const
|
|
44
|
+
// 获取图层的相对坐标原点
|
|
45
|
+
const layerRelativeOrigin = layer.getRelativeOrigin && layer.getRelativeOrigin();
|
|
46
|
+
const relativeOrigin = layerRelativeOrigin || [0, 0];
|
|
47
|
+
|
|
45
48
|
// 重新计算坐标系参数
|
|
46
|
-
this.coordinateSystemService.refresh(
|
|
49
|
+
this.coordinateSystemService.refresh();
|
|
50
|
+
|
|
51
|
+
// 特殊处理:如果图层启用了相对坐标,强制设置ViewportCenter为RelativeOrigin
|
|
52
|
+
// 这样可以避免shader中的精度问题
|
|
53
|
+
const isUsingRelativeCoords = relativeOrigin && (Math.abs(relativeOrigin[0]) > 0.0001 || Math.abs(relativeOrigin[1]) > 0.0001);
|
|
54
|
+
if (isUsingRelativeCoords && this.coordinateSystemService.getCoordinateSystem() === 2) {
|
|
55
|
+
// COORDINATE_SYSTEM_LNGLAT_OFFSET
|
|
56
|
+
// 强制设置ViewportCenter为RelativeOrigin,避免shader中的大数计算
|
|
57
|
+
this.coordinateSystemService.setViewportCenter(relativeOrigin);
|
|
58
|
+
}
|
|
47
59
|
const {
|
|
48
60
|
width,
|
|
49
61
|
height
|
|
@@ -51,7 +63,7 @@ export default class ShaderUniformPlugin {
|
|
|
51
63
|
const {
|
|
52
64
|
data,
|
|
53
65
|
uniforms
|
|
54
|
-
} = this.generateUBO(width, height);
|
|
66
|
+
} = this.generateUBO(width, height, relativeOrigin);
|
|
55
67
|
if (this.layerService.alreadyInRendering && this.rendererService.uniformBuffers[0]) {
|
|
56
68
|
const renderUniformBuffer = this.rendererService.uniformBuffers[0];
|
|
57
69
|
// Update only once since all models can share one UBO.
|
|
@@ -75,7 +87,7 @@ export default class ShaderUniformPlugin {
|
|
|
75
87
|
}
|
|
76
88
|
});
|
|
77
89
|
}
|
|
78
|
-
generateUBO(width, height) {
|
|
90
|
+
generateUBO(width, height, offset) {
|
|
79
91
|
const u_ProjectionMatrix = this.cameraService.getProjectionMatrix();
|
|
80
92
|
const u_ViewMatrix = this.cameraService.getViewMatrix();
|
|
81
93
|
const u_ViewProjectionMatrix = this.cameraService.getViewProjectionMatrix();
|
|
@@ -92,6 +104,7 @@ export default class ShaderUniformPlugin {
|
|
|
92
104
|
const u_ViewportCenter = this.coordinateSystemService.getViewportCenter();
|
|
93
105
|
const u_ViewportSize = [width, height];
|
|
94
106
|
const u_FocalDistance = this.cameraService.getFocalDistance();
|
|
107
|
+
const u_RelativeOrigin = offset && offset.length >= 2 ? [offset[0], offset[1]] : [0, 0];
|
|
95
108
|
const data = [...u_ViewMatrix,
|
|
96
109
|
// 16
|
|
97
110
|
...u_ProjectionMatrix,
|
|
@@ -116,7 +129,10 @@ export default class ShaderUniformPlugin {
|
|
|
116
129
|
// 4
|
|
117
130
|
u_FocalDistance,
|
|
118
131
|
// 1
|
|
119
|
-
|
|
132
|
+
...u_RelativeOrigin,
|
|
133
|
+
// 2
|
|
134
|
+
0 // padding
|
|
135
|
+
];
|
|
120
136
|
return {
|
|
121
137
|
data,
|
|
122
138
|
uniforms: {
|
|
@@ -138,7 +154,9 @@ export default class ShaderUniformPlugin {
|
|
|
138
154
|
// 其他参数,例如视口大小、DPR 等
|
|
139
155
|
u_ViewportSize: u_ViewportSize,
|
|
140
156
|
u_ModelMatrix,
|
|
141
|
-
u_DevicePixelRatio: u_DevicePixelRatio
|
|
157
|
+
u_DevicePixelRatio: u_DevicePixelRatio,
|
|
158
|
+
// 相对原点坐标
|
|
159
|
+
u_RelativeOrigin: u_RelativeOrigin
|
|
142
160
|
}
|
|
143
161
|
};
|
|
144
162
|
}
|
|
@@ -3,7 +3,7 @@ import { AttributeType, gl } from '@antv/l7-core';
|
|
|
3
3
|
import BaseModel from "../../core/BaseModel";
|
|
4
4
|
import { rgb2arr } from '@antv/l7-utils';
|
|
5
5
|
/* babel-plugin-inline-import '../shaders/billboard/billboard_point_frag.glsl' */
|
|
6
|
-
const simplePointFrag = "
|
|
6
|
+
const simplePointFrag = "layout(std140) uniform commonUniorm {\n vec4 u_stroke_color;\n float u_additive;\n float u_stroke_opacity;\n float u_stroke_width;\n};\n\nin vec4 v_color;\nin float v_blur;\nin float v_innerRadius;\n\nout vec4 outputColor;\n\n#pragma include \"picking\"\nvoid main() {\n vec2 center = vec2(0.5);\n\n // Tip: \u7247\u5143\u5230\u4E2D\u5FC3\u70B9\u7684\u8DDD\u79BB 0 - 1\n float fragmengTocenter = distance(center, gl_PointCoord) * 2.0;\n // Tip: \u7247\u5143\u7684\u526A\u5207\u6210\u5706\u5F62\n float circleClipOpacity = 1.0 - smoothstep(v_blur, 1.0, fragmengTocenter);\n\n if (v_innerRadius < 0.99) {\n // \u5F53\u5B58\u5728 stroke \u4E14 stroke > 0.01\n float blurWidth = (1.0 - v_blur) / 2.0;\n vec4 stroke = vec4(u_stroke_color.rgb, u_stroke_opacity);\n if (fragmengTocenter > v_innerRadius + blurWidth) {\n outputColor = stroke;\n } else if (fragmengTocenter > v_innerRadius - blurWidth) {\n float mixR = (fragmengTocenter - (v_innerRadius - blurWidth)) / (blurWidth * 2.0);\n outputColor = mix(v_color, stroke, mixR);\n } else {\n outputColor = v_color;\n }\n } else {\n // \u5F53\u4E0D\u5B58\u5728 stroke \u6216 stroke <= 0.01\n outputColor = v_color;\n }\n\n outputColor = filterColor(outputColor);\n\n if (u_additive > 0.0) {\n outputColor *= circleClipOpacity;\n } else {\n outputColor.a *= circleClipOpacity;\n }\n\n}\n";
|
|
7
7
|
/* babel-plugin-inline-import '../shaders/billboard/billboard_point_vert.glsl' */
|
|
8
8
|
const simplePointVert = "\nlayout(location = ATTRIBUTE_LOCATION_POSITION) in vec3 a_Position;\nlayout(location = ATTRIBUTE_LOCATION_POSITION_64LOW) in vec2 a_Position64Low;\nlayout(location = ATTRIBUTE_LOCATION_COLOR) in vec4 a_Color;\nlayout(location = ATTRIBUTE_LOCATION_SIZE) in float a_Size;\n\nlayout(std140) uniform commonUniorm {\n vec4 u_stroke_color;\n float u_additive;\n float u_stroke_opacity;\n float u_stroke_width;\n};\n\nout vec4 v_color;\nout float v_blur;\nout float v_innerRadius;\n\n#pragma include \"projection\"\n#pragma include \"picking\"\n#pragma include \"project\"\nvoid main() {\n v_color = vec4(a_Color.xyz, a_Color.w * opacity);\n v_blur = 1.0 - max(2.0 / a_Size, 0.05);\n v_innerRadius = max((a_Size - u_stroke_width) / a_Size, 0.0);\n\n vec2 offset = project_pixel(u_offsets);\n\n vec4 project_pos = project_position(vec4(a_Position, 1.0), a_Position64Low);\n gl_Position = project_common_position_to_clipspace(vec4(vec2(project_pos.xy+offset),project_pos.z,project_pos.w));\n\n gl_PointSize = a_Size * 2.0 * u_DevicePixelRatio;\n setPickingColor(a_PickingColor);\n}\n";
|
|
9
9
|
export function PointTriangulation(feature) {
|
|
@@ -5,7 +5,7 @@ import { calculateCentroid, fp64LowPart, rgb2arr } from '@antv/l7-utils';
|
|
|
5
5
|
import BaseModel from "../../core/BaseModel";
|
|
6
6
|
import { PointExtrudeTriangulation } from "../../core/triangulation";
|
|
7
7
|
/* babel-plugin-inline-import '../shaders/extrude/extrude_frag.glsl' */
|
|
8
|
-
const pointExtrudeFrag = "
|
|
8
|
+
const pointExtrudeFrag = "in vec4 v_color;\nin float v_lightWeight;\nout vec4 outputColor;\n\nlayout(std140) uniform commonUniforms {\n float u_pickLight;\n float u_heightfixed;\n float u_r;\n float u_linearColor;\n vec4 u_sourceColor;\n vec4 u_targetColor;\n float u_opacitylinear;\n float u_opacitylinear_dir;\n float u_lightEnable;\n};\n\n#pragma include \"scene_uniforms\"\n#pragma include \"picking\"\n\nvoid main() {\n outputColor = v_color;\n // \u5F00\u542F\u900F\u660E\u5EA6\u6E10\u53D8\n // picking\n if (u_pickLight > 0.0) {\n outputColor = filterColorAlpha(outputColor, v_lightWeight);\n } else {\n outputColor = filterColor(outputColor);\n }\n}\n";
|
|
9
9
|
/* babel-plugin-inline-import '../shaders/extrude/extrude_vert.glsl' */
|
|
10
10
|
const pointExtrudeVert = "#define pi (3.1415926535)\n\nlayout(location = ATTRIBUTE_LOCATION_POSITION) in vec3 a_Position;\nlayout(location = ATTRIBUTE_LOCATION_COLOR) in vec4 a_Color;\nlayout(location = ATTRIBUTE_LOCATION_SIZE) in vec3 a_Size;\nlayout(location = ATTRIBUTE_LOCATION_EXTRUDE) in vec4 a_Extrude;\nlayout(location = ATTRIBUTE_LOCATION_NORMAL) in vec3 a_Normal;\n\nlayout(std140) uniform commonUniforms {\n float u_pickLight;\n float u_heightfixed;\n float u_r;\n float u_linearColor;\n vec4 u_sourceColor;\n vec4 u_targetColor;\n float u_opacitylinear;\n float u_opacitylinear_dir;\n float u_lightEnable;\n};\nout vec4 v_color;\nout float v_lightWeight;\n\n#pragma include \"projection\"\n#pragma include \"light\"\n#pragma include \"picking\"\n\nfloat getYRadian(float x, float z) {\n if (x > 0.0 && z > 0.0) {\n return atan(x / z);\n } else if (x > 0.0 && z <= 0.0) {\n return atan(-z / x) + pi / 2.0;\n } else if (x <= 0.0 && z <= 0.0) {\n return pi + atan(x / z); //atan(x/z) +\n } else {\n return atan(z / -x) + pi * 3.0 / 2.0;\n }\n}\n\nfloat getXRadian(float y, float r) {\n return atan(y / r);\n}\n\nvoid main() {\n vec3 size = a_Size * a_Position;\n\n vec3 offset = size; // \u63A7\u5236\u5706\u67F1\u4F53\u7684\u5927\u5C0F - \u4ECE\u6807\u51C6\u5355\u4F4D\u5706\u67F1\u4F53\u8FDB\u884C\u504F\u79FB\n\n if (u_heightfixed < 1.0) {\n // \u5706\u67F1\u4F53\u4E0D\u56FA\u5B9A\u9AD8\u5EA6\n } else {\n // \u5706\u67F1\u4F53\u56FA\u5B9A\u9AD8\u5EA6 \uFF08 \u5904\u7406 mapbox \uFF09\n if (\n u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT ||\n u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT_OFFSET\n ) {\n offset *= 4.0 / pow(2.0, 21.0 - u_Zoom);\n }\n }\n\n vec2 positions = a_Extrude.xy;\n vec2 positions64Low = a_Extrude.zw;\n vec4 project_pos = project_position(vec4(positions, 0.0, 1.0), positions64Low);\n\n // u_r \u63A7\u5236\u5706\u67F1\u7684\u751F\u957F\n vec4 pos = vec4(project_pos.xy + offset.xy, offset.z * u_r, 1.0);\n\n // // \u5706\u67F1\u5149\u7167\u6548\u679C\n float lightWeight = 1.0;\n\n if (u_lightEnable > 0.0) {\n // \u53D6\u6D88\u4E09\u5143\u8868\u8FBE\u5F0F\uFF0C\u589E\u5F3A\u5065\u58EE\u6027\n lightWeight = calc_lighting(pos);\n }\n\n v_lightWeight = lightWeight;\n\n v_color = a_Color;\n\n // \u8BBE\u7F6E\u5706\u67F1\u7684\u5E95\u8272\n if (u_linearColor == 1.0) {\n // \u4F7F\u7528\u6E10\u53D8\u989C\u8272\n v_color = mix(u_sourceColor, u_targetColor, a_Position.z);\n v_color.a = v_color.a * opacity;\n } else {\n v_color = vec4(a_Color.rgb * lightWeight, a_Color.w * opacity);\n }\n\n if (u_opacitylinear > 0.0) {\n v_color.a *= u_opacitylinear_dir > 0.0 ? 1.0 - a_Position.z : a_Position.z;\n }\n\n gl_Position = project_common_position_to_clipspace(pos);\n\n setPickingColor(a_PickingColor);\n}\n";
|
|
11
11
|
export default class ExtrudeModel extends BaseModel {
|