@antv/l7-layers 2.21.9 → 2.21.11-beta.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.
Files changed (287) hide show
  1. package/es/citybuliding/models/build.d.ts +16 -0
  2. package/es/citybuliding/models/build.js +18 -20
  3. package/es/citybuliding/shaders/build_frag.glsl +6 -6
  4. package/es/citybuliding/shaders/build_vert.glsl +8 -14
  5. package/es/core/BaseLayer.d.ts +0 -1
  6. package/es/core/BaseLayer.js +9 -19
  7. package/es/core/BaseModel.d.ts +15 -2
  8. package/es/core/BaseModel.js +98 -64
  9. package/es/core/CommonStyleAttribute.d.ts +14 -18
  10. package/es/core/CommonStyleAttribute.js +23 -67
  11. package/es/core/shape/extrude.js +6 -3
  12. package/es/core/triangulation.js +22 -50
  13. package/es/core/utils.d.ts +4 -0
  14. package/es/core/utils.js +33 -0
  15. package/es/earth/models/atmosphere.d.ts +15 -0
  16. package/es/earth/models/atmosphere.js +30 -24
  17. package/es/earth/models/base.d.ts +15 -0
  18. package/es/earth/models/base.js +30 -24
  19. package/es/earth/models/bloomsphere.d.ts +15 -0
  20. package/es/earth/models/bloomsphere.js +30 -24
  21. package/es/earth/shaders/atmosphere/atmosphere_vert.glsl +7 -5
  22. package/es/earth/shaders/base/base_vert.glsl +3 -3
  23. package/es/earth/shaders/bloomshpere/bloomsphere_vert.glsl +5 -4
  24. package/es/geometry/models/billboard.d.ts +15 -0
  25. package/es/geometry/models/billboard.js +14 -8
  26. package/es/geometry/models/plane.d.ts +14 -0
  27. package/es/geometry/models/plane.js +10 -10
  28. package/es/geometry/models/sprite.js +3 -9
  29. package/es/geometry/shaders/billboard_vert.glsl +28 -25
  30. package/es/geometry/shaders/plane_vert.glsl +6 -6
  31. package/es/geometry/shaders/sprite_vert.glsl +7 -9
  32. package/es/heatmap/models/grid.d.ts +14 -0
  33. package/es/heatmap/models/grid.js +10 -3
  34. package/es/heatmap/models/grid3d.d.ts +16 -0
  35. package/es/heatmap/models/grid3d.js +14 -6
  36. package/es/heatmap/models/heatmap.d.ts +20 -1
  37. package/es/heatmap/models/heatmap.js +96 -83
  38. package/es/heatmap/models/hexagon.d.ts +14 -0
  39. package/es/heatmap/models/hexagon.js +9 -3
  40. package/es/heatmap/shaders/grid/grid_vert.glsl +30 -42
  41. package/es/heatmap/shaders/grid3d/grid_3d_vert.glsl +14 -26
  42. package/es/heatmap/shaders/heatmap/heatmap_3d_vert.glsl +19 -16
  43. package/es/heatmap/shaders/heatmap/heatmap_framebuffer_vert.glsl +16 -22
  44. package/es/heatmap/shaders/heatmap/heatmap_vert.glsl +3 -4
  45. package/es/heatmap/shaders/hexagon/hexagon_vert.glsl +13 -23
  46. package/es/image/models/image.d.ts +14 -0
  47. package/es/image/models/image.js +11 -7
  48. package/es/image/shaders/image_vert.glsl +7 -6
  49. package/es/line/models/arc.d.ts +18 -0
  50. package/es/line/models/arc.js +57 -8
  51. package/es/line/models/arc_3d.d.ts +18 -0
  52. package/es/line/models/arc_3d.js +55 -7
  53. package/es/line/models/flow.d.ts +17 -0
  54. package/es/line/models/flow.js +35 -7
  55. package/es/line/models/great_circle.d.ts +17 -0
  56. package/es/line/models/great_circle.js +34 -6
  57. package/es/line/models/line.d.ts +17 -0
  58. package/es/line/models/line.js +17 -8
  59. package/es/line/models/simple_line.d.ts +14 -0
  60. package/es/line/models/simple_line.js +12 -47
  61. package/es/line/models/wall.d.ts +17 -0
  62. package/es/line/models/wall.js +22 -48
  63. package/es/line/shaders/arc/line_arc_vert.glsl +44 -52
  64. package/es/line/shaders/arc3d/line_arc_3d_vert.glsl +15 -20
  65. package/es/line/shaders/flow/flow_line_vert.glsl +30 -48
  66. package/es/line/shaders/greatCircle/line_arc_great_circle_vert.glsl +53 -74
  67. package/es/line/shaders/line/line_vert.glsl +31 -48
  68. package/es/line/shaders/simple/simpleline_vert.glsl +18 -23
  69. package/es/line/shaders/wall/wall_vert.glsl +36 -45
  70. package/es/mask/models/fill.js +2 -1
  71. package/es/mask/shaders/mask_vert.glsl +2 -7
  72. package/es/plugins/DataMappingPlugin.d.ts +0 -1
  73. package/es/plugins/DataMappingPlugin.js +1 -24
  74. package/es/plugins/PixelPickingPlugin.js +2 -2
  75. package/es/plugins/RegisterStyleAttributePlugin.d.ts +0 -1
  76. package/es/plugins/RegisterStyleAttributePlugin.js +3 -25
  77. package/es/plugins/ShaderUniformPlugin.d.ts +0 -5
  78. package/es/plugins/ShaderUniformPlugin.js +4 -35
  79. package/es/point/models/billboard_point.d.ts +14 -0
  80. package/es/point/models/billboard_point.js +11 -3
  81. package/es/point/models/earthExtrude.d.ts +16 -0
  82. package/es/point/models/earthExtrude.js +15 -8
  83. package/es/point/models/earthFill.d.ts +16 -0
  84. package/es/point/models/earthFill.js +13 -5
  85. package/es/point/models/extrude.d.ts +16 -0
  86. package/es/point/models/extrude.js +19 -12
  87. package/es/point/models/fill.d.ts +16 -0
  88. package/es/point/models/fill.js +16 -5
  89. package/es/point/models/fillImage.d.ts +16 -0
  90. package/es/point/models/fillImage.js +16 -16
  91. package/es/point/models/image.d.ts +15 -0
  92. package/es/point/models/image.js +14 -4
  93. package/es/point/models/normal.d.ts +14 -0
  94. package/es/point/models/normal.js +11 -3
  95. package/es/point/models/radar.d.ts +15 -0
  96. package/es/point/models/radar.js +13 -4
  97. package/es/point/models/text.d.ts +16 -0
  98. package/es/point/models/text.js +18 -11
  99. package/es/point/shaders/billboard/billboard_point_vert.glsl +10 -13
  100. package/es/point/shaders/earthExtrude/earthExtrude_vert.glsl +15 -25
  101. package/es/point/shaders/earthFill/earthFill_vert.glsl +6 -6
  102. package/es/point/shaders/extrude/extrude_vert.glsl +35 -39
  103. package/es/point/shaders/fill/fill_vert.glsl +12 -14
  104. package/es/point/shaders/fillImage/fillImage_vert.glsl +16 -28
  105. package/es/point/shaders/image/image_vert.glsl +15 -12
  106. package/es/point/shaders/normal/normal_vert.glsl +7 -10
  107. package/es/point/shaders/radar/radar_vert.glsl +11 -11
  108. package/es/point/shaders/text/text_vert.glsl +10 -9
  109. package/es/polygon/models/extrude.d.ts +16 -0
  110. package/es/polygon/models/extrude.js +26 -26
  111. package/es/polygon/models/extrusion.d.ts +16 -0
  112. package/es/polygon/models/extrusion.js +34 -4
  113. package/es/polygon/models/fill.d.ts +14 -0
  114. package/es/polygon/models/fill.js +12 -4
  115. package/es/polygon/models/ocean.d.ts +14 -0
  116. package/es/polygon/models/ocean.js +11 -6
  117. package/es/polygon/models/water.d.ts +14 -0
  118. package/es/polygon/models/water.js +11 -6
  119. package/es/polygon/shaders/extrude/polygon_extrude_picklight_vert.glsl +17 -15
  120. package/es/polygon/shaders/extrude/polygon_extrude_vert.glsl +22 -20
  121. package/es/polygon/shaders/extrude/polygon_extrudetex_vert.glsl +17 -17
  122. package/es/polygon/shaders/extrusion/polygon_extrusion_vert.glsl +8 -8
  123. package/es/polygon/shaders/fill/fill_linear_vert.glsl +7 -6
  124. package/es/polygon/shaders/fill/fill_vert.glsl +10 -12
  125. package/es/polygon/shaders/ocean/ocean_vert.glsl +3 -4
  126. package/es/polygon/shaders/water/polygon_water_vert.glsl +5 -5
  127. package/es/raster/index.d.ts +1 -1
  128. package/es/raster/index.js +1 -1
  129. package/es/raster/models/raster.d.ts +14 -0
  130. package/es/raster/models/raster.js +13 -3
  131. package/es/raster/models/rasterRgb.d.ts +14 -0
  132. package/es/raster/models/rasterRgb.js +12 -3
  133. package/es/raster/models/rasterTerrainRgb.d.ts +14 -0
  134. package/es/raster/models/rasterTerrainRgb.js +11 -3
  135. package/es/raster/shaders/raster/raster_2d_vert.glsl +6 -6
  136. package/es/raster/shaders/rgb/raster_rgb_vert.glsl +11 -11
  137. package/es/raster/shaders/terrain/terrain_rgb_vert.glsl +11 -11
  138. package/es/tile/core/BaseLayer.js +0 -16
  139. package/es/utils/extrude_polyline.d.ts +0 -15
  140. package/es/utils/extrude_polyline.js +0 -217
  141. package/es/wind/models/wind.d.ts +14 -0
  142. package/es/wind/models/wind.js +9 -1
  143. package/es/wind/shaders/wind_vert.glsl +6 -5
  144. package/lib/citybuliding/models/build.d.ts +16 -0
  145. package/lib/citybuliding/models/build.js +18 -20
  146. package/lib/citybuliding/shaders/build_frag.glsl +6 -6
  147. package/lib/citybuliding/shaders/build_vert.glsl +8 -14
  148. package/lib/core/BaseLayer.d.ts +0 -1
  149. package/lib/core/BaseLayer.js +9 -19
  150. package/lib/core/BaseModel.d.ts +15 -2
  151. package/lib/core/BaseModel.js +96 -62
  152. package/lib/core/CommonStyleAttribute.d.ts +14 -18
  153. package/lib/core/CommonStyleAttribute.js +23 -68
  154. package/lib/core/shape/extrude.js +6 -3
  155. package/lib/core/triangulation.js +22 -50
  156. package/lib/core/utils.d.ts +4 -0
  157. package/lib/core/utils.js +35 -0
  158. package/lib/earth/models/atmosphere.d.ts +15 -0
  159. package/lib/earth/models/atmosphere.js +30 -24
  160. package/lib/earth/models/base.d.ts +15 -0
  161. package/lib/earth/models/base.js +30 -24
  162. package/lib/earth/models/bloomsphere.d.ts +15 -0
  163. package/lib/earth/models/bloomsphere.js +30 -24
  164. package/lib/earth/shaders/atmosphere/atmosphere_vert.glsl +7 -5
  165. package/lib/earth/shaders/base/base_vert.glsl +3 -3
  166. package/lib/earth/shaders/bloomshpere/bloomsphere_vert.glsl +5 -4
  167. package/lib/geometry/models/billboard.d.ts +15 -0
  168. package/lib/geometry/models/billboard.js +14 -8
  169. package/lib/geometry/models/plane.d.ts +14 -0
  170. package/lib/geometry/models/plane.js +10 -10
  171. package/lib/geometry/models/sprite.js +3 -9
  172. package/lib/geometry/shaders/billboard_vert.glsl +28 -25
  173. package/lib/geometry/shaders/plane_vert.glsl +6 -6
  174. package/lib/geometry/shaders/sprite_vert.glsl +7 -9
  175. package/lib/heatmap/models/grid.d.ts +14 -0
  176. package/lib/heatmap/models/grid.js +10 -3
  177. package/lib/heatmap/models/grid3d.d.ts +16 -0
  178. package/lib/heatmap/models/grid3d.js +14 -6
  179. package/lib/heatmap/models/heatmap.d.ts +20 -1
  180. package/lib/heatmap/models/heatmap.js +95 -82
  181. package/lib/heatmap/models/hexagon.d.ts +14 -0
  182. package/lib/heatmap/models/hexagon.js +9 -3
  183. package/lib/heatmap/shaders/grid/grid_vert.glsl +30 -42
  184. package/lib/heatmap/shaders/grid3d/grid_3d_vert.glsl +14 -26
  185. package/lib/heatmap/shaders/heatmap/heatmap_3d_vert.glsl +19 -16
  186. package/lib/heatmap/shaders/heatmap/heatmap_framebuffer_vert.glsl +16 -22
  187. package/lib/heatmap/shaders/heatmap/heatmap_vert.glsl +3 -4
  188. package/lib/heatmap/shaders/hexagon/hexagon_vert.glsl +13 -23
  189. package/lib/image/models/image.d.ts +14 -0
  190. package/lib/image/models/image.js +11 -7
  191. package/lib/image/shaders/image_vert.glsl +7 -6
  192. package/lib/line/models/arc.d.ts +18 -0
  193. package/lib/line/models/arc.js +56 -7
  194. package/lib/line/models/arc_3d.d.ts +18 -0
  195. package/lib/line/models/arc_3d.js +55 -7
  196. package/lib/line/models/flow.d.ts +17 -0
  197. package/lib/line/models/flow.js +35 -7
  198. package/lib/line/models/great_circle.d.ts +17 -0
  199. package/lib/line/models/great_circle.js +33 -5
  200. package/lib/line/models/line.d.ts +17 -0
  201. package/lib/line/models/line.js +17 -8
  202. package/lib/line/models/simple_line.d.ts +14 -0
  203. package/lib/line/models/simple_line.js +12 -47
  204. package/lib/line/models/wall.d.ts +17 -0
  205. package/lib/line/models/wall.js +22 -48
  206. package/lib/line/shaders/arc/line_arc_vert.glsl +44 -52
  207. package/lib/line/shaders/arc3d/line_arc_3d_vert.glsl +15 -20
  208. package/lib/line/shaders/flow/flow_line_vert.glsl +30 -48
  209. package/lib/line/shaders/greatCircle/line_arc_great_circle_vert.glsl +53 -74
  210. package/lib/line/shaders/line/line_vert.glsl +31 -48
  211. package/lib/line/shaders/simple/simpleline_vert.glsl +18 -23
  212. package/lib/line/shaders/wall/wall_vert.glsl +36 -45
  213. package/lib/mask/models/fill.js +2 -1
  214. package/lib/mask/shaders/mask_vert.glsl +2 -7
  215. package/lib/plugins/DataMappingPlugin.d.ts +0 -1
  216. package/lib/plugins/DataMappingPlugin.js +0 -23
  217. package/lib/plugins/PixelPickingPlugin.js +1 -1
  218. package/lib/plugins/RegisterStyleAttributePlugin.d.ts +0 -1
  219. package/lib/plugins/RegisterStyleAttributePlugin.js +2 -24
  220. package/lib/plugins/ShaderUniformPlugin.d.ts +0 -5
  221. package/lib/plugins/ShaderUniformPlugin.js +4 -35
  222. package/lib/point/models/billboard_point.d.ts +14 -0
  223. package/lib/point/models/billboard_point.js +11 -3
  224. package/lib/point/models/earthExtrude.d.ts +16 -0
  225. package/lib/point/models/earthExtrude.js +14 -7
  226. package/lib/point/models/earthFill.d.ts +16 -0
  227. package/lib/point/models/earthFill.js +13 -5
  228. package/lib/point/models/extrude.d.ts +16 -0
  229. package/lib/point/models/extrude.js +18 -11
  230. package/lib/point/models/fill.d.ts +16 -0
  231. package/lib/point/models/fill.js +16 -5
  232. package/lib/point/models/fillImage.d.ts +16 -0
  233. package/lib/point/models/fillImage.js +16 -16
  234. package/lib/point/models/image.d.ts +15 -0
  235. package/lib/point/models/image.js +14 -4
  236. package/lib/point/models/normal.d.ts +14 -0
  237. package/lib/point/models/normal.js +11 -3
  238. package/lib/point/models/radar.d.ts +15 -0
  239. package/lib/point/models/radar.js +13 -4
  240. package/lib/point/models/text.d.ts +16 -0
  241. package/lib/point/models/text.js +18 -11
  242. package/lib/point/shaders/billboard/billboard_point_vert.glsl +10 -13
  243. package/lib/point/shaders/earthExtrude/earthExtrude_vert.glsl +15 -25
  244. package/lib/point/shaders/earthFill/earthFill_vert.glsl +6 -6
  245. package/lib/point/shaders/extrude/extrude_vert.glsl +35 -39
  246. package/lib/point/shaders/fill/fill_vert.glsl +12 -14
  247. package/lib/point/shaders/fillImage/fillImage_vert.glsl +16 -28
  248. package/lib/point/shaders/image/image_vert.glsl +15 -12
  249. package/lib/point/shaders/normal/normal_vert.glsl +7 -10
  250. package/lib/point/shaders/radar/radar_vert.glsl +11 -11
  251. package/lib/point/shaders/text/text_vert.glsl +10 -9
  252. package/lib/polygon/models/extrude.d.ts +16 -0
  253. package/lib/polygon/models/extrude.js +25 -25
  254. package/lib/polygon/models/extrusion.d.ts +16 -0
  255. package/lib/polygon/models/extrusion.js +34 -4
  256. package/lib/polygon/models/fill.d.ts +14 -0
  257. package/lib/polygon/models/fill.js +12 -4
  258. package/lib/polygon/models/ocean.d.ts +14 -0
  259. package/lib/polygon/models/ocean.js +11 -6
  260. package/lib/polygon/models/water.d.ts +14 -0
  261. package/lib/polygon/models/water.js +11 -6
  262. package/lib/polygon/shaders/extrude/polygon_extrude_picklight_vert.glsl +17 -15
  263. package/lib/polygon/shaders/extrude/polygon_extrude_vert.glsl +22 -20
  264. package/lib/polygon/shaders/extrude/polygon_extrudetex_vert.glsl +17 -17
  265. package/lib/polygon/shaders/extrusion/polygon_extrusion_vert.glsl +8 -8
  266. package/lib/polygon/shaders/fill/fill_linear_vert.glsl +7 -6
  267. package/lib/polygon/shaders/fill/fill_vert.glsl +10 -12
  268. package/lib/polygon/shaders/ocean/ocean_vert.glsl +3 -4
  269. package/lib/polygon/shaders/water/polygon_water_vert.glsl +5 -5
  270. package/lib/raster/index.d.ts +1 -1
  271. package/lib/raster/index.js +2 -2
  272. package/lib/raster/models/raster.d.ts +14 -0
  273. package/lib/raster/models/raster.js +13 -3
  274. package/lib/raster/models/rasterRgb.d.ts +14 -0
  275. package/lib/raster/models/rasterRgb.js +12 -3
  276. package/lib/raster/models/rasterTerrainRgb.d.ts +14 -0
  277. package/lib/raster/models/rasterTerrainRgb.js +11 -3
  278. package/lib/raster/shaders/raster/raster_2d_vert.glsl +6 -6
  279. package/lib/raster/shaders/rgb/raster_rgb_vert.glsl +11 -11
  280. package/lib/raster/shaders/terrain/terrain_rgb_vert.glsl +11 -11
  281. package/lib/tile/core/BaseLayer.js +0 -16
  282. package/lib/utils/extrude_polyline.d.ts +0 -15
  283. package/lib/utils/extrude_polyline.js +0 -217
  284. package/lib/wind/models/wind.d.ts +14 -0
  285. package/lib/wind/models/wind.js +9 -1
  286. package/lib/wind/shaders/wind_vert.glsl +6 -5
  287. package/package.json +9 -9
@@ -5,25 +5,32 @@ import { AttributeType, gl } from '@antv/l7-core';
5
5
  import { rgb2arr } from '@antv/l7-utils';
6
6
  import BaseModel from "../../core/BaseModel";
7
7
  import { PolygonExtrudeTriangulation } from "../../core/triangulation";
8
+ import { loadImage } from "../../utils/load-image";
8
9
  /* babel-plugin-inline-import '../shaders/extrude/polygon_extrude_frag.glsl' */
9
10
  const polygonExtrudeFrag = "layout(std140) uniform commonUniforms {\n vec4 u_sourceColor;\n vec4 u_targetColor;\n float u_linearColor;\n float u_topsurface;\n float u_sidesurface;\n float u_heightfixed; // \u9ED8\u8BA4\u4E0D\u56FA\u5B9A\n float u_raisingHeight;\n};\n\nin vec4 v_Color;\n#pragma include \"scene_uniforms\"\n#pragma include \"picking\"\nout vec4 outputColor;\nvoid main() {\n\n // top face\n if(u_topsurface < 1.0) {\n discard;\n }\n\n outputColor = v_Color;\n \n outputColor = filterColor(outputColor);\n}\n";
10
- /* babel-plugin-inline-import '../shaders/extrude/polygon_extrude_vert.glsl' */
11
- const polygonExtrudeVert = "layout(location = 0) in vec3 a_Position;\nlayout(location = 1) in vec4 a_Color;\nlayout(location = 9) in float a_Size;\nlayout(location = 13) in vec3 a_Normal;\nlayout(location = 14) in vec3 a_uvs;\n\nlayout(std140) uniform commonUniforms {\n vec4 u_sourceColor;\n vec4 u_targetColor;\n float u_linearColor;\n float u_topsurface;\n float u_sidesurface;\n float u_heightfixed; // \u9ED8\u8BA4\u4E0D\u56FA\u5B9A\n float u_raisingHeight;\n};\n\nout vec4 v_Color;\n\n#pragma include \"projection\"\n#pragma include \"light\"\n#pragma include \"picking\"\n\nvoid main() {\n \nfloat isSide = a_Position.z;\n float topU = a_uvs[0];\n float topV = 1.0 - a_uvs[1];\n float sidey = a_uvs[2];\n\n vec4 pos = vec4(a_Position.xy, a_Position.z * a_Size, 1.0);\n float lightWeight = calc_lighting(pos);\n\n vec4 project_pos = project_position(pos);\n\n if(u_heightfixed > 0.0) { // \u5224\u65AD\u51E0\u4F55\u4F53\u662F\u5426\u56FA\u5B9A\u9AD8\u5EA6\n project_pos.z = a_Position.z * a_Size;\n project_pos.z += u_raisingHeight;\n\n if(u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT || u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT_OFFSET) {\n float mapboxZoomScale = 4.0/pow(2.0, 21.0 - u_Zoom);\n project_pos.z *= mapboxZoomScale;\n project_pos.z += u_raisingHeight * mapboxZoomScale;\n }\n }\n\n\n gl_Position = project_common_position_to_clipspace_v2(vec4(project_pos.xyz, 1.0));\n\n // Tip: \u90E8\u5206\u673A\u578B GPU \u8BA1\u7B97\u7CBE\u5EA6\u517C\u5BB9\n if(isSide < 0.999) {\n // side face\n // if(u_sidesurface < 1.0) {\n // discard;\n // }\n\n if(u_linearColor == 1.0) {\n vec4 linearColor = mix(u_targetColor, u_sourceColor, sidey);\n linearColor.rgb *= lightWeight;\n v_Color = linearColor;\n } else {\n v_Color = a_Color;\n }\n\n } else {\n v_Color = a_Color;\n }\n\n v_Color = vec4(v_Color.rgb * lightWeight, v_Color.w * opacity);\n\n\n setPickingColor(a_PickingColor);\n}\n"; // extrude
12
- /* babel-plugin-inline-import '../shaders/extrude/polygon_extrudetex_frag.glsl' */
13
- const polygonExtrudeTexFrag = "uniform sampler2D u_texture;\n\nlayout(std140) uniform commonUniforms {\n vec4 u_sourceColor;\n vec4 u_targetColor;\n float u_linearColor;\n float u_topsurface;\n float u_sidesurface;\n float u_heightfixed; // \u9ED8\u8BA4\u4E0D\u56FA\u5B9A\n float u_raisingHeight;\n};\n\nin vec4 v_Color;\nin vec3 v_uvs;\nin vec2 v_texture_data;\n\n#pragma include \"scene_uniforms\"\n#pragma include \"picking\"\n\nout vec4 outputColor;\n\nvoid main() {\n float opacity = u_opacity;\n float isSide = v_texture_data.x;\n float lightWeight = v_texture_data.y;\n float topU = v_uvs[0];\n float topV = 1.0 - v_uvs[1];\n float sidey = v_uvs[2];\n\n outputColor = texture(SAMPLER_2D(u_texture), vec2(topU, topV));\n // Tip: \u90E8\u5206\u673A\u578B GPU \u8BA1\u7B97\u7CBE\u5EA6\u517C\u5BB9\n if (isSide < 0.999) {// \u662F\u5426\u662F\u8FB9\u7F18\n // side face\n if (u_sidesurface < 1.0) {\n discard;\n }\n\n if (u_linearColor == 1.0) {\n vec4 linearColor = mix(u_targetColor, u_sourceColor, sidey);\n linearColor.rgb *= lightWeight;\n outputColor = linearColor;\n } else {\n outputColor = v_Color;\n }\n } else {\n // top face\n if (u_topsurface < 1.0) {\n discard;\n }\n }\n \n outputColor.a *= opacity;\n outputColor = filterColor(outputColor);\n}\n"; // texture
14
- /* babel-plugin-inline-import '../shaders/extrude/polygon_extrudetex_vert.glsl' */
15
- const polygonExtrudeTexVert = "layout(location = 0) in vec3 a_Position;\nlayout(location = 1) in vec4 a_Color;\nlayout(location = 9) in float a_Size;\nlayout(location = 13) in vec3 a_Normal;\nlayout(location = 14) in vec3 a_uvs;\n\n\nlayout(std140) uniform commonUniforms {\n vec4 u_sourceColor;\n vec4 u_targetColor;\n float u_linearColor;\n float u_topsurface;\n float u_sidesurface;\n float u_heightfixed; // \u9ED8\u8BA4\u4E0D\u56FA\u5B9A\n float u_raisingHeight;\n};\n\nout vec4 v_Color;\nout vec3 v_uvs;\nout vec2 v_texture_data;\n\n#pragma include \"projection\"\n#pragma include \"light\"\n#pragma include \"picking\"\n\nvoid main() {\n \n vec4 pos = vec4(a_Position.xy, a_Position.z * a_Size, 1.0);\n float lightWeight = calc_lighting(pos);\n vec4 project_pos = project_position(pos);\n v_uvs = a_uvs;\n v_Color = a_Color;\n v_Color.a *= opacity;\n \n v_texture_data = vec2(a_Position.z, lightWeight);\n\n if(u_heightfixed > 0.0) { // \u5224\u65AD\u51E0\u4F55\u4F53\u662F\u5426\u56FA\u5B9A\u9AD8\u5EA6\n project_pos.z = a_Position.z * a_Size;\n project_pos.z += u_raisingHeight;\n\n if(u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT || u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT_OFFSET) {\n float mapboxZoomScale = 4.0/pow(2.0, 21.0 - u_Zoom);\n project_pos.z *= mapboxZoomScale;\n project_pos.z += u_raisingHeight * mapboxZoomScale;\n }\n }\n\n\n gl_Position = project_common_position_to_clipspace_v2(vec4(project_pos.xyz, 1.0));\n\n\n\n setPickingColor(a_PickingColor);\n}\n"; // extrude picking
16
- import { ShaderLocation } from "../../core/CommonStyleAttribute";
17
- import { loadImage } from "../../utils/load-image";
18
11
  /* babel-plugin-inline-import '../shaders/extrude/polygon_extrude_picklight_frag.glsl' */
19
12
  const polygonExtrudePickLightFrag = "\nlayout(std140) uniform commonUniforms {\n vec4 u_sourceColor;\n vec4 u_targetColor;\n float u_linearColor;\n float u_topsurface;\n float u_sidesurface;\n float u_heightfixed; // \u9ED8\u8BA4\u4E0D\u56FA\u5B9A\n float u_raisingHeight;\n};\n\nin vec4 v_Color;\nin vec3 v_uvs;\nin vec2 v_texture_data;\nout vec4 outputColor;\n\n#pragma include \"scene_uniforms\"\n#pragma include \"picking\"\n\nvoid main() {\n float isSide = v_texture_data.x;\n float sidey = v_uvs[2];\n float lightWeight = v_texture_data.y;\n\n // Tip: \u90E8\u5206\u673A\u578B GPU \u8BA1\u7B97\u7CBE\u5EA6\u517C\u5BB9\n if(isSide < 0.999) {\n // side face\n if(u_sidesurface < 1.0) {\n discard;\n }\n \n if( u_linearColor == 1.0) {\n // side use linear\n vec4 linearColor = mix(u_targetColor, u_sourceColor, sidey);\n linearColor.rgb *= lightWeight;\n outputColor = linearColor;\n } else {\n // side notuse linear\n outputColor = v_Color;\n }\n } else {\n // top face\n if(u_topsurface < 1.0) {\n discard;\n }\n outputColor = v_Color;\n }\n\n outputColor = filterColorAlpha(outputColor, lightWeight);\n}\n";
20
13
  /* babel-plugin-inline-import '../shaders/extrude/polygon_extrude_picklight_vert.glsl' */
21
- const polygonExtrudePickLightVert = "layout(location = 0) in vec3 a_Position;\nlayout(location = 1) in vec4 a_Color;\nlayout(location = 9) in float a_Size;\nlayout(location = 13) in vec3 a_Normal;\nlayout(location = 14) in vec3 a_uvs;\n\n\nlayout(std140) uniform commonUniforms {\n vec4 u_sourceColor;\n vec4 u_targetColor;\n float u_linearColor;\n float u_topsurface;\n float u_sidesurface;\n float u_heightfixed; // \u9ED8\u8BA4\u4E0D\u56FA\u5B9A\n float u_raisingHeight;\n};\n\nout vec4 v_Color;\nout vec3 v_uvs;\nout vec2 v_texture_data;\n\n#pragma include \"projection\"\n#pragma include \"light\"\n#pragma include \"picking\"\n\nvoid main() {\n\n\n v_uvs = a_uvs;\n // cal style mapping - \u6570\u636E\u7EB9\u7406\u6620\u5C04\u90E8\u5206\u7684\u8BA1\u7B97\n vec4 pos = vec4(a_Position.xy, a_Position.z * a_Size, 1.0);\n vec4 project_pos = project_position(pos);\n\n if(u_heightfixed > 0.0) { // \u5224\u65AD\u51E0\u4F55\u4F53\u662F\u5426\u56FA\u5B9A\u9AD8\u5EA6\n project_pos.z = a_Position.z * a_Size;\n project_pos.z += u_raisingHeight;\n if(u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT || u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT_OFFSET) {\n float mapboxZoomScale = 4.0/pow(2.0, 21.0 - u_Zoom);\n project_pos.z *= mapboxZoomScale;\n project_pos.z += u_raisingHeight * mapboxZoomScale;\n }\n }\n\n gl_Position = project_common_position_to_clipspace_v2(vec4(project_pos.xyz, 1.0));\n float lightWeight = calc_lighting(pos);\n v_texture_data = vec2(a_Position.z,lightWeight);\n\n v_Color = vec4(a_Color.rgb * lightWeight, a_Color.w * opacity);\n\n setPickingColor(a_PickingColor);\n}\n";
14
+ const polygonExtrudePickLightVert = "layout(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;\nlayout(location = ATTRIBUTE_LOCATION_NORMAL) in vec3 a_Normal;\nlayout(location = ATTRIBUTE_LOCATION_UV) in vec3 a_uvs;\n\nlayout(std140) uniform commonUniforms {\n vec4 u_sourceColor;\n vec4 u_targetColor;\n float u_linearColor;\n float u_topsurface;\n float u_sidesurface;\n float u_heightfixed; // \u9ED8\u8BA4\u4E0D\u56FA\u5B9A\n float u_raisingHeight;\n};\n\nout vec4 v_Color;\nout vec3 v_uvs;\nout vec2 v_texture_data;\n\n#pragma include \"projection\"\n#pragma include \"light\"\n#pragma include \"picking\"\n\nvoid main() {\n v_uvs = a_uvs;\n // cal style mapping - \u6570\u636E\u7EB9\u7406\u6620\u5C04\u90E8\u5206\u7684\u8BA1\u7B97\n vec4 pos = vec4(a_Position.xy, a_Position.z * a_Size, 1.0);\n vec4 project_pos = project_position(pos, a_Position64Low);\n\n if (u_heightfixed > 0.0) {\n // \u5224\u65AD\u51E0\u4F55\u4F53\u662F\u5426\u56FA\u5B9A\u9AD8\u5EA6\n project_pos.z = a_Position.z * a_Size;\n project_pos.z += 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 project_pos.z *= mapboxZoomScale;\n project_pos.z += u_raisingHeight * mapboxZoomScale;\n }\n }\n\n gl_Position = project_common_position_to_clipspace(vec4(project_pos.xyz, 1.0));\n float lightWeight = calc_lighting(project_pos);\n v_texture_data = vec2(a_Position.z, lightWeight);\n\n v_Color = vec4(a_Color.rgb * lightWeight, a_Color.w * opacity);\n\n setPickingColor(a_PickingColor);\n}\n";
15
+ /* babel-plugin-inline-import '../shaders/extrude/polygon_extrude_vert.glsl' */
16
+ const polygonExtrudeVert = "layout(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;\nlayout(location = ATTRIBUTE_LOCATION_NORMAL) in vec3 a_Normal;\nlayout(location = ATTRIBUTE_LOCATION_UV) in vec3 a_uvs;\n\nlayout(std140) uniform commonUniforms {\n vec4 u_sourceColor;\n vec4 u_targetColor;\n float u_linearColor;\n float u_topsurface;\n float u_sidesurface;\n float u_heightfixed; // \u9ED8\u8BA4\u4E0D\u56FA\u5B9A\n float u_raisingHeight;\n};\n\nout vec4 v_Color;\n\n#pragma include \"projection\"\n#pragma include \"light\"\n#pragma include \"picking\"\n\nvoid main() {\n float isSide = a_Position.z;\n float topU = a_uvs[0];\n float topV = 1.0 - a_uvs[1];\n float sidey = a_uvs[2];\n\n vec4 pos = vec4(a_Position.xy, a_Position.z * a_Size, 1.0);\n\n vec4 project_pos = project_position(pos, a_Position64Low);\n float lightWeight = calc_lighting(project_pos);\n\n if (u_heightfixed > 0.0) {\n // \u5224\u65AD\u51E0\u4F55\u4F53\u662F\u5426\u56FA\u5B9A\u9AD8\u5EA6\n project_pos.z = a_Position.z * a_Size;\n project_pos.z += u_raisingHeight;\n\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 project_pos.z *= mapboxZoomScale;\n project_pos.z += u_raisingHeight * mapboxZoomScale;\n }\n }\n\n gl_Position = project_common_position_to_clipspace(vec4(project_pos.xyz, 1.0));\n\n // Tip: \u90E8\u5206\u673A\u578B GPU \u8BA1\u7B97\u7CBE\u5EA6\u517C\u5BB9\n if (isSide < 0.999) {\n // side face\n // if(u_sidesurface < 1.0) {\n // discard;\n // }\n\n if (u_linearColor == 1.0) {\n vec4 linearColor = mix(u_targetColor, u_sourceColor, sidey);\n linearColor.rgb *= lightWeight;\n v_Color = linearColor;\n } else {\n v_Color = a_Color;\n }\n\n } else {\n v_Color = a_Color;\n }\n\n v_Color = vec4(v_Color.rgb * lightWeight, v_Color.w * opacity);\n\n setPickingColor(a_PickingColor);\n}\n";
17
+ /* babel-plugin-inline-import '../shaders/extrude/polygon_extrudetex_frag.glsl' */
18
+ const polygonExtrudeTexFrag = "uniform sampler2D u_texture;\n\nlayout(std140) uniform commonUniforms {\n vec4 u_sourceColor;\n vec4 u_targetColor;\n float u_linearColor;\n float u_topsurface;\n float u_sidesurface;\n float u_heightfixed; // \u9ED8\u8BA4\u4E0D\u56FA\u5B9A\n float u_raisingHeight;\n};\n\nin vec4 v_Color;\nin vec3 v_uvs;\nin vec2 v_texture_data;\n\n#pragma include \"scene_uniforms\"\n#pragma include \"picking\"\n\nout vec4 outputColor;\n\nvoid main() {\n float opacity = u_opacity;\n float isSide = v_texture_data.x;\n float lightWeight = v_texture_data.y;\n float topU = v_uvs[0];\n float topV = 1.0 - v_uvs[1];\n float sidey = v_uvs[2];\n\n outputColor = texture(SAMPLER_2D(u_texture), vec2(topU, topV));\n // Tip: \u90E8\u5206\u673A\u578B GPU \u8BA1\u7B97\u7CBE\u5EA6\u517C\u5BB9\n if (isSide < 0.999) {// \u662F\u5426\u662F\u8FB9\u7F18\n // side face\n if (u_sidesurface < 1.0) {\n discard;\n }\n\n if (u_linearColor == 1.0) {\n vec4 linearColor = mix(u_targetColor, u_sourceColor, sidey);\n linearColor.rgb *= lightWeight;\n outputColor = linearColor;\n } else {\n outputColor = v_Color;\n }\n } else {\n // top face\n if (u_topsurface < 1.0) {\n discard;\n }\n }\n \n outputColor.a *= opacity;\n outputColor = filterColor(outputColor);\n}\n";
19
+ /* babel-plugin-inline-import '../shaders/extrude/polygon_extrudetex_vert.glsl' */
20
+ const polygonExtrudeTexVert = "layout(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;\nlayout(location = ATTRIBUTE_LOCATION_NORMAL) in vec3 a_Normal;\nlayout(location = ATTRIBUTE_LOCATION_UV) in vec3 a_uvs;\n\nlayout(std140) uniform commonUniforms {\n vec4 u_sourceColor;\n vec4 u_targetColor;\n float u_linearColor;\n float u_topsurface;\n float u_sidesurface;\n float u_heightfixed; // \u9ED8\u8BA4\u4E0D\u56FA\u5B9A\n float u_raisingHeight;\n};\n\nout vec4 v_Color;\nout vec3 v_uvs;\nout vec2 v_texture_data;\n\n#pragma include \"projection\"\n#pragma include \"light\"\n#pragma include \"picking\"\n\nvoid main() {\n vec4 pos = vec4(a_Position.xy, a_Position.z * a_Size, 1.0);\n vec4 project_pos = project_position(pos, a_Position64Low);\n float lightWeight = calc_lighting(project_pos);\n v_uvs = a_uvs;\n v_Color = a_Color;\n v_Color.a *= opacity;\n\n v_texture_data = vec2(a_Position.z, lightWeight);\n\n if (u_heightfixed > 0.0) {\n // \u5224\u65AD\u51E0\u4F55\u4F53\u662F\u5426\u56FA\u5B9A\u9AD8\u5EA6\n project_pos.z = a_Position.z * a_Size;\n project_pos.z += u_raisingHeight;\n\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 project_pos.z *= mapboxZoomScale;\n project_pos.z += u_raisingHeight * mapboxZoomScale;\n }\n }\n\n gl_Position = project_common_position_to_clipspace(vec4(project_pos.xyz, 1.0));\n\n setPickingColor(a_PickingColor);\n}\n";
22
21
  export default class ExtrudeModel extends BaseModel {
23
22
  constructor(...args) {
24
23
  super(...args);
25
24
  _defineProperty(this, "texture", void 0);
26
25
  }
26
+ get attributeLocation() {
27
+ return Object.assign(super.attributeLocation, {
28
+ MAX: super.attributeLocation.MAX,
29
+ SIZE: 9,
30
+ NORMAL: 10,
31
+ UV: 11
32
+ });
33
+ }
27
34
  getUninforms() {
28
35
  const commoninfo = this.getCommonUniformsInfo();
29
36
  const attributeInfo = this.getUniformsBufferInfo(this.getStyleAttribute());
@@ -91,6 +98,7 @@ export default class ExtrudeModel extends BaseModel {
91
98
  depth: {
92
99
  enable: true
93
100
  },
101
+ defines: _this2.getDefines(),
94
102
  inject: _this2.getInject(),
95
103
  triangulation: PolygonExtrudeTriangulation
96
104
  });
@@ -129,26 +137,18 @@ export default class ExtrudeModel extends BaseModel {
129
137
  this.textures = [];
130
138
  }
131
139
  registerBuiltinAttributes() {
132
- const bbox = this.layer.getSource().extent;
133
- let bounds = bbox;
134
- const layerCenter = this.layer.coordCenter || this.layer.getSource().center;
135
- let lngLen = bounds[2] - bounds[0];
136
- let latLen = bounds[3] - bounds[1];
137
- if (this.mapService.version === 'GAODE2.x') {
138
- // @ts-ignore
139
- const [minX, minY] = this.mapService.coordToAMap2RelativeCoordinates([bbox[0], bbox[1]], layerCenter);
140
- // @ts-ignore
141
- const [maxX, maxY] = this.mapService.coordToAMap2RelativeCoordinates([bbox[2], bbox[3]], layerCenter);
142
- lngLen = maxX - minX;
143
- latLen = maxY - minY;
144
- bounds = [minX, minY, maxX, maxY];
145
- }
140
+ const bounds = this.layer.getSource().extent;
141
+ const lngLen = bounds[2] - bounds[0];
142
+ const latLen = bounds[3] - bounds[1];
143
+
144
+ // 注册 Position 属性 64 位地位部分,经纬度数据开启双精度,避免大于 22 层级以上出现数据偏移
145
+ this.registerPosition64LowAttribute();
146
146
  this.styleAttributeService.registerStyleAttribute({
147
147
  name: 'uvs',
148
148
  type: AttributeType.Attribute,
149
149
  descriptor: {
150
150
  name: 'a_uvs',
151
- shaderLocation: ShaderLocation.UV,
151
+ shaderLocation: this.attributeLocation.UV,
152
152
  buffer: {
153
153
  // give the WebGL driver a hint that this buffer may change
154
154
  usage: gl.STATIC_DRAW,
@@ -169,7 +169,7 @@ export default class ExtrudeModel extends BaseModel {
169
169
  type: AttributeType.Attribute,
170
170
  descriptor: {
171
171
  name: 'a_Normal',
172
- shaderLocation: ShaderLocation.NORMAL,
172
+ shaderLocation: this.attributeLocation.NORMAL,
173
173
  buffer: {
174
174
  // give the WebGL driver a hint that this buffer may change
175
175
  usage: gl.STATIC_DRAW,
@@ -187,7 +187,7 @@ export default class ExtrudeModel extends BaseModel {
187
187
  type: AttributeType.Attribute,
188
188
  descriptor: {
189
189
  name: 'a_Size',
190
- shaderLocation: ShaderLocation.SIZE,
190
+ shaderLocation: this.attributeLocation.SIZE,
191
191
  buffer: {
192
192
  usage: gl.DYNAMIC_DRAW,
193
193
  data: [],
@@ -1,6 +1,22 @@
1
1
  import type { IModel, ITexture2D } from '@antv/l7-core';
2
2
  import BaseModel from '../../core/BaseModel';
3
3
  export default class ExtrusionModel extends BaseModel {
4
+ protected get attributeLocation(): {
5
+ readonly POSITION: 0;
6
+ readonly POSITION_64LOW: 1;
7
+ readonly COLOR: 2;
8
+ readonly PICKING_COLOR: 3;
9
+ readonly STROKE: 4;
10
+ readonly OPACITY: 5;
11
+ readonly OFFSETS: 6;
12
+ readonly ROTATION: 7;
13
+ readonly MAX: 8;
14
+ } & Record<string, number> & {
15
+ MAX: 8;
16
+ SIZE: number;
17
+ NORMAL: number;
18
+ EXTRUSION_BASE: number;
19
+ };
4
20
  protected texture: ITexture2D;
5
21
  getUninforms(): {
6
22
  [x: string]: any;
@@ -3,17 +3,24 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
3
  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
- import { ShaderLocation } from "../../core/CommonStyleAttribute";
7
6
  import { PolygonExtrudeTriangulation } from "../../core/triangulation";
8
7
  /* babel-plugin-inline-import '../shaders/extrusion/polygon_extrusion_frag.glsl' */
9
8
  const polygonExtrudeFrag = "\nin vec4 v_Color;\n#pragma include \"scene_uniforms\"\n#pragma include \"picking\"\nout vec4 outputColor;\nvoid main() {\n\n outputColor = v_Color;\n outputColor = filterColor(outputColor);\n}\n";
10
9
  /* babel-plugin-inline-import '../shaders/extrusion/polygon_extrusion_vert.glsl' */
11
- const polygonExtrudeVert = "layout(location = 0) in vec3 a_Position;\nlayout(location = 1) in vec4 a_Color;\nlayout(location = 9) in float a_Size;\nlayout(location = 13) in vec3 a_Normal;\n\nout vec4 v_Color;\n\n#pragma include \"projection\"\n#pragma include \"light\"\n#pragma include \"picking\"\n\nvoid main() {\n \n vec4 pos = vec4(a_Position.xy, a_Position.z * a_Size + (1.0 - a_Position.z) * extrusionBase, 1.0);\n\n vec4 project_pos = project_position(pos);\n float lightWeight = calc_lighting(project_pos);\n v_Color = a_Color;\n v_Color = vec4(v_Color.rgb * lightWeight, v_Color.w * opacity);\n\n gl_Position = project_common_position_to_clipspace_v2(vec4(project_pos.xyz, 1.0));\n\n setPickingColor(a_PickingColor);\n}\n";
10
+ const polygonExtrudeVert = "layout(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;\nlayout(location = ATTRIBUTE_LOCATION_NORMAL) in vec3 a_Normal;\n\nout vec4 v_Color;\n\n#pragma include \"projection\"\n#pragma include \"light\"\n#pragma include \"picking\"\n\nvoid main() {\n vec4 pos = vec4(a_Position.xy, a_Position.z * a_Size + (1.0 - a_Position.z) * extrusionBase, 1.0);\n\n vec4 project_pos = project_position(pos, a_Position64Low);\n float lightWeight = calc_lighting(project_pos);\n v_Color = a_Color;\n v_Color = vec4(v_Color.rgb * lightWeight, v_Color.w * opacity);\n\n gl_Position = project_common_position_to_clipspace(vec4(project_pos.xyz, 1.0));\n\n setPickingColor(a_PickingColor);\n}\n";
12
11
  export default class ExtrusionModel extends BaseModel {
13
12
  constructor(...args) {
14
13
  super(...args);
15
14
  _defineProperty(this, "texture", void 0);
16
15
  }
16
+ get attributeLocation() {
17
+ return Object.assign(super.attributeLocation, {
18
+ MAX: super.attributeLocation.MAX,
19
+ SIZE: 9,
20
+ NORMAL: 10,
21
+ EXTRUSION_BASE: 11
22
+ });
23
+ }
17
24
  getUninforms() {
18
25
  const commoninfo = this.getCommonUniformsInfo();
19
26
  const attributeInfo = this.getUniformsBufferInfo(this.getStyleAttribute());
@@ -44,6 +51,7 @@ export default class ExtrusionModel extends BaseModel {
44
51
  moduleName: type,
45
52
  vertexShader: vert,
46
53
  fragmentShader: frag,
54
+ defines: _this2.getDefines(),
47
55
  inject: _this2.getInject(),
48
56
  triangulation: PolygonExtrudeTriangulation,
49
57
  depth: {
@@ -65,12 +73,14 @@ export default class ExtrusionModel extends BaseModel {
65
73
  (_this$texture = this.texture) === null || _this$texture === void 0 || _this$texture.destroy();
66
74
  }
67
75
  registerBuiltinAttributes() {
76
+ // 注册 Position 属性 64 位地位部分,经纬度数据开启双精度,避免大于 22 层级以上出现数据偏移
77
+ this.registerPosition64LowAttribute();
68
78
  this.styleAttributeService.registerStyleAttribute({
69
79
  name: 'normal',
70
80
  type: AttributeType.Attribute,
71
81
  descriptor: {
72
82
  name: 'a_Normal',
73
- shaderLocation: ShaderLocation.NORMAL,
83
+ shaderLocation: this.attributeLocation.NORMAL,
74
84
  buffer: {
75
85
  // give the WebGL driver a hint that this buffer may change
76
86
  usage: gl.STATIC_DRAW,
@@ -88,7 +98,7 @@ export default class ExtrusionModel extends BaseModel {
88
98
  type: AttributeType.Attribute,
89
99
  descriptor: {
90
100
  name: 'a_Size',
91
- shaderLocation: ShaderLocation.SIZE,
101
+ shaderLocation: this.attributeLocation.SIZE,
92
102
  buffer: {
93
103
  usage: gl.DYNAMIC_DRAW,
94
104
  data: [],
@@ -103,5 +113,25 @@ export default class ExtrusionModel extends BaseModel {
103
113
  }
104
114
  }
105
115
  });
116
+ this.styleAttributeService.registerStyleAttribute({
117
+ name: 'extrusionBase',
118
+ type: AttributeType.Attribute,
119
+ descriptor: {
120
+ name: 'a_ExtrusionBase',
121
+ shaderLocation: this.attributeLocation.EXTRUSION_BASE,
122
+ buffer: {
123
+ usage: gl.STATIC_DRAW,
124
+ data: [],
125
+ type: gl.FLOAT
126
+ },
127
+ size: 1,
128
+ update: feature => {
129
+ const {
130
+ extrusionBase: op = 0
131
+ } = feature;
132
+ return [op];
133
+ }
134
+ }
135
+ });
106
136
  }
107
137
  }
@@ -1,6 +1,20 @@
1
1
  import type { IModel } from '@antv/l7-core';
2
2
  import BaseModel from '../../core/BaseModel';
3
3
  export default class FillModel extends BaseModel {
4
+ protected get attributeLocation(): {
5
+ readonly POSITION: 0;
6
+ readonly POSITION_64LOW: 1;
7
+ readonly COLOR: 2;
8
+ readonly PICKING_COLOR: 3;
9
+ readonly STROKE: 4;
10
+ readonly OPACITY: 5;
11
+ readonly OFFSETS: 6;
12
+ readonly ROTATION: 7;
13
+ readonly MAX: 8;
14
+ } & Record<string, number> & {
15
+ MAX: 8;
16
+ LINEAR: number;
17
+ };
4
18
  getUninforms(): {
5
19
  [x: string]: any;
6
20
  };
@@ -2,17 +2,22 @@ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
2
2
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
3
  import { AttributeType, gl } from '@antv/l7-core';
4
4
  import BaseModel from "../../core/BaseModel";
5
- import { ShaderLocation } from "../../core/CommonStyleAttribute";
6
5
  import { polygonTriangulation, polygonTriangulationWithCenter } from "../../core/triangulation";
7
6
  /* babel-plugin-inline-import '../shaders/fill/fill_frag.glsl' */
8
7
  const polygon_frag = "in vec4 v_color;\n#pragma include \"scene_uniforms\"\n#pragma include \"picking\"\nout vec4 outputColor;\nvoid main() {\n outputColor = v_color;\n outputColor = filterColor(outputColor);\n}\n";
9
8
  /* babel-plugin-inline-import '../shaders/fill/fill_linear_frag.glsl' */
10
9
  const polygon_linear_frag = "\nlayout(std140) uniform commonUniforms {\n float u_raisingHeight;\n float u_opacitylinear;\n float u_dir;\n};\n\nin vec4 v_color;\nin vec3 v_linear;\nin vec2 v_pos;\nout vec4 outputColor;\n#pragma include \"scene_uniforms\"\n#pragma include \"picking\"\n\nvoid main() {\n outputColor = v_color;\n if (u_opacitylinear > 0.0) {\n outputColor.a *= u_dir == 1.0 ? 1.0 - length(v_pos - v_linear.xy)/v_linear.z : length(v_pos - v_linear.xy)/v_linear.z;\n }\n outputColor = filterColor(outputColor);\n}\n";
11
10
  /* babel-plugin-inline-import '../shaders/fill/fill_linear_vert.glsl' */
12
- const polygon_linear_vert = "layout(location = 0) in vec3 a_Position;\nlayout(location = 1) in vec4 a_Color;\nlayout(location = 15) in vec3 a_linear;\n\nlayout(std140) uniform commonUniforms {\n float u_raisingHeight;\n float u_opacitylinear;\n float u_dir;\n};\n\nout vec4 v_color;\nout vec3 v_linear;\nout vec2 v_pos;\n\n#pragma include \"projection\"\n#pragma include \"picking\"\n\nvoid main() {\n if (u_opacitylinear > 0.0) {\n v_linear = a_linear;\n v_pos = a_Position.xy;\n }\n v_color = vec4(a_Color.xyz, a_Color.w * opacity);\n vec4 project_pos = project_position(vec4(a_Position, 1.0));\n project_pos.z += u_raisingHeight;\n\n if (u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT || u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT_OFFSET) {\n float mapboxZoomScale = 4.0/pow(2.0, 21.0 - u_Zoom);\n project_pos.z *= mapboxZoomScale;\n project_pos.z += u_raisingHeight * mapboxZoomScale;\n }\n\n gl_Position = project_common_position_to_clipspace_v2(vec4(project_pos.xyz, 1.0));\n setPickingColor(a_PickingColor);\n}";
11
+ const polygon_linear_vert = "layout(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_LINEAR) in vec3 a_linear;\n\nlayout(std140) uniform commonUniforms {\n float u_raisingHeight;\n float u_opacitylinear;\n float u_dir;\n};\n\nout vec4 v_color;\nout vec3 v_linear;\nout vec2 v_pos;\n\n#pragma include \"projection\"\n#pragma include \"picking\"\n\nvoid main() {\n if (u_opacitylinear > 0.0) {\n v_linear = a_linear;\n v_pos = a_Position.xy;\n }\n v_color = vec4(a_Color.xyz, a_Color.w * opacity);\n vec4 project_pos = project_position(vec4(a_Position, 1.0), a_Position64Low);\n project_pos.z += u_raisingHeight;\n\n if (u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT || u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT_OFFSET) {\n float mapboxZoomScale = 4.0/pow(2.0, 21.0 - u_Zoom);\n project_pos.z *= mapboxZoomScale;\n project_pos.z += u_raisingHeight * mapboxZoomScale;\n }\n\n gl_Position = project_common_position_to_clipspace(vec4(project_pos.xyz, 1.0));\n setPickingColor(a_PickingColor);\n}\n";
13
12
  /* babel-plugin-inline-import '../shaders/fill/fill_vert.glsl' */
14
- const polygon_vert = "layout(location = 0) in vec3 a_Position;\nlayout(location = 1) in vec4 a_Color;\n\nlayout(std140) uniform commonUniforms {\n float u_raisingHeight;\n};\n\n\nout vec4 v_color;\n\n\n#pragma include \"projection\"\n#pragma include \"picking\"\n\nvoid main() {\n // cal style mapping - \u6570\u636E\u7EB9\u7406\u6620\u5C04\u90E8\u5206\u7684\u8BA1\u7B97\n\n // cal style mapping - \u6570\u636E\u7EB9\u7406\u6620\u5C04\u90E8\u5206\u7684\u8BA1\u7B97\n\n v_color = vec4(a_Color.xyz, a_Color.w * opacity);\n vec4 project_pos = project_position(vec4(a_Position, 1.0));\n // gl_Position = project_common_position_to_clipspace(vec4(project_pos.xyz, 1.0));\n\n project_pos.z += u_raisingHeight;\n\n if(u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT || u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT_OFFSET) {\n float mapboxZoomScale = 4.0/pow(2.0, 21.0 - u_Zoom);\n project_pos.z *= mapboxZoomScale;\n project_pos.z += u_raisingHeight * mapboxZoomScale;\n }\n\n \n gl_Position = project_common_position_to_clipspace_v2(vec4(project_pos.xyz, 1.0));\n\n setPickingColor(a_PickingColor);\n}\n\n";
13
+ const polygon_vert = "layout(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;\n\nlayout(std140) uniform commonUniforms {\n float u_raisingHeight;\n};\n\nout vec4 v_color;\n\n#pragma include \"projection\"\n#pragma include \"picking\"\n\nvoid main() {\n // cal style mapping - \u6570\u636E\u7EB9\u7406\u6620\u5C04\u90E8\u5206\u7684\u8BA1\u7B97\n\n v_color = vec4(a_Color.xyz, a_Color.w * opacity);\n vec4 project_pos = project_position(vec4(a_Position, 1.0), a_Position64Low);\n\n project_pos.z += u_raisingHeight;\n\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 project_pos.z *= mapboxZoomScale;\n project_pos.z += u_raisingHeight * mapboxZoomScale;\n }\n\n gl_Position = project_common_position_to_clipspace(vec4(project_pos.xyz, 1.0));\n\n setPickingColor(a_PickingColor);\n}\n\n";
15
14
  export default class FillModel extends BaseModel {
15
+ get attributeLocation() {
16
+ return Object.assign(super.attributeLocation, {
17
+ MAX: super.attributeLocation.MAX,
18
+ LINEAR: 9
19
+ });
20
+ }
16
21
  getUninforms() {
17
22
  const commoninfo = this.getCommonUniformsInfo();
18
23
  const attributeInfo = this.getUniformsBufferInfo(this.getStyleAttribute());
@@ -56,6 +61,7 @@ export default class FillModel extends BaseModel {
56
61
  moduleName: type,
57
62
  vertexShader: vert,
58
63
  fragmentShader: frag,
64
+ defines: _this2.getDefines(),
59
65
  inject: _this2.getInject(),
60
66
  triangulation,
61
67
  primitive: gl.TRIANGLES,
@@ -67,6 +73,8 @@ export default class FillModel extends BaseModel {
67
73
  })();
68
74
  }
69
75
  registerBuiltinAttributes() {
76
+ // 注册 Position 属性 64 位地位部分,经纬度数据开启双精度,避免大于 22 层级以上出现数据偏移
77
+ this.registerPosition64LowAttribute();
70
78
  const {
71
79
  opacityLinear = {
72
80
  enable: false,
@@ -79,7 +87,7 @@ export default class FillModel extends BaseModel {
79
87
  type: AttributeType.Attribute,
80
88
  descriptor: {
81
89
  name: 'a_linear',
82
- shaderLocation: ShaderLocation.LINEAR,
90
+ shaderLocation: this.attributeLocation.LINEAR,
83
91
  buffer: {
84
92
  // give the WebGL driver a hint that this buffer may change
85
93
  usage: gl.STATIC_DRAW,
@@ -1,6 +1,20 @@
1
1
  import type { IModel, IModelUniform } from '@antv/l7-core';
2
2
  import BaseModel from '../../core/BaseModel';
3
3
  export default class OceanModel extends BaseModel {
4
+ protected get attributeLocation(): {
5
+ readonly POSITION: 0;
6
+ readonly POSITION_64LOW: 1;
7
+ readonly COLOR: 2;
8
+ readonly PICKING_COLOR: 3;
9
+ readonly STROKE: 4;
10
+ readonly OPACITY: 5;
11
+ readonly OFFSETS: 6;
12
+ readonly ROTATION: 7;
13
+ readonly MAX: 8;
14
+ } & Record<string, number> & {
15
+ MAX: 8;
16
+ UV: number;
17
+ };
4
18
  private texture1;
5
19
  private texture2;
6
20
  private texture3;
@@ -4,12 +4,11 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
4
4
  import { AttributeType, gl } from '@antv/l7-core';
5
5
  import { rgb2arr } from '@antv/l7-utils';
6
6
  import BaseModel from "../../core/BaseModel";
7
- import { ShaderLocation } from "../../core/CommonStyleAttribute";
8
7
  import { polygonTriangulation } from "../../core/triangulation";
9
8
  /* babel-plugin-inline-import '../shaders/ocean/ocean_frag.glsl' */
10
9
  const ocean_frag = "\nlayout(std140) uniform commonUniforms {\n vec4 u_watercolor;\n vec4 u_watercolor2;\n float u_time;\n};\n\nin vec2 v_uv;\nin float v_opacity;\nout vec4 outputColor;\n\nfloat coast2water_fadedepth = 0.10;\nfloat large_waveheight = .750; // change to adjust the \"heavy\" waves\nfloat large_wavesize = 3.4; // factor to adjust the large wave size\nfloat small_waveheight = 0.6; // change to adjust the small random waves\nfloat small_wavesize = 0.5; // factor to ajust the small wave size\nfloat water_softlight_fact = 15.; // range [1..200] (should be << smaller than glossy-fact)\nfloat water_glossylight_fact= 120.; // range [1..200]\nfloat particle_amount = 70.;\n\nvec3 water_specularcolor = vec3(1.3, 1.3, 0.9); // specular Color (RGB) of the water-highlights\n#define light vec3(-0., sin(u_time*0.5)*.5 + .35, 2.8) // position of the sun\n\nuniform sampler2D u_texture1;\nuniform sampler2D u_texture2;\nuniform sampler2D u_texture3;\n\n \n\nfloat hash( float n ) {\n return fract(sin(n)*43758.5453123);\n}\n\n// 2d noise function\nfloat noise1( in vec2 x ) {\n vec2 p = floor(x);\n vec2 f = smoothstep(0.0, 1.0, fract(x));\n float n = p.x + p.y*57.0;\n return mix(mix( hash(n+ 0.0), hash(n+ 1.0),f.x),\n mix( hash(n+ 57.0), hash(n+ 58.0),f.x),f.y);\n}\n\nfloat noise(vec2 p) {\n return texture(SAMPLER_2D(u_texture2),p*vec2(1./256.)).x;\n}\n\nvec4 highness(vec2 p) {\n vec4 t = texture(SAMPLER_2D(u_texture1),fract(p));\n float clipped = -2.0-smoothstep(3.,10.,t.a)*6.9-smoothstep(10.,100.,t.a)*89.9-smoothstep(0.,10000.,t.a)*10000.0;\n return clamp(t, 0.0,3.0)+clamp(t/3.0-1.0, 0.0,1.0)+clamp(t/16.0-1.0, 0.0,1.0);\n}\n\nfloat height_map( vec2 p ) {\n vec4 height=highness(p);\n /*\n height = -0.5+\n 0.5*smoothstep(-100.,0.,-height)+\n 2.75*smoothstep(0.,2.,height)+\n 1.75*smoothstep(2.,4.,height)+\n 2.75*smoothstep(4.,16.,height)+\n 1.5*smoothstep(16.,1000.,height);\n */\n\n mat2 m = mat2( 0.9563*1.4, -0.2924*1.4, 0.2924*1.4, 0.9563*1.4 );\n //p = p*6.;\n float f = 0.6000*noise1( p ); p = m*p*1.1*6.;\n f += 0.2500*noise( p ); p = m*p*1.32;\n f += 0.1666*noise( p ); p = m*p*1.11;\n f += 0.0834*noise( p ); p = m*p*1.12;\n f += 0.0634*noise( p ); p = m*p*1.13;\n f += 0.0444*noise( p ); p = m*p*1.14;\n f += 0.0274*noise( p ); p = m*p*1.15;\n f += 0.0134*noise( p ); p = m*p*1.16;\n f += 0.0104*noise( p ); p = m*p*1.17;\n f += 0.0084*noise( p );\n f = .25*f+dot(height,vec4(-.03125,-.125,.25,.25))*.5;\n const float FLAT_LEVEL = 0.92525;\n //f = f*0.25+height*0.75;\n if (f<FLAT_LEVEL)\n f = f;\n else\n f = pow((f-FLAT_LEVEL)/(1.-FLAT_LEVEL), 2.)*(1.-FLAT_LEVEL)*2.0+FLAT_LEVEL; // makes a smooth coast-increase\n return clamp(f, 0., 10.);\n}\n\nvec3 plasma_quintic( float x ) {\n x = clamp( x, 0.0, 1.0);\n vec4 x1 = vec4( 1.0, x, x * x, x * x * x ); // 1 x x2 x3\n vec4 x2 = x1 * x1.w * x; // x4 x5 x6 x7\n return vec3(\n dot( x1.xyzw, vec4( +0.063861086, +1.992659096, -1.023901152, -0.490832805 ) ) + dot( x2.xy, vec2( +1.308442123, -0.914547012 ) ),\n dot( x1.xyzw, vec4( +0.049718590, -0.791144343, +2.892305078, +0.811726816 ) ) + dot( x2.xy, vec2( -4.686502417, +2.717794514 ) ),\n dot( x1.xyzw, vec4( +0.513275779, +1.580255060, -5.164414457, +4.559573646 ) ) + dot( x2.xy, vec2( -1.916810682, +0.570638854 ) ) );\n}\n\nvec4 color(vec2 p){\n vec4 c1 = vec4(1.7,1.6,.9,1);\n vec4 c2 = vec4(.2,.94,.1,1);\n vec4 c3 = vec4(.3,.2,.0,1);\n vec4 c4 = vec4(.99,.99,1.6,1);\n vec4 v = highness(p);\n float los = smoothstep(0.1,1.1,v.b);\n float his = smoothstep(3.5,6.5,v.b);\n float ces = smoothstep(1.,5.,v.a);\n vec4 lo = mix(c1,c2,los);\n vec4 hi = mix(c3,c4,his);\n vec4 ce = mix(lo,hi,ces);\n\n return vec4(plasma_quintic(ces),1).ragb;\n}\n\nvec3 terrain_map( vec2 p )\n{\n return color(p).rgb*0.75+0.25*vec3(0.7, .55, .4)+texture(SAMPLER_2D(u_texture3), fract(p*5.)).rgb*.5; // test-terrain is simply 'sandstone'\n}\n\nconst mat2 m = mat2( 0.72, -1.60, 1.60, 0.72 );\n\nfloat water_map( vec2 p, float height ) {\n vec2 p2 = p*large_wavesize;\n vec2 shift1 = 0.001*vec2( u_time*160.0*2.0, u_time*120.0*2.0 );\n vec2 shift2 = 0.001*vec2( u_time*190.0*2.0, -u_time*130.0*2.0 );\n\n // coarse crossing 'ocean' waves...\n float f = 0.6000*noise( p );\n f += 0.2500*noise( p*m );\n f += 0.1666*noise( p*m*m );\n float wave = sin(p2.x*0.622+p2.y*0.622+shift2.x*4.269)*large_waveheight*f*height*height ;\n\n p *= small_wavesize;\n f = 0.;\n float amp = 1.0, s = .5;\n for (int i=0; i<9; i++)\n { p = m*p*.947; f -= amp*abs(sin((noise( p+shift1*s )-.5)*2.)); amp = amp*.59; s*=-1.329; }\n \n return wave+f*small_waveheight;\n}\n\nfloat nautic(vec2 p) {\n p *= 18.;\n float f = 0.;\n float amp = 1.0, s = .5;\n for (int i=0; i<3; i++)\n { p = m*p*1.2; f += amp*abs(smoothstep(0., 1., noise( p+u_time*s ))-.5); amp = amp*.5; s*=-1.227; }\n return pow(1.-f, 5.);\n}\n\nfloat particles(vec2 p) {\n p *= 200.;\n float f = 0.;\n float amp = 1.0, s = 1.5;\n for (int i=0; i<3; i++)\n { p = m*p*1.2; f += amp*noise( p+u_time*s ); amp = amp*.5; s*=-1.227; }\n return pow(f*.35, 7.)*particle_amount;\n}\n\nfloat test_shadow( vec2 xy, float height) {\n vec3 r0 = vec3(xy, height);\n vec3 rd = normalize( light - r0 );\n \n float hit = 1.0;\n float t = 0.001;\n for (int j=1; j<25; j++)\n {\n vec3 p = r0 + t*rd;\n float h = height_map( p.xy );\n float height_diff = p.z - h;\n if (height_diff<0.0)\n {\n return 0.0;\n }\n t += 0.01+height_diff*.02;\n hit = min(hit, 2.*height_diff/t); // soft shaddow \n }\n return hit;\n}\n\nvec3 CalcTerrain(vec2 uv, float height) {\n vec3 col = terrain_map( uv );\n vec2 iResolution = vec2(512.);\n float h1 = height_map(uv-vec2(0., 0.5)/ iResolution.xy);\n float h2 = height_map(uv+vec2(0., 0.5)/ iResolution.xy);\n float h3 = height_map(uv-vec2(0.5, 0.)/ iResolution.xy);\n float h4 = height_map(uv+vec2(0.5, 0.)/ iResolution.xy);\n vec3 norm = normalize(vec3(h3-h4, h1-h2, 1.));\n vec3 r0 = vec3(uv, height);\n vec3 rd = normalize( light - r0 );\n float grad = dot(norm, rd);\n col *= grad+pow(grad, 8.);\n float terrainshade = test_shadow( uv, height );\n col = mix(col*.25, col, terrainshade);\n return col;\n}\n\n\nvoid main() {\n vec3 watercolor = u_watercolor.rgb;\n vec3 watercolor2 = u_watercolor2.rgb;\n vec2 uv = v_uv;\n float WATER_LEVEL = 0.84; // Water level (range: 0.0 - 2.0)\n float deepwater_fadedepth = 0.4 + coast2water_fadedepth;\n float height = height_map( uv );\n vec3 col;\n\n float waveheight = clamp(WATER_LEVEL*3.-1.5, 0., 1.);\n float level = WATER_LEVEL + .2*water_map(uv*15. + vec2(u_time*.1), waveheight);\n if (height > level)\n {\n col = CalcTerrain(uv, height);\n }\n if (height <= level)\n {\n vec2 dif = vec2(.0, .01);\n vec2 pos = uv*15. + vec2(u_time*.01);\n float h1 = water_map(pos-dif,waveheight);\n float h2 = water_map(pos+dif,waveheight);\n float h3 = water_map(pos-dif.yx,waveheight);\n float h4 = water_map(pos+dif.yx,waveheight);\n vec3 normwater = normalize(vec3(h3-h4, h1-h2, .125)); // norm-vector of the 'bumpy' water-plane\n uv += normwater.xy*.002*(level-height);\n \n col = CalcTerrain(uv, height);\n\n float coastfade = clamp((level-height)/coast2water_fadedepth, 0., 1.);\n float coastfade2= clamp((level-height)/deepwater_fadedepth, 0., 1.);\n float intensity = col.r*.2126+col.g*.7152+col.b*.0722;\n watercolor = mix(watercolor*intensity, watercolor2, smoothstep(0., 1., coastfade2));\n\n vec3 r0 = vec3(uv, WATER_LEVEL);\n vec3 rd = normalize( light - r0 ); // ray-direction to the light from water-position\n float grad = dot(normwater, rd); // dot-product of norm-vector and light-direction\n float specular = pow(grad, water_softlight_fact); // used for soft highlights \n float specular2= pow(grad, water_glossylight_fact); // used for glossy highlights\n float gradpos = dot(vec3(0., 0., 1.), rd);\n float specular1= smoothstep(0., 1., pow(gradpos, 5.)); // used for diffusity (some darker corona around light's specular reflections...) \n float watershade = test_shadow( uv, level );\n watercolor *= 2.2+watershade;\n watercolor += (.2+.8*watershade) * ((grad-1.0)*.5+specular) * .25;\n watercolor /= (1.+specular1*1.25);\n watercolor += watershade*specular2*water_specularcolor;\n watercolor += watershade*coastfade*(1.-coastfade2)*(vec3(.5, .6, .7)*nautic(uv)+vec3(1., 1., 1.)*particles(uv));\n \n col = mix(col, watercolor, coastfade);\n }\n \n outputColor = vec4(col, v_opacity); \n}\n";
11
10
  /* babel-plugin-inline-import '../shaders/ocean/ocean_vert.glsl' */
12
- const ocean_vert = "layout(location = 0) in vec3 a_Position;\nlayout(location = 14) in vec2 a_uv;\n\nlayout(std140) uniform commonUniforms {\n vec4 u_watercolor;\n vec4 u_watercolor2;\n float u_time;\n};\n\n\nout vec2 v_uv;\nout float v_opacity;\n\n#pragma include \"projection\"\n\nvoid main() {\n v_uv = a_uv;\n v_opacity = opacity;\n vec4 project_pos = project_position(vec4(a_Position, 1.0));\n gl_Position = project_common_position_to_clipspace_v2(vec4(project_pos.xyz, 1.0));\n}\n\n";
11
+ const ocean_vert = "layout(location = ATTRIBUTE_LOCATION_POSITION) in vec3 a_Position;\nlayout(location = ATTRIBUTE_LOCATION_UV) in vec2 a_uv;\n\nlayout(std140) uniform commonUniforms {\n vec4 u_watercolor;\n vec4 u_watercolor2;\n float u_time;\n};\n\nout vec2 v_uv;\nout float v_opacity;\n\n#pragma include \"projection\"\n\nvoid main() {\n v_uv = a_uv;\n v_opacity = opacity;\n vec4 project_pos = project_position(vec4(a_Position, 1.0));\n gl_Position = project_common_position_to_clipspace(vec4(project_pos.xyz, 1.0));\n}\n\n";
13
12
  export default class OceanModel extends BaseModel {
14
13
  constructor(...args) {
15
14
  super(...args);
@@ -17,6 +16,12 @@ export default class OceanModel extends BaseModel {
17
16
  _defineProperty(this, "texture2", void 0);
18
17
  _defineProperty(this, "texture3", void 0);
19
18
  }
19
+ get attributeLocation() {
20
+ return Object.assign(super.attributeLocation, {
21
+ MAX: super.attributeLocation.MAX,
22
+ UV: 9
23
+ });
24
+ }
20
25
  getUninforms() {
21
26
  const commoninfo = this.getCommonUniformsInfo();
22
27
  const attributeInfo = this.getUniformsBufferInfo(this.getStyleAttribute());
@@ -62,6 +67,7 @@ export default class OceanModel extends BaseModel {
62
67
  moduleName: 'polygonOcean',
63
68
  vertexShader: ocean_vert,
64
69
  fragmentShader: ocean_frag,
70
+ defines: _this2.getDefines(),
65
71
  inject: _this2.getInject(),
66
72
  triangulation: polygonTriangulation,
67
73
  primitive: gl.TRIANGLES,
@@ -88,7 +94,7 @@ export default class OceanModel extends BaseModel {
88
94
  type: AttributeType.Attribute,
89
95
  descriptor: {
90
96
  name: 'a_uv',
91
- shaderLocation: ShaderLocation.UV,
97
+ shaderLocation: this.attributeLocation.UV,
92
98
  buffer: {
93
99
  // give the WebGL driver a hint that this buffer may change
94
100
  usage: gl.STATIC_DRAW,
@@ -96,9 +102,8 @@ export default class OceanModel extends BaseModel {
96
102
  type: gl.FLOAT
97
103
  },
98
104
  size: 2,
99
- update: (feature, featureIdx, vertex, attributeIdx) => {
100
- const v = feature.version === 'GAODE2.x' ? feature.originCoordinates[0][attributeIdx] : vertex;
101
- const [lng, lat] = v;
105
+ update: (feature, featureIdx, vertex) => {
106
+ const [lng, lat] = vertex;
102
107
  return [(lng - minLng) / lngLen, (lat - minLat) / latLen];
103
108
  }
104
109
  }
@@ -1,6 +1,20 @@
1
1
  import type { IModel, IModelUniform } from '@antv/l7-core';
2
2
  import BaseModel from '../../core/BaseModel';
3
3
  export default class WaterModel extends BaseModel {
4
+ protected get attributeLocation(): {
5
+ readonly POSITION: 0;
6
+ readonly POSITION_64LOW: 1;
7
+ readonly COLOR: 2;
8
+ readonly PICKING_COLOR: 3;
9
+ readonly STROKE: 4;
10
+ readonly OPACITY: 5;
11
+ readonly OFFSETS: 6;
12
+ readonly ROTATION: 7;
13
+ readonly MAX: 8;
14
+ } & Record<string, number> & {
15
+ MAX: 8;
16
+ UV: number;
17
+ };
4
18
  private texture;
5
19
  getUninforms(): {
6
20
  [x: string]: any;
@@ -3,17 +3,22 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
3
  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
- import { ShaderLocation } from "../../core/CommonStyleAttribute";
7
6
  import { polygonTriangulation } from "../../core/triangulation";
8
7
  /* babel-plugin-inline-import '../shaders/water/polygon_water_frag.glsl' */
9
8
  const water_frag = "uniform sampler2D u_texture;\nlayout(std140) uniform commonUniforms {\n float u_speed;\n float u_time;\n};\n\nout vec4 outputColor;\n\n\nin vec4 v_Color;\nin vec2 v_uv;\n\nfloat rand(vec2 n) { return 0.5 + 0.5 * fract(sin(dot(n.xy, vec2(12.9898, 78.233)))* 43758.5453); }\n\nfloat water(vec3 p) {\n float t = u_time * u_speed;\n p.z += t * 2.; p.x += t * 2.;\n vec3 c1 = texture(SAMPLER_2D(u_texture), p.xz / 30.).xyz;\n p.z += t * 3.; p.x += t * 0.52;\n vec3 c2 = texture(SAMPLER_2D(u_texture), p.xz / 30.).xyz;\n p.z += t * 4.; p.x += t * 0.8;\n vec3 c3 = texture(SAMPLER_2D(u_texture), p.xz / 30.).xyz;\n c1 += c2 - c3;\n float z = (c1.x + c1.y + c1.z) / 3.;\n return p.y + z / 4.;\n}\n\nfloat map(vec3 p) {\n float d = 100.0;\n d = water(p);\n return d;\n}\n\nfloat intersect(vec3 ro, vec3 rd) {\n float d = 0.0;\n for (int i = 0; i <= 100; i++) {\n float h = map(ro + rd * d);\n if (h < 0.1) return d;\n d += h;\n }\n return 0.0;\n}\n\nvec3 norm(vec3 p) {\n float eps = .1;\n return normalize(vec3(\n map(p + vec3(eps, 0, 0)) - map(p + vec3(-eps, 0, 0)),\n map(p + vec3(0, eps, 0)) - map(p + vec3(0, -eps, 0)),\n map(p + vec3(0, 0, eps)) - map(p + vec3(0, 0, -eps))\n ));\n} \n\nfloat calSpc() {\n vec3 l1 = normalize(vec3(1, 1, 1));\n vec3 ro = vec3(-3, 20, -8);\n vec3 rc = vec3(0, 0, 0);\n vec3 ww = normalize(rc - ro);\n vec3 uu = normalize(cross(vec3(0,1,0), ww));\n vec3 vv = normalize(cross(rc - ro, uu));\n vec3 rd = normalize(uu * v_uv.x + vv * v_uv.y + ww);\n float d = intersect(ro, rd);\n vec3 p = ro + rd * d;\n vec3 n = norm(p);\n float spc = pow(max(0.0, dot(reflect(l1, n), rd)), 30.0);\n return spc;\n}\n\nvoid main() {\n\n outputColor = v_Color;\n float spc = calSpc();\n outputColor += spc * 0.4;\n}\n";
10
9
  /* babel-plugin-inline-import '../shaders/water/polygon_water_vert.glsl' */
11
- const water_vert = "layout(location = 0) in vec3 a_Position;\nlayout(location = 1) in vec4 a_Color;\nlayout(location = 14) in vec2 a_uv;\nlayout(std140) uniform commonUniforms {\n float u_speed;\n float u_time;\n};\nout vec4 v_Color;\nout vec2 v_uv;\n\n\n#pragma include \"projection\"\n\nvoid main() {\n v_uv = a_uv;\n v_Color = a_Color;\n v_Color.a *= opacity;\n vec4 project_pos = project_position(vec4(a_Position, 1.0));\n\n gl_Position = project_common_position_to_clipspace_v2(vec4(project_pos.xyz, 1.0));\n}\n\n";
10
+ const water_vert = "layout(location = ATTRIBUTE_LOCATION_POSITION) in vec3 a_Position;\nlayout(location = ATTRIBUTE_LOCATION_COLOR) in vec4 a_Color;\nlayout(location = ATTRIBUTE_LOCATION_UV) in vec2 a_uv;\n\nlayout(std140) uniform commonUniforms {\n float u_speed;\n float u_time;\n};\nout vec4 v_Color;\nout vec2 v_uv;\n\n#pragma include \"projection\"\n\nvoid main() {\n v_uv = a_uv;\n v_Color = a_Color;\n v_Color.a *= opacity;\n vec4 project_pos = project_position(vec4(a_Position, 1.0));\n\n gl_Position = project_common_position_to_clipspace(vec4(project_pos.xyz, 1.0));\n}\n\n";
12
11
  export default class WaterModel extends BaseModel {
13
12
  constructor(...args) {
14
13
  super(...args);
15
14
  _defineProperty(this, "texture", void 0);
16
15
  }
16
+ get attributeLocation() {
17
+ return Object.assign(super.attributeLocation, {
18
+ MAX: super.attributeLocation.MAX,
19
+ UV: 9
20
+ });
21
+ }
17
22
  getUninforms() {
18
23
  const commoninfo = this.getCommonUniformsInfo();
19
24
  const attributeInfo = this.getUniformsBufferInfo(this.getStyleAttribute());
@@ -56,6 +61,7 @@ export default class WaterModel extends BaseModel {
56
61
  vertexShader: water_vert,
57
62
  fragmentShader: water_frag,
58
63
  triangulation: polygonTriangulation,
64
+ defines: _this2.getDefines(),
59
65
  inject: _this2.getInject(),
60
66
  primitive: gl.TRIANGLES,
61
67
  depth: {
@@ -81,7 +87,7 @@ export default class WaterModel extends BaseModel {
81
87
  type: AttributeType.Attribute,
82
88
  descriptor: {
83
89
  name: 'a_uv',
84
- shaderLocation: ShaderLocation.UV,
90
+ shaderLocation: this.attributeLocation.UV,
85
91
  buffer: {
86
92
  // give the WebGL driver a hint that this buffer may change
87
93
  usage: gl.STATIC_DRAW,
@@ -89,9 +95,8 @@ export default class WaterModel extends BaseModel {
89
95
  type: gl.FLOAT
90
96
  },
91
97
  size: 2,
92
- update: (feature, featureIdx, vertex, attributeIdx) => {
93
- const v = feature.version === 'GAODE2.x' ? feature.originCoordinates[0][attributeIdx] : vertex;
94
- const [lng, lat] = v;
98
+ update: (feature, featureIdx, vertex) => {
99
+ const [lng, lat] = vertex;
95
100
  return [(lng - minLng) / lngLen, (lat - minLat) / latLen];
96
101
  }
97
102
  }
@@ -1,9 +1,9 @@
1
- layout(location = 0) in vec3 a_Position;
2
- layout(location = 1) in vec4 a_Color;
3
- layout(location = 9) in float a_Size;
4
- layout(location = 13) in vec3 a_Normal;
5
- layout(location = 14) in vec3 a_uvs;
6
-
1
+ layout(location = ATTRIBUTE_LOCATION_POSITION) in vec3 a_Position;
2
+ layout(location = ATTRIBUTE_LOCATION_POSITION_64LOW) in vec2 a_Position64Low;
3
+ layout(location = ATTRIBUTE_LOCATION_COLOR) in vec4 a_Color;
4
+ layout(location = ATTRIBUTE_LOCATION_SIZE) in float a_Size;
5
+ layout(location = ATTRIBUTE_LOCATION_NORMAL) in vec3 a_Normal;
6
+ layout(location = ATTRIBUTE_LOCATION_UV) in vec3 a_uvs;
7
7
 
8
8
  layout(std140) uniform commonUniforms {
9
9
  vec4 u_sourceColor;
@@ -24,26 +24,28 @@ out vec2 v_texture_data;
24
24
  #pragma include "picking"
25
25
 
26
26
  void main() {
27
-
28
-
29
27
  v_uvs = a_uvs;
30
28
  // cal style mapping - 数据纹理映射部分的计算
31
29
  vec4 pos = vec4(a_Position.xy, a_Position.z * a_Size, 1.0);
32
- vec4 project_pos = project_position(pos);
30
+ vec4 project_pos = project_position(pos, a_Position64Low);
33
31
 
34
- if(u_heightfixed > 0.0) { // 判断几何体是否固定高度
32
+ if (u_heightfixed > 0.0) {
33
+ // 判断几何体是否固定高度
35
34
  project_pos.z = a_Position.z * a_Size;
36
35
  project_pos.z += u_raisingHeight;
37
- if(u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT || u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT_OFFSET) {
38
- float mapboxZoomScale = 4.0/pow(2.0, 21.0 - u_Zoom);
36
+ if (
37
+ u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT ||
38
+ u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT_OFFSET
39
+ ) {
40
+ float mapboxZoomScale = 4.0 / pow(2.0, 21.0 - u_Zoom);
39
41
  project_pos.z *= mapboxZoomScale;
40
42
  project_pos.z += u_raisingHeight * mapboxZoomScale;
41
43
  }
42
44
  }
43
45
 
44
- gl_Position = project_common_position_to_clipspace_v2(vec4(project_pos.xyz, 1.0));
45
- float lightWeight = calc_lighting(pos);
46
- v_texture_data = vec2(a_Position.z,lightWeight);
46
+ gl_Position = project_common_position_to_clipspace(vec4(project_pos.xyz, 1.0));
47
+ float lightWeight = calc_lighting(project_pos);
48
+ v_texture_data = vec2(a_Position.z, lightWeight);
47
49
 
48
50
  v_Color = vec4(a_Color.rgb * lightWeight, a_Color.w * opacity);
49
51
 
@@ -1,8 +1,9 @@
1
- layout(location = 0) in vec3 a_Position;
2
- layout(location = 1) in vec4 a_Color;
3
- layout(location = 9) in float a_Size;
4
- layout(location = 13) in vec3 a_Normal;
5
- layout(location = 14) in vec3 a_uvs;
1
+ layout(location = ATTRIBUTE_LOCATION_POSITION) in vec3 a_Position;
2
+ layout(location = ATTRIBUTE_LOCATION_POSITION_64LOW) in vec2 a_Position64Low;
3
+ layout(location = ATTRIBUTE_LOCATION_COLOR) in vec4 a_Color;
4
+ layout(location = ATTRIBUTE_LOCATION_SIZE) in float a_Size;
5
+ layout(location = ATTRIBUTE_LOCATION_NORMAL) in vec3 a_Normal;
6
+ layout(location = ATTRIBUTE_LOCATION_UV) in vec3 a_uvs;
6
7
 
7
8
  layout(std140) uniform commonUniforms {
8
9
  vec4 u_sourceColor;
@@ -21,39 +22,41 @@ out vec4 v_Color;
21
22
  #pragma include "picking"
22
23
 
23
24
  void main() {
24
-
25
- float isSide = a_Position.z;
26
- float topU = a_uvs[0];
27
- float topV = 1.0 - a_uvs[1];
28
- float sidey = a_uvs[2];
25
+ float isSide = a_Position.z;
26
+ float topU = a_uvs[0];
27
+ float topV = 1.0 - a_uvs[1];
28
+ float sidey = a_uvs[2];
29
29
 
30
30
  vec4 pos = vec4(a_Position.xy, a_Position.z * a_Size, 1.0);
31
- float lightWeight = calc_lighting(pos);
32
31
 
33
- vec4 project_pos = project_position(pos);
32
+ vec4 project_pos = project_position(pos, a_Position64Low);
33
+ float lightWeight = calc_lighting(project_pos);
34
34
 
35
- if(u_heightfixed > 0.0) { // 判断几何体是否固定高度
35
+ if (u_heightfixed > 0.0) {
36
+ // 判断几何体是否固定高度
36
37
  project_pos.z = a_Position.z * a_Size;
37
38
  project_pos.z += u_raisingHeight;
38
39
 
39
- if(u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT || u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT_OFFSET) {
40
- float mapboxZoomScale = 4.0/pow(2.0, 21.0 - u_Zoom);
40
+ if (
41
+ u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT ||
42
+ u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT_OFFSET
43
+ ) {
44
+ float mapboxZoomScale = 4.0 / pow(2.0, 21.0 - u_Zoom);
41
45
  project_pos.z *= mapboxZoomScale;
42
46
  project_pos.z += u_raisingHeight * mapboxZoomScale;
43
47
  }
44
48
  }
45
49
 
46
-
47
- gl_Position = project_common_position_to_clipspace_v2(vec4(project_pos.xyz, 1.0));
50
+ gl_Position = project_common_position_to_clipspace(vec4(project_pos.xyz, 1.0));
48
51
 
49
52
  // Tip: 部分机型 GPU 计算精度兼容
50
- if(isSide < 0.999) {
53
+ if (isSide < 0.999) {
51
54
  // side face
52
55
  // if(u_sidesurface < 1.0) {
53
56
  // discard;
54
57
  // }
55
58
 
56
- if(u_linearColor == 1.0) {
59
+ if (u_linearColor == 1.0) {
57
60
  vec4 linearColor = mix(u_targetColor, u_sourceColor, sidey);
58
61
  linearColor.rgb *= lightWeight;
59
62
  v_Color = linearColor;
@@ -67,6 +70,5 @@ float isSide = a_Position.z;
67
70
 
68
71
  v_Color = vec4(v_Color.rgb * lightWeight, v_Color.w * opacity);
69
72
 
70
-
71
73
  setPickingColor(a_PickingColor);
72
74
  }