@tangram.gl/tangram-renderer 0.0.0-stage → 0.0.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 (321) hide show
  1. package/README.md +59 -2
  2. package/dist/core.js +36923 -0
  3. package/dist/core.js.map +6 -0
  4. package/dist/index.js +32 -0
  5. package/dist/loaders-gl-worker.js +82 -0
  6. package/dist/loaders-gl-worker.js.map +6 -0
  7. package/dist/map-logic.js +2 -0
  8. package/dist/map-logic.js.map +6 -0
  9. package/dist/projected-basemaps-worker.js +3 -0
  10. package/dist/projected-basemaps-worker.js.map +6 -0
  11. package/dist/shader-modules.js +141 -0
  12. package/dist/shader-modules.js.map +6 -0
  13. package/dist/style-schema.js +126 -0
  14. package/dist/style-schema.js.map +6 -0
  15. package/dist/tangram-style.schema.json +882 -0
  16. package/dist/tangram.debug.mjs +37139 -0
  17. package/dist/tangram.debug.mjs.map +6 -0
  18. package/dist/tangram.min.mjs +4950 -0
  19. package/dist/types/builders/earcut.d.ts +15 -0
  20. package/dist/types/core.d.ts +29 -0
  21. package/dist/types/gl/constants.d.ts +2 -0
  22. package/dist/types/gl/globe_mesh.d.ts +48 -0
  23. package/dist/types/gl/glsl.d.ts +17 -0
  24. package/dist/types/gl/vertex-constants.d.ts +4 -0
  25. package/dist/types/gl/vertex-types.d.ts +34 -0
  26. package/dist/types/gl/vertex_data.d.ts +32 -0
  27. package/dist/types/gl/vertex_elements.d.ts +8 -0
  28. package/dist/types/gl/vertex_layout.d.ts +32 -0
  29. package/dist/types/glsl.d.ts +14 -0
  30. package/dist/types/gpu/luma_device_renderer.d.ts +66 -0
  31. package/dist/types/gpu/resource_lifecycle.d.ts +4 -0
  32. package/dist/types/gpu/tangram_gpu_backend.d.ts +151 -0
  33. package/dist/types/index.d.ts +155 -0
  34. package/dist/types/lights/light-definitions.d.ts +121 -0
  35. package/dist/types/map-logic/draped-terrain-bounds.d.ts +41 -0
  36. package/dist/types/map-logic/globe-terrain-preparation.d.ts +85 -0
  37. package/dist/types/map-logic/globe-terrain.d.ts +54 -0
  38. package/dist/types/map-logic/index.d.ts +33 -0
  39. package/dist/types/map-logic/label-identity.d.ts +22 -0
  40. package/dist/types/map-logic/label-placement.d.ts +32 -0
  41. package/dist/types/map-logic/screen-bounds.d.ts +15 -0
  42. package/dist/types/map-logic/terrain-data.d.ts +55 -0
  43. package/dist/types/map-logic/terrain-error.d.ts +51 -0
  44. package/dist/types/map-logic/terrain-ground-topology.d.ts +26 -0
  45. package/dist/types/map-logic/terrain-height-field.d.ts +59 -0
  46. package/dist/types/map-logic/terrain-navigation.d.ts +27 -0
  47. package/dist/types/map-logic/terrain-neighborhood.d.ts +5 -0
  48. package/dist/types/map-logic/terrain-query.d.ts +33 -0
  49. package/dist/types/map-logic/terrain-resource-budget.d.ts +51 -0
  50. package/dist/types/map-logic/terrain-transition-topology.d.ts +23 -0
  51. package/dist/types/map-logic/tile-build-queue.d.ts +51 -0
  52. package/dist/types/map-logic/tile-cache-policy.d.ts +46 -0
  53. package/dist/types/map-logic/tile-residency.d.ts +17 -0
  54. package/dist/types/map-logic/triangle-query-index.d.ts +87 -0
  55. package/dist/types/procedures/js-yaml.d.ts +15 -0
  56. package/dist/types/procedures/mesh-projector.d.ts +107 -0
  57. package/dist/types/procedures/mvt-dependencies.d.ts +20 -0
  58. package/dist/types/procedures/projected-coordinate-transform.d.ts +27 -0
  59. package/dist/types/procedures/projection-batch-executor.d.ts +53 -0
  60. package/dist/types/procedures/scene-yaml-legacy.d.ts +6 -0
  61. package/dist/types/procedures/terrain-draping.d.ts +165 -0
  62. package/dist/types/procedures/terrain-globe.d.ts +6 -0
  63. package/dist/types/procedures/terrain-styled-topology.d.ts +34 -0
  64. package/dist/types/procedures/web-mercator-legacy.d.ts +4 -0
  65. package/dist/types/procedures/web-mercator-math.d.ts +4 -0
  66. package/dist/types/scene/globals.d.ts +11 -0
  67. package/dist/types/scene/ground_footprint.d.ts +16 -0
  68. package/dist/types/scene/host_frame.d.ts +54 -0
  69. package/dist/types/scene/projection_math.d.ts +52 -0
  70. package/dist/types/scene/scene-resource-types.d.ts +177 -0
  71. package/dist/types/scene/scene_bundle.d.ts +69 -0
  72. package/dist/types/scene/visibility_adapter.d.ts +106 -0
  73. package/dist/types/selection/draped-terrain-surface.d.ts +78 -0
  74. package/dist/types/selection/terrain_surface.d.ts +149 -0
  75. package/dist/types/shader-modules/globe-horizon.d.ts +15 -0
  76. package/dist/types/shader-modules/height-decode.d.ts +13 -0
  77. package/dist/types/shader-modules/hillshade.d.ts +13 -0
  78. package/dist/types/shader-modules/index.d.ts +6 -0
  79. package/dist/types/shader-modules/planar.d.ts +12 -0
  80. package/dist/types/shader-modules/sphere-map.d.ts +13 -0
  81. package/dist/types/shader-modules/triplanar.d.ts +15 -0
  82. package/dist/types/sources/decoded_tile_store.d.ts +95 -0
  83. package/dist/types/sources/tile_source_metadata.d.ts +32 -0
  84. package/dist/types/styles/text/fontfaceobserver.d.ts +10 -0
  85. package/dist/types/tile/tile_id.d.ts +37 -0
  86. package/dist/types/tile/tile_traversal_adapter.d.ts +63 -0
  87. package/dist/types/types.d.ts +293 -0
  88. package/dist/types/utils/geo.d.ts +57 -0
  89. package/dist/types/utils/hash.d.ts +1 -0
  90. package/dist/types/utils/log.d.ts +27 -0
  91. package/dist/types/utils/props.d.ts +6 -0
  92. package/dist/types/utils/subscribe.d.ts +10 -0
  93. package/dist/types/utils/thread.d.ts +6 -0
  94. package/dist/types/utils/urls.d.ts +26 -0
  95. package/dist/types/utils/utils.d.ts +26 -0
  96. package/dist/types/utils/version.d.ts +2 -0
  97. package/dist/types/utils/worker-types.d.ts +68 -0
  98. package/dist/types/utils/worker_broker.d.ts +3 -0
  99. package/package.json +103 -3
  100. package/src/builders/common.ts +41 -0
  101. package/src/builders/earcut.d.ts +15 -0
  102. package/src/builders/geometry-types.ts +60 -0
  103. package/src/builders/points.ts +115 -0
  104. package/src/builders/polygons.ts +225 -0
  105. package/src/builders/polylines.ts +682 -0
  106. package/src/builders/wireframe.ts +31 -0
  107. package/src/core.d.ts +29 -0
  108. package/src/core.ts +33 -0
  109. package/src/experimental/loaders-gl-worker.ts +19 -0
  110. package/src/experimental/projected-basemaps-worker.ts +13 -0
  111. package/src/experimental/projected-mesh-cache.ts +137 -0
  112. package/src/experimental/projected-mesh-domain.ts +110 -0
  113. package/src/experimental/projected-mesh-refinement.ts +193 -0
  114. package/src/experimental/projected-mesh.ts +399 -0
  115. package/src/experimental/projected-normal.ts +26 -0
  116. package/src/experimental/projected-symbol-mesh.ts +74 -0
  117. package/src/gl/constants.ts +18 -0
  118. package/src/gl/context.ts +103 -0
  119. package/src/gl/extensions.ts +30 -0
  120. package/src/gl/globe_mesh.ts +285 -0
  121. package/src/gl/glsl.ts +257 -0
  122. package/src/gl/mesh-types.ts +56 -0
  123. package/src/gl/render_state.ts +111 -0
  124. package/src/gl/shader_program.ts +1310 -0
  125. package/src/gl/texture.ts +814 -0
  126. package/src/gl/uniform_buffer.ts +340 -0
  127. package/src/gl/vao.ts +154 -0
  128. package/src/gl/vbo_mesh.ts +349 -0
  129. package/src/gl/vertex-constants.ts +19 -0
  130. package/src/gl/vertex-types.ts +35 -0
  131. package/src/gl/vertex_data.ts +126 -0
  132. package/src/gl/vertex_elements.ts +54 -0
  133. package/src/gl/vertex_layout.ts +241 -0
  134. package/src/glsl.d.ts +14 -0
  135. package/src/gpu/luma_device_renderer.ts +579 -0
  136. package/src/gpu/pixel_readback.ts +51 -0
  137. package/src/gpu/resource_lifecycle.ts +32 -0
  138. package/src/gpu/tangram_gpu_backend.ts +195 -0
  139. package/src/index.d.ts +155 -0
  140. package/src/index.ts +105 -0
  141. package/src/labels/collision-types.ts +94 -0
  142. package/src/labels/collision.ts +273 -0
  143. package/src/labels/collision_grid.ts +61 -0
  144. package/src/labels/intersect.ts +30 -0
  145. package/src/labels/label-types.ts +91 -0
  146. package/src/labels/label.ts +207 -0
  147. package/src/labels/label_line.ts +801 -0
  148. package/src/labels/label_point.ts +131 -0
  149. package/src/labels/main-pass-types.ts +73 -0
  150. package/src/labels/main_pass.ts +221 -0
  151. package/src/labels/point_anchor.ts +100 -0
  152. package/src/labels/point_placement.ts +150 -0
  153. package/src/labels/projected-pass.ts +259 -0
  154. package/src/labels/repeat_group.ts +72 -0
  155. package/src/lights/ambient_light.glsl +18 -0
  156. package/src/lights/directional_light.glsl +39 -0
  157. package/src/lights/geographic-lights.ts +21 -0
  158. package/src/lights/light-definitions.ts +285 -0
  159. package/src/lights/light.ts +590 -0
  160. package/src/lights/lighting-uniforms.ts +80 -0
  161. package/src/lights/lighting-wgsl.ts +116 -0
  162. package/src/lights/material.glsl +237 -0
  163. package/src/lights/material.ts +145 -0
  164. package/src/lights/native-falloff.ts +37 -0
  165. package/src/lights/point_light.glsl +96 -0
  166. package/src/lights/spot_light.glsl +111 -0
  167. package/src/map-logic/draped-terrain-bounds.ts +71 -0
  168. package/src/map-logic/globe-terrain-preparation.ts +217 -0
  169. package/src/map-logic/globe-terrain.ts +296 -0
  170. package/src/map-logic/index.ts +37 -0
  171. package/src/map-logic/label-identity.ts +36 -0
  172. package/src/map-logic/label-placement.ts +117 -0
  173. package/src/map-logic/screen-bounds.ts +34 -0
  174. package/src/map-logic/terrain-data.ts +107 -0
  175. package/src/map-logic/terrain-error.ts +134 -0
  176. package/src/map-logic/terrain-ground-topology.ts +164 -0
  177. package/src/map-logic/terrain-height-field.ts +254 -0
  178. package/src/map-logic/terrain-navigation.ts +50 -0
  179. package/src/map-logic/terrain-neighborhood.ts +43 -0
  180. package/src/map-logic/terrain-query.ts +51 -0
  181. package/src/map-logic/terrain-resource-budget.ts +124 -0
  182. package/src/map-logic/terrain-transition-topology.ts +164 -0
  183. package/src/map-logic/tile-build-queue.ts +110 -0
  184. package/src/map-logic/tile-cache-policy.ts +89 -0
  185. package/src/map-logic/tile-residency.ts +50 -0
  186. package/src/map-logic/triangle-query-index.ts +265 -0
  187. package/src/procedures/js-yaml.d.ts +15 -0
  188. package/src/procedures/mesh-projector.ts +191 -0
  189. package/src/procedures/mlt-loaders.ts +55 -0
  190. package/src/procedures/mvt-dependencies.d.ts +20 -0
  191. package/src/procedures/mvt-legacy.ts +150 -0
  192. package/src/procedures/mvt-loaders.ts +53 -0
  193. package/src/procedures/mvt-parser.ts +48 -0
  194. package/src/procedures/mvt-properties.ts +36 -0
  195. package/src/procedures/mvt-tile-provider.ts +72 -0
  196. package/src/procedures/pmtiles-loader.ts +75 -0
  197. package/src/procedures/projected-coordinate-transform.ts +79 -0
  198. package/src/procedures/projection-batch-executor.ts +140 -0
  199. package/src/procedures/scene-yaml-legacy.ts +16 -0
  200. package/src/procedures/scene-yaml-loaders.ts +10 -0
  201. package/src/procedures/terrain-draping.ts +713 -0
  202. package/src/procedures/terrain-globe.ts +32 -0
  203. package/src/procedures/terrain-styled-topology.ts +184 -0
  204. package/src/procedures/web-mercator-legacy.ts +24 -0
  205. package/src/procedures/web-mercator-math.ts +50 -0
  206. package/src/scene/camera.ts +298 -0
  207. package/src/scene/camera_base.ts +116 -0
  208. package/src/scene/classic_scene.ts +20 -0
  209. package/src/scene/external_camera.ts +101 -0
  210. package/src/scene/globals.ts +120 -0
  211. package/src/scene/ground_footprint.ts +139 -0
  212. package/src/scene/host_frame.ts +326 -0
  213. package/src/scene/projected_tile_lod.ts +125 -0
  214. package/src/scene/projection_math.ts +142 -0
  215. package/src/scene/projection_shaders.ts +183 -0
  216. package/src/scene/renderer.ts +516 -0
  217. package/src/scene/scene-resource-types.ts +174 -0
  218. package/src/scene/scene.ts +2378 -0
  219. package/src/scene/scene_bundle.ts +304 -0
  220. package/src/scene/scene_debug.ts +129 -0
  221. package/src/scene/scene_loader.ts +402 -0
  222. package/src/scene/scene_worker.ts +528 -0
  223. package/src/scene/view.ts +683 -0
  224. package/src/scene/visibility_adapter.ts +319 -0
  225. package/src/scene/worker_url.ts +15 -0
  226. package/src/selection/draped-terrain-surface.ts +377 -0
  227. package/src/selection/selection-types.ts +79 -0
  228. package/src/selection/selection.ts +542 -0
  229. package/src/selection/selection_fragment.glsl +18 -0
  230. package/src/selection/selection_globals.glsl +9 -0
  231. package/src/selection/selection_pixels.ts +59 -0
  232. package/src/selection/selection_vertex.glsl +15 -0
  233. package/src/selection/terrain_surface.ts +298 -0
  234. package/src/shader-modules/globe-horizon.ts +52 -0
  235. package/src/shader-modules/height-decode.ts +41 -0
  236. package/src/shader-modules/hillshade.ts +70 -0
  237. package/src/shader-modules/index.ts +10 -0
  238. package/src/shader-modules/planar.ts +24 -0
  239. package/src/shader-modules/sphere-map.ts +38 -0
  240. package/src/shader-modules/triplanar.ts +45 -0
  241. package/src/sources/aligned_tile_source.ts +122 -0
  242. package/src/sources/data_source.ts +655 -0
  243. package/src/sources/decoded_tile_store.ts +245 -0
  244. package/src/sources/geojson.ts +300 -0
  245. package/src/sources/mvt.ts +247 -0
  246. package/src/sources/raster.ts +341 -0
  247. package/src/sources/shared_tile_source_adapter.ts +117 -0
  248. package/src/sources/sources.ts +10 -0
  249. package/src/sources/tile_source_adapter.ts +84 -0
  250. package/src/sources/tile_source_metadata.ts +65 -0
  251. package/src/sources/tile_source_state.ts +112 -0
  252. package/src/sources/topojson.ts +90 -0
  253. package/src/styles/feature_annotations.ts +16 -0
  254. package/src/styles/filter.ts +190 -0
  255. package/src/styles/geometry-style-types.ts +209 -0
  256. package/src/styles/globe_visibility_wgsl.ts +22 -0
  257. package/src/styles/layer-types.ts +45 -0
  258. package/src/styles/layer.ts +586 -0
  259. package/src/styles/lines/dasharray.ts +49 -0
  260. package/src/styles/lines/lines.ts +707 -0
  261. package/src/styles/lines/lines_wgsl.ts +224 -0
  262. package/src/styles/points/point-runtime-types.ts +125 -0
  263. package/src/styles/points/points.ts +1079 -0
  264. package/src/styles/points/points_fragment.glsl +126 -0
  265. package/src/styles/points/points_vertex.glsl +230 -0
  266. package/src/styles/points/points_wgsl.ts +189 -0
  267. package/src/styles/polygons/polygons.ts +268 -0
  268. package/src/styles/polygons/polygons_fragment.glsl +173 -0
  269. package/src/styles/polygons/polygons_vertex.glsl +213 -0
  270. package/src/styles/polygons/polygons_wgsl.ts +127 -0
  271. package/src/styles/property-types.ts +125 -0
  272. package/src/styles/raster/raster.ts +33 -0
  273. package/src/styles/raster/raster_globals.glsl +46 -0
  274. package/src/styles/style-mixing-types.ts +101 -0
  275. package/src/styles/style-runtime-types.ts +220 -0
  276. package/src/styles/style-schema.ts +133 -0
  277. package/src/styles/style.ts +1033 -0
  278. package/src/styles/style_globals.glsl +69 -0
  279. package/src/styles/style_manager.ts +464 -0
  280. package/src/styles/style_parser.ts +620 -0
  281. package/src/styles/text/font_manager.ts +180 -0
  282. package/src/styles/text/fontfaceobserver.d.ts +10 -0
  283. package/src/styles/text/text-types.ts +220 -0
  284. package/src/styles/text/text.ts +378 -0
  285. package/src/styles/text/text_canvas.ts +773 -0
  286. package/src/styles/text/text_labels.ts +436 -0
  287. package/src/styles/text/text_segments.ts +142 -0
  288. package/src/styles/text/text_settings.ts +228 -0
  289. package/src/styles/text/text_wgsl.ts +159 -0
  290. package/src/styles/text/text_wrap.ts +194 -0
  291. package/src/tile/globe_tile_preload.ts +40 -0
  292. package/src/tile/tangram_tileset_2d.ts +108 -0
  293. package/src/tile/tile-build-types.ts +155 -0
  294. package/src/tile/tile.ts +807 -0
  295. package/src/tile/tile_id.ts +172 -0
  296. package/src/tile/tile_manager.ts +889 -0
  297. package/src/tile/tile_pyramid.ts +119 -0
  298. package/src/tile/tile_resource_cache.ts +91 -0
  299. package/src/tile/tile_traversal_adapter.ts +132 -0
  300. package/src/types.ts +332 -0
  301. package/src/utils/debounce.ts +17 -0
  302. package/src/utils/debug_settings.ts +43 -0
  303. package/src/utils/errors.ts +12 -0
  304. package/src/utils/functions.ts +95 -0
  305. package/src/utils/geo.ts +364 -0
  306. package/src/utils/hash.ts +14 -0
  307. package/src/utils/log.ts +108 -0
  308. package/src/utils/media_capture.ts +193 -0
  309. package/src/utils/merge.ts +44 -0
  310. package/src/utils/obb.ts +134 -0
  311. package/src/utils/props.ts +43 -0
  312. package/src/utils/slice.ts +14 -0
  313. package/src/utils/subscribe.ts +58 -0
  314. package/src/utils/task.ts +154 -0
  315. package/src/utils/thread.ts +26 -0
  316. package/src/utils/urls.ts +223 -0
  317. package/src/utils/utils.ts +310 -0
  318. package/src/utils/vector.ts +197 -0
  319. package/src/utils/version.ts +8 -0
  320. package/src/utils/worker-types.ts +79 -0
  321. package/src/utils/worker_broker.ts +523 -0
@@ -0,0 +1,126 @@
1
+ // Tangram
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) 2013-2016 Brett Camper and Mapzen
4
+
5
+ uniform vec2 u_resolution;
6
+ uniform float u_time;
7
+ uniform vec3 u_map_position;
8
+ uniform vec4 u_tile_origin;
9
+ uniform float u_meters_per_pixel;
10
+ uniform float u_device_pixel_ratio;
11
+ uniform float u_visible_time;
12
+ uniform mat3 u_normalMatrix;
13
+ uniform mat3 u_inverseNormalMatrix;
14
+
15
+ uniform sampler2D u_texture;
16
+ uniform float u_point_type;
17
+ uniform bool u_apply_color_blocks;
18
+
19
+ varying vec4 v_color;
20
+ varying vec2 v_texcoord;
21
+ varying vec4 v_world_position;
22
+ varying float v_alpha_factor;
23
+
24
+ #ifdef TANGRAM_HAS_SHADER_POINTS
25
+ varying vec4 v_outline_color;
26
+ varying float v_outline_edge;
27
+ varying float v_aa_offset;
28
+ #endif
29
+
30
+ #ifdef TANGRAM_SHOW_HIDDEN_LABELS
31
+ varying float v_label_hidden;
32
+ #endif
33
+
34
+ #define TANGRAM_NORMAL vec3(0., 0., 1.)
35
+
36
+ #pragma tangram: attributes
37
+ #pragma tangram: camera
38
+ #pragma tangram: material
39
+ #pragma tangram: lighting
40
+ #pragma tangram: raster
41
+ #pragma tangram: global
42
+
43
+ #ifdef TANGRAM_HAS_SHADER_POINTS
44
+ //l is the distance from the center to the fragment, R is the radius of the drawn point
45
+ float _tangram_antialias(float l, float R){
46
+ float low = R - v_aa_offset;
47
+ float high = R + v_aa_offset;
48
+ return 1. - smoothstep(low, high, l);
49
+ }
50
+ #endif
51
+
52
+ void main (void) {
53
+ // Initialize globals
54
+ #pragma tangram: setup
55
+
56
+ vec4 color = v_color;
57
+
58
+ #ifdef TANGRAM_HAS_SHADER_POINTS
59
+ // Only apply shader blocks to point, not to attached text (N.B.: for compatibility with ES)
60
+ if (u_point_type == TANGRAM_POINT_TYPE_TEXTURE) { // sprite texture
61
+ color *= texture2D(u_texture, v_texcoord);
62
+ }
63
+ else if (u_point_type == TANGRAM_POINT_TYPE_LABEL) { // label texture
64
+ color = texture2D(u_texture, v_texcoord);
65
+ color.rgb /= max(color.a, 0.001); // un-multiply canvas texture
66
+ }
67
+ else if (u_point_type == TANGRAM_POINT_TYPE_SHADER) { // shader point
68
+ // Mask of outermost circle, either outline or point boundary
69
+ float _d = length(v_texcoord); // distance to this fragment from the point center
70
+ float _outer_alpha = _tangram_antialias(_d, 1.);
71
+ float _fill_alpha = _tangram_antialias(_d, 1. - (v_outline_edge * 0.5)) * color.a;
72
+ float _stroke_alpha = (_outer_alpha - _tangram_antialias(_d, 1. - v_outline_edge)) * v_outline_color.a;
73
+
74
+ // Apply alpha compositing with stroke 'over' fill.
75
+ #ifdef TANGRAM_BLEND_ADD
76
+ color.a = _stroke_alpha + _fill_alpha;
77
+ color.rgb = color.rgb * _fill_alpha + v_outline_color.rgb * _stroke_alpha;
78
+ #else // TANGRAM_BLEND_OVERLAY (and fallback for not implemented blending modes)
79
+ color.a = _stroke_alpha + _fill_alpha * (1. - _stroke_alpha);
80
+ color.rgb = mix(color.rgb * _fill_alpha, v_outline_color.rgb, _stroke_alpha) / max(color.a, 0.001); // avoid divide by zero
81
+ #endif
82
+ }
83
+ #else
84
+ // If shader points not supported, assume label texture
85
+ color = texture2D(u_texture, v_texcoord);
86
+ color.rgb /= max(color.a, 0.001); // un-multiply canvas texture
87
+ #endif
88
+
89
+ // Shader blocks for color/filter are only applied for sprites, shader points, and standalone text,
90
+ // NOT for text attached to a point (N.B.: for compatibility with ES)
91
+ if (u_apply_color_blocks) {
92
+ #pragma tangram: color
93
+ #pragma tangram: filter
94
+ }
95
+
96
+ color.a *= v_alpha_factor;
97
+
98
+ // highlight hidden label in fragment shader for debugging
99
+ #ifdef TANGRAM_SHOW_HIDDEN_LABELS
100
+ if (v_label_hidden > 0.) {
101
+ color.a *= 0.5;
102
+ color.rgb = vec3(1., 0., 0.);
103
+ }
104
+ #endif
105
+
106
+ // Use alpha test as a lower-quality substitute
107
+ // For opaque and translucent: avoid transparent pixels writing to depth buffer, obscuring geometry underneath
108
+ // For multiply: avoid transparent pixels multiplying geometry underneath to zero/full black
109
+ #if defined(TANGRAM_BLEND_OPAQUE) || defined(TANGRAM_BLEND_TRANSLUCENT) || defined(TANGRAM_BLEND_MULTIPLY)
110
+ if (color.a < TANGRAM_ALPHA_TEST) {
111
+ discard;
112
+ }
113
+ #endif
114
+
115
+ // Make points more visible in wireframe debug mode
116
+ #ifdef TANGRAM_WIREFRAME
117
+ color = vec4(vec3(0.5), 1.); // use gray outline for textured points
118
+ #ifdef TANGRAM_HAS_SHADER_POINTS
119
+ if (u_point_type == TANGRAM_POINT_TYPE_SHADER) {
120
+ color = vec4(v_color.rgb, 1.); // use original vertex color outline for shader points
121
+ }
122
+ #endif
123
+ #endif
124
+
125
+ gl_FragColor = color;
126
+ }
@@ -0,0 +1,230 @@
1
+ // Tangram
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) 2013-2016 Brett Camper and Mapzen
4
+ // Copyright (c) 2026 vis.gl contributors
5
+
6
+ uniform vec2 u_resolution;
7
+ uniform float u_time;
8
+ uniform vec3 u_map_position;
9
+ uniform vec4 u_tile_origin;
10
+ uniform float u_tile_proxy_order_offset;
11
+ uniform bool u_tile_fade_in;
12
+ uniform float u_meters_per_pixel;
13
+ uniform float u_device_pixel_ratio;
14
+ uniform float u_visible_time;
15
+ uniform bool u_view_panning;
16
+ uniform float u_view_pan_snap_timer;
17
+ #ifndef TANGRAM_UNIFORM_BLOCK_TANGRAMVIEW
18
+ uniform int u_projection_mode;
19
+ #endif
20
+ uniform mat4 u_model;
21
+ uniform mat4 u_modelView;
22
+ uniform mat3 u_normalMatrix;
23
+ uniform mat3 u_inverseNormalMatrix;
24
+
25
+ attribute vec4 a_position;
26
+ attribute vec4 a_shape;
27
+ attribute vec4 a_color;
28
+ attribute vec2 a_texcoord;
29
+ attribute vec2 a_offset;
30
+ #ifdef TANGRAM_CPU_PROJECTED
31
+ attribute vec3 a_projected_position;
32
+ #endif
33
+
34
+ uniform float u_point_type;
35
+
36
+ #ifdef TANGRAM_CURVED_LABEL
37
+ attribute vec4 a_offsets;
38
+ attribute vec4 a_pre_angles;
39
+ attribute vec4 a_angles;
40
+ #endif
41
+
42
+ varying vec4 v_color;
43
+ varying vec2 v_texcoord;
44
+ varying vec4 v_world_position;
45
+ varying float v_alpha_factor;
46
+
47
+ #ifdef TANGRAM_HAS_SHADER_POINTS
48
+ attribute float a_outline_edge;
49
+ attribute vec4 a_outline_color;
50
+
51
+ varying float v_outline_edge;
52
+ varying vec4 v_outline_color;
53
+ varying float v_aa_offset;
54
+ #endif
55
+
56
+ #ifdef TANGRAM_SHOW_HIDDEN_LABELS
57
+ varying float v_label_hidden;
58
+ #endif
59
+
60
+ #define TANGRAM_PI 3.14159265359
61
+ #define TANGRAM_NORMAL vec3(0., 0., 1.)
62
+
63
+ #pragma tangram: attributes
64
+ #pragma tangram: camera
65
+ #pragma tangram: material
66
+ #pragma tangram: lighting
67
+ #pragma tangram: raster
68
+ #pragma tangram: global
69
+
70
+ vec2 rotate2D(vec2 _st, float _angle) {
71
+ return mat2(cos(_angle),-sin(_angle),
72
+ sin(_angle),cos(_angle)) * _st;
73
+ }
74
+
75
+ #pragma tangram: projection
76
+
77
+ #pragma tangram: globe_visibility
78
+
79
+ #ifdef TANGRAM_CURVED_LABEL
80
+ // Assumes stops are [0, 0.33, 0.66, 0.99];
81
+ float mix4linear(vec4 v, float x) {
82
+ x = clamp(x, 0., 1.);
83
+ return mix(mix(v[0], v[1], 3. * x),
84
+ mix(v[1],
85
+ mix(v[2], v[3], 3. * (max(x, .66) - .66)),
86
+ 3. * (clamp(x, .33, .66) - .33)),
87
+ step(0.33, x)
88
+ );
89
+ }
90
+ #endif
91
+
92
+ void main() {
93
+ // Initialize globals
94
+ #pragma tangram: setup
95
+
96
+ // discard hidden labels by collapsing into degenerate triangle
97
+ #ifndef TANGRAM_SHOW_HIDDEN_LABELS
98
+ if (a_shape.w == 0.) {
99
+ gl_Position = vec4(0., 0., 0., 1.);
100
+ return;
101
+ }
102
+ #else
103
+ // highlight hidden label in fragment shader for debugging
104
+ if (a_shape.w == 0.) {
105
+ v_label_hidden = 1.; // label debug testing
106
+ }
107
+ else {
108
+ v_label_hidden = 0.;
109
+ }
110
+ #endif
111
+
112
+ v_alpha_factor = 1.0;
113
+ v_color = a_color;
114
+ v_texcoord = a_texcoord; // UV from vertex attribute
115
+
116
+ #ifdef TANGRAM_HAS_SHADER_POINTS
117
+ v_outline_color = a_outline_color;
118
+ v_outline_edge = a_outline_edge;
119
+
120
+ if (u_point_type == TANGRAM_POINT_TYPE_SHADER) { // shader point
121
+ // use point dimensions for UVs instead (ignore attribute), add antialiasing info for fragment shader
122
+ float _size = abs(a_shape.x / 128.); // radius in pixels
123
+ v_texcoord = sign(a_shape.xy) * (_size + 1.) / _size;
124
+ _size += 2.;
125
+ v_aa_offset = 2. / _size;
126
+ }
127
+ #endif
128
+
129
+ // Position
130
+ vec4 world_position;
131
+ #ifdef TANGRAM_CPU_PROJECTED
132
+ world_position = vec4(a_projected_position, 1.);
133
+ vec4 position = world_position;
134
+ #else
135
+ vec4 local_position = vec4(a_position.xyz, 1.);
136
+ #ifdef TANGRAM_TERRAIN_DRAPED
137
+ local_position.z += tangramTerrainHeight();
138
+ #endif
139
+ vec4 position = tangramModelView(local_position, world_position);
140
+ #endif
141
+ // Occlude the shared geographic anchor before screen-space offsets. This
142
+ // also applies to text and selection programs using this vertex shader.
143
+ if (u_projection_mode == 1 && tangramGlobeOccluded(position.xyz, world_position.z, u_eye)) {
144
+ gl_Position = vec4(2., 2., 2., 1.);
145
+ return;
146
+ }
147
+
148
+ // Apply positioning and scaling in screen space
149
+ vec2 _shape = a_shape.xy / 256.; // values have an 8-bit fraction
150
+ vec2 _offset = vec2(a_offset.x, -a_offset.y); // flip y to make it point down
151
+ float _theta = a_shape.z / 4096.;
152
+
153
+ #ifdef TANGRAM_CURVED_LABEL
154
+ //TODO: potential bug? null is passed in for non-curved labels, otherwise the first offset will be 0
155
+ if (a_offsets[0] != 0.){
156
+ vec4 _angles_scaled = (TANGRAM_PI / 16384.) * a_angles;
157
+ vec4 _pre_angles_scaled = (TANGRAM_PI / 128.) * a_pre_angles;
158
+ vec4 _offsets_scaled = (1. / 64.) * a_offsets;
159
+
160
+ float _zoom = clamp(u_map_position.z - u_tile_origin.z, 0., 1.); //fract(u_map_position.z);
161
+ float _pre_angle = mix4linear(_pre_angles_scaled, _zoom);
162
+ float _angle = mix4linear(_angles_scaled, _zoom);
163
+ float _offset_curve = mix4linear(_offsets_scaled, _zoom);
164
+
165
+ _shape = rotate2D(_shape, _pre_angle); // rotate in place
166
+ _shape.x += _offset_curve; // offset for curved label segment
167
+ _shape = rotate2D(_shape, _angle); // rotate relative to curved label anchor
168
+ _shape += rotate2D(_offset, _theta); // offset if specified in the scene file
169
+ }
170
+ else {
171
+ _shape = rotate2D(_shape + _offset, _theta);
172
+ }
173
+ #else
174
+ _shape = rotate2D(_shape + _offset, _theta);
175
+ #endif
176
+
177
+ // Fade in (if requested) based on time mesh has been visible.
178
+ // Value passed to fragment shader in the v_alpha_factor varying
179
+ #ifdef TANGRAM_FADE_IN_RATE
180
+ if (u_tile_fade_in) {
181
+ v_alpha_factor *= clamp(u_visible_time * TANGRAM_FADE_IN_RATE, 0., 1.);
182
+ }
183
+ #endif
184
+
185
+ // World coordinates for 3d procedural textures
186
+ v_world_position = world_position;
187
+ v_world_position.xy += _shape * u_meters_per_pixel;
188
+ v_world_position = wrapWorldPosition(v_world_position);
189
+
190
+ // Modify position before camera projection
191
+ #pragma tangram: position
192
+
193
+ cameraProjection(position);
194
+
195
+ #ifdef TANGRAM_LAYER_ORDER
196
+ // +1 is to keep all layers including proxies > 0
197
+ applyLayerOrder(a_position.w + u_tile_proxy_order_offset + 1., position);
198
+ #endif
199
+
200
+ // Apply pixel offset in screen-space
201
+ // Multiply by 2 is because screen is 2 units wide Normalized Device Coords (and u_resolution device pixels wide)
202
+ // Device pixel ratio adjustment is because shape is in logical pixels
203
+ position.xy += _shape * position.w * 2. * u_device_pixel_ratio / u_resolution;
204
+ #ifdef TANGRAM_HAS_SHADER_POINTS
205
+ if (u_point_type == TANGRAM_POINT_TYPE_SHADER) { // shader point
206
+ // enlarge by 1px to catch missed MSAA fragments
207
+ position.xy += sign(_shape) * position.w * u_device_pixel_ratio / u_resolution;
208
+ }
209
+ #endif
210
+
211
+ // Snap to pixel grid
212
+ // Only applied to fully upright sprites/labels (not shader-drawn points), while panning is not active
213
+ #ifdef TANGRAM_HAS_SHADER_POINTS
214
+ if (!u_view_panning && (abs(_theta) < TANGRAM_EPSILON) && u_point_type != TANGRAM_POINT_TYPE_SHADER) {
215
+ #else
216
+ if (!u_view_panning && (abs(_theta) < TANGRAM_EPSILON)) {
217
+ #endif
218
+ vec2 _position_fract = fract((((position.xy / position.w) + 1.) * .5) * u_resolution);
219
+ vec2 _position_snap = position.xy + ((step(0.5, _position_fract) - _position_fract) * position.w * 2. / u_resolution);
220
+
221
+ // Animate the snapping to smooth the transition and make it less noticeable
222
+ #ifdef TANGRAM_VIEW_PAN_SNAP_RATE
223
+ position.xy = mix(position.xy, _position_snap, clamp(u_view_pan_snap_timer * TANGRAM_VIEW_PAN_SNAP_RATE, 0., 1.));
224
+ #else
225
+ position.xy = _position_snap;
226
+ #endif
227
+ }
228
+
229
+ gl_Position = position;
230
+ }
@@ -0,0 +1,189 @@
1
+ // tangram-layers
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import {GLOBE_PROJECTION_WGSL, TERRAIN_DRAPING_WGSL} from '../../scene/projection_shaders';
6
+ import {GLOBE_VISIBILITY_WGSL} from '../globe_visibility_wgsl';
7
+
8
+ /**
9
+ * Build the portable point shader used by the luma.gl WebGPU renderer.
10
+ *
11
+ * One buffered point-type attribute selects sprite, attached-label, or shader
12
+ * circle rendering without scalar WebGL uniforms. All point variants share an
13
+ * all-buffered vertex layout so WebGPU never depends on constant attributes.
14
+ *
15
+ * @param cpuProjection Use preprojected ground anchors while retaining screen-space billboard shapes.
16
+ * @param selection Emit the worker selection key after visible-shape masking.
17
+ * @param terrain Add physical terrain height/morph attributes to the anchor.
18
+ * @returns {string} Complete WGSL source for Tangram's point style.
19
+ */
20
+ export function buildPointsWGSL(cpuProjection = false, selection = false, terrain = false) {
21
+ return `
22
+ @group(0) @binding(3) var u_texture: texture_2d<f32>;
23
+ @group(0) @binding(4) var u_textureSampler: sampler;
24
+ ${GLOBE_PROJECTION_WGSL}
25
+ ${terrain ? TERRAIN_DRAPING_WGSL : ''}
26
+ ${GLOBE_VISIBILITY_WGSL}
27
+
28
+ struct PointAttributes {
29
+ ${terrain ? '@location(14) a_terrain: vec4<f32>, @location(15) a_terrain_previous: vec4<f32>,' : ''}
30
+ @location(0) a_position: vec4<${terrain ? 'f32' : 'i32'}>,
31
+ @location(1) a_shape: vec4<i32>,
32
+ @location(2) a_texcoord: vec2<f32>,
33
+ @location(3) a_offset: vec2<i32>,
34
+ @location(4) a_color: vec4<f32>,
35
+ ${selection ? '@location(5) a_selection_color: vec4<f32>,' : ''}
36
+ @location(6) a_outline_color: vec4<f32>,
37
+ @location(7) a_outline_edge: f32,
38
+ @location(8) a_point_type: f32,
39
+ ${cpuProjection ? '@location(9) a_projected_position: vec3<f32>,' : ''}
40
+ };
41
+
42
+ struct PointVaryings {
43
+ @builtin(position) position: vec4<f32>,
44
+ @location(0) texcoord: vec2<f32>,
45
+ @location(1) color: vec4<f32>,
46
+ @location(2) outline_color: vec4<f32>,
47
+ @location(3) outline_edge: f32,
48
+ @location(4) aa_offset: f32,
49
+ @location(5) @interpolate(flat) point_type: u32,
50
+ ${selection ? '@location(6) @interpolate(flat) selection_color: vec4<f32>,' : ''}
51
+ };
52
+
53
+ fn rotate2D(point: vec2<f32>, angle: f32) -> vec2<f32> {
54
+ let cosine = cos(angle);
55
+ let sine = sin(angle);
56
+ return vec2<f32>(
57
+ cosine * point.x - sine * point.y,
58
+ sine * point.x + cosine * point.y
59
+ );
60
+ }
61
+
62
+ fn antialiasCircle(distance: f32, radius: f32, offset: f32) -> f32 {
63
+ return 1.0 - smoothstep(radius - offset, radius + offset, distance);
64
+ }
65
+
66
+ @vertex
67
+ fn vertexMain(attributes: PointAttributes) -> PointVaryings {
68
+ var output: PointVaryings;
69
+ ${selection ? 'output.selection_color = attributes.a_selection_color;' : ''}
70
+ output.color = attributes.a_color;
71
+ output.outline_color = attributes.a_outline_color;
72
+ output.outline_edge = attributes.a_outline_edge;
73
+ output.point_type = u32(round(attributes.a_point_type));
74
+ output.aa_offset = 0.0;
75
+ output.texcoord = vec2<f32>(
76
+ attributes.a_texcoord.x,
77
+ 1.0 - attributes.a_texcoord.y
78
+ );
79
+
80
+ if (attributes.a_shape.w == 0) {
81
+ output.position = vec4<f32>(2.0, 2.0, 2.0, 1.0);
82
+ return output;
83
+ }
84
+
85
+ var shape = vec2<f32>(attributes.a_shape.xy) / 256.0;
86
+ let offset = vec2<f32>(
87
+ f32(attributes.a_offset.x),
88
+ -f32(attributes.a_offset.y)
89
+ );
90
+ let theta = f32(attributes.a_shape.z) / 4096.0;
91
+
92
+ if (output.point_type == 3u) {
93
+ let point_size = max(abs(f32(attributes.a_shape.x)) / 128.0, 1.0);
94
+ output.texcoord = sign(vec2<f32>(attributes.a_shape.xy)) *
95
+ ((point_size + 1.0) / point_size);
96
+ output.aa_offset = 2.0 / (point_size + 2.0);
97
+ }
98
+
99
+ shape = rotate2D(shape + offset, theta);
100
+ let local_position = vec4<f32>(
101
+ f32(attributes.a_position.x),
102
+ f32(attributes.a_position.y),
103
+ f32(attributes.a_position.z) ${terrain ? '+ tangramTerrainHeight(attributes.a_terrain, attributes.a_terrain_previous)' : ''},
104
+ 1.0
105
+ );
106
+ let projected_position = ${cpuProjection ? 'vec4<f32>(attributes.a_projected_position, 1.0)' : 'tangramModelView(local_position)'};
107
+ if (TangramView.u_projection_mode == 1 && tangramGlobeOccluded(projected_position.xyz,
108
+ (TangramTile.u_model * local_position).z, TangramCamera.u_eye)) {
109
+ output.position = vec4<f32>(2.0, 2.0, 2.0, 1.0);
110
+ return output;
111
+ }
112
+ var clip_position = TangramCamera.u_projection * projected_position;
113
+ ${cpuProjection ? 'clip_position.z = (clip_position.z + clip_position.w) * 0.5;' : ''}
114
+ let screen_offset = shape * clip_position.w * 2.0 *
115
+ TangramView.u_device_pixel_ratio / TangramView.u_resolution;
116
+ clip_position = vec4<f32>(
117
+ clip_position.xy + screen_offset,
118
+ clip_position.zw
119
+ );
120
+
121
+ if (output.point_type == 3u) {
122
+ let antialias_offset = sign(shape) * clip_position.w *
123
+ TangramView.u_device_pixel_ratio / TangramView.u_resolution;
124
+ clip_position = vec4<f32>(
125
+ clip_position.xy + antialias_offset,
126
+ clip_position.zw
127
+ );
128
+ }
129
+
130
+ output.position = clip_position;
131
+ return output;
132
+ }
133
+
134
+ @fragment
135
+ fn fragmentMain(input: PointVaryings) -> @location(0) vec4<f32> {
136
+ var color = input.color;
137
+
138
+ if (input.point_type == 1u) {
139
+ color *= textureSampleLevel(
140
+ u_texture,
141
+ u_textureSampler,
142
+ input.texcoord,
143
+ 0.0
144
+ );
145
+ }
146
+ else if (input.point_type == 2u) {
147
+ let atlas_color = textureSampleLevel(
148
+ u_texture,
149
+ u_textureSampler,
150
+ input.texcoord,
151
+ 0.0
152
+ );
153
+ color = vec4<f32>(
154
+ atlas_color.rgb / max(atlas_color.a, 0.001),
155
+ atlas_color.a
156
+ );
157
+ }
158
+ else {
159
+ let distance = length(input.texcoord);
160
+ let outer_alpha = antialiasCircle(distance, 1.0, input.aa_offset);
161
+ let fill_alpha = antialiasCircle(
162
+ distance,
163
+ 1.0 - input.outline_edge * 0.5,
164
+ input.aa_offset
165
+ ) * color.a;
166
+ let stroke_alpha = max(
167
+ outer_alpha - antialiasCircle(
168
+ distance,
169
+ 1.0 - input.outline_edge,
170
+ input.aa_offset
171
+ ),
172
+ 0.0
173
+ ) * input.outline_color.a;
174
+ let composed_alpha = stroke_alpha + fill_alpha * (1.0 - stroke_alpha);
175
+ let composed_rgb = mix(
176
+ color.rgb * fill_alpha,
177
+ input.outline_color.rgb,
178
+ stroke_alpha
179
+ ) / max(composed_alpha, 0.001);
180
+ color = vec4<f32>(composed_rgb, composed_alpha);
181
+ }
182
+
183
+ if (color.a < 0.001) {
184
+ discard;
185
+ }
186
+ return ${selection ? 'input.selection_color' : 'color'};
187
+ }
188
+ `;
189
+ }