@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,224 @@
1
+ // tangram-layers
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import Geo from '../../utils/geo';
6
+ import {GLOBE_PROJECTION_WGSL, GLOBE_NORMAL_WGSL, TERRAIN_DRAPING_WGSL, TERRAIN_GLOBE_ATTRIBUTES_WGSL} from '../../scene/projection_shaders';
7
+ import {buildLightingWGSL} from '../../lights/lighting-wgsl';
8
+
9
+ const LAYER_DELTA = 1 / (1 << 14);
10
+ const ATTRIBUTE_SCALE = 1024;
11
+
12
+ /**
13
+ * Build the portable base-line shader used by the luma.gl WebGPU renderer.
14
+ *
15
+ * Tangram's line builder emits expanded triangle geometry. The extrusion
16
+ * vector and its fractional-zoom scaling are therefore applied before the
17
+ * host-provided tile and camera matrices. Buffered offsets and elevation use
18
+ * the same zoom interpolation and height packing as Tangram's GLSL renderer.
19
+ * Textured and dashed styles sample luma-owned textures using per-mesh state
20
+ * from a std140 uniform block. Animated styles reuse the generated line
21
+ * texture coordinates and Tangram's frame time to produce portable compact
22
+ * repeating vehicles without additive blending. Arbitrary custom shader
23
+ * blocks remain follow-up tranches. Selection shares the same geometry and masks.
24
+ *
25
+ * @param {object} options Shader options.
26
+ * @param {boolean} options.animated Enables the portable traffic vehicles.
27
+ * @returns {string} Complete WGSL source for the line style.
28
+ */
29
+ export function buildLinesWGSL({ animated = false, lighting, lightCount, cpuProjection = false, terrain = false, selection = false }: {
30
+ /** Physical ground displacement from worker attributes. */
31
+ terrain?: boolean;
32
+ /** Emit the worker selection key after applying texture and dash masks. */
33
+ selection?: boolean;
34
+ /** Enable the existing portable traffic animation. */
35
+ animated?: boolean;
36
+ /** Opt into constant-material surface lighting. */
37
+ lighting?: 'vertex' | 'fragment' | false;
38
+ /** Active scene light count, used to specialize shader compilation. */
39
+ lightCount?: number;
40
+ /** Use worker-projected fixed-meter ribbons; normal line shaders retain dynamic extrusion. */
41
+ cpuProjection?: boolean;
42
+ } = {}) {
43
+ const configured = lighting === 'vertex' || lighting === 'fragment';
44
+ const animated_fragment = animated ? `
45
+
46
+ let direction = select(-1.0, 1.0, input.texcoord.x < 0.5);
47
+ let lane_phase = select(0.0, 2.75, direction > 0.0);
48
+ // Keep the pattern continuous along the buffered road distance. The
49
+ // derivative-aware body below remains a few pixels long at every zoom
50
+ // instead of collapsing to a sub-pixel flash or stretching into a trail.
51
+ let traffic_coordinate = input.texcoord.y * 0.125 -
52
+ TangramView.u_time * 1.8 * direction + lane_phase;
53
+ let vehicle_position = fract(traffic_coordinate / 6.0);
54
+ let longitudinal_distance = abs(vehicle_position - 0.5);
55
+ let longitudinal_derivative = max(fwidth(vehicle_position), 0.001);
56
+ let vehicle_half_length = max(0.022, longitudinal_derivative * 1.35);
57
+ let vehicle_body = 1.0 - smoothstep(
58
+ vehicle_half_length,
59
+ vehicle_half_length + longitudinal_derivative,
60
+ longitudinal_distance
61
+ );
62
+ let vehicle_halo = 1.0 - smoothstep(
63
+ vehicle_half_length + longitudinal_derivative,
64
+ vehicle_half_length + longitudinal_derivative * 2.5,
65
+ longitudinal_distance
66
+ );
67
+ let lane_center = select(0.72, 0.28, direction > 0.0);
68
+ let lane_distance = abs(input.texcoord.x - lane_center);
69
+ let lane_derivative = max(fwidth(input.texcoord.x), 0.01);
70
+ let lane_half_width = clamp(lane_derivative * 0.45, 0.10, 0.22);
71
+ let lane_edge = clamp(lane_derivative * 0.35, 0.02, 0.18);
72
+ let lane_mask = 1.0 - smoothstep(
73
+ lane_half_width,
74
+ lane_half_width + lane_edge,
75
+ lane_distance
76
+ );
77
+ let vehicle = max(vehicle_body, vehicle_halo * 0.35) * lane_mask;
78
+ let vehicle_color = vec3<f32>(0.62, 1.0, 0.98);
79
+ let animated_color = mix(
80
+ color.rgb,
81
+ vehicle_color,
82
+ vehicle * 0.98
83
+ );
84
+ color = vec4<f32>(animated_color, color.a);
85
+ ` : '';
86
+
87
+ return `
88
+ @group(0) @binding(3) var u_texture: texture_2d<f32>;
89
+ @group(0) @binding(4) var u_textureSampler: sampler;
90
+ ${GLOBE_PROJECTION_WGSL}
91
+ ${configured ? `${GLOBE_NORMAL_WGSL}\n${buildLightingWGSL(lightCount)}` : ''}
92
+ ${terrain ? TERRAIN_DRAPING_WGSL : ''}
93
+
94
+ struct LineAttributes {
95
+ ${terrain ? TERRAIN_GLOBE_ATTRIBUTES_WGSL : ''}
96
+ ${terrain ? '@location(14) a_terrain: vec4<f32>, @location(15) a_terrain_previous: vec4<f32>,' : ''}
97
+ @location(0) a_position: vec4<${terrain ? 'f32' : 'i32'}>,
98
+ @location(1) a_extrude: vec2<${terrain ? 'f32' : 'i32'}>,
99
+ @location(2) a_offset: vec2<${terrain ? 'f32' : 'i32'}>,
100
+ @location(3) a_z_and_offset_scale: vec2<i32>,
101
+ @location(4) a_texcoord: vec2<f32>,
102
+ @location(5) a_color: vec4<f32>,
103
+ ${selection ? '@location(8) a_selection_color: vec4<f32>,' : ''}
104
+ ${cpuProjection ? '@location(6) a_projected_position: vec3<f32>, @location(7) a_projected_stroke: vec4<f32>,' : ''}
105
+ };
106
+
107
+ struct LineVaryings {
108
+ @builtin(position) position: vec4<f32>,
109
+ @location(0) color: vec4<f32>,
110
+ @location(1) texcoord: vec2<f32>,
111
+ @location(5) tile_position: vec2<f32>,
112
+ ${selection ? '@location(6) @interpolate(flat) selection_color: vec4<f32>,' : ''}
113
+ ${configured ? '@location(2) normal: vec3<f32>, @location(3) eye_position: vec3<f32>, @location(4) lighting: vec4<f32>,' : ''}
114
+ };
115
+
116
+ @vertex
117
+ fn vertexMain(attributes: LineAttributes) -> LineVaryings {
118
+ var output: LineVaryings;
119
+ ${selection ? 'output.selection_color = attributes.a_selection_color;' : ''}
120
+ var extrusion = vec2<f32>(attributes.a_extrude);
121
+ var offset = vec2<f32>(attributes.a_offset);
122
+
123
+ var zoom_delta = clamp(
124
+ TangramView.u_map_position.z - TangramTile.u_tile_origin.z,
125
+ 0.0,
126
+ 4.0
127
+ );
128
+ zoom_delta += step(1.0, zoom_delta) * (1.0 - zoom_delta) +
129
+ mix(0.0, 2.0, clamp((zoom_delta - 2.0) / 2.0, 0.0, 1.0));
130
+
131
+ let midpoint_zoom_delta = (zoom_delta - 0.5) * 2.0;
132
+ let width_scale = f32(attributes.a_position.z) / ${ATTRIBUTE_SCALE}.0;
133
+ extrusion -= extrusion * width_scale * midpoint_zoom_delta;
134
+
135
+ let offset_width_scale =
136
+ f32(attributes.a_z_and_offset_scale.y) / ${ATTRIBUTE_SCALE}.0;
137
+ let offset_scale_direction = sign(step(0.0, offset_width_scale) - 0.5);
138
+ offset -= offset * abs(offset_width_scale) * (
139
+ (1.0 - step(0.0, offset_scale_direction)) -
140
+ (zoom_delta * -offset_scale_direction)
141
+ );
142
+
143
+ let screen_space_scale = exp2(
144
+ -zoom_delta - (TangramTile.u_tile_origin.z - TangramTile.u_tile_origin.w)
145
+ );
146
+ extrusion *= screen_space_scale;
147
+ offset *= screen_space_scale;
148
+
149
+ let local_position = vec4<f32>(
150
+ vec2<f32>(attributes.a_position.xy) + extrusion + offset,
151
+ f32(attributes.a_z_and_offset_scale.x) / ${Geo.height_scale}.0 ${terrain ? '+ tangramTerrainHeight(attributes.a_terrain, attributes.a_terrain_previous) + tangramTerrainRibbonOffset(extrusion + offset, vec2<f32>(attributes.a_position.xy), attributes.a_terrain, attributes.a_terrain_previous)' : ''},
152
+ 1.0
153
+ );
154
+ let eye_position = ${cpuProjection ? 'vec4<f32>(attributes.a_projected_position, 1.0)' : terrain ? 'tangramTerrainModelView(local_position, attributes.a_terrain, attributes.a_terrain_previous, attributes.a_terrain_globe_base, attributes.a_terrain_globe_relief, attributes.a_terrain_globe_base_previous, attributes.a_terrain_globe_relief_previous)' : 'tangramModelView(local_position)'};
155
+ var clip_position = TangramCamera.u_projection * eye_position;
156
+ ${cpuProjection ? 'clip_position.z = (clip_position.z + clip_position.w) * 0.5;' : ''}
157
+ ${cpuProjection ? `
158
+ if (attributes.a_projected_stroke.w > 0.0) {
159
+ let center = TangramCamera.u_projection * vec4<f32>(attributes.a_projected_stroke.xy, 0.0, 1.0);
160
+ let direction = (clip_position.xy / clip_position.w - center.xy / center.w) * TangramView.u_resolution;
161
+ let magnitude = length(direction);
162
+ let normalized_direction = direction / max(magnitude, 0.000001);
163
+ clip_position.x = center.x + normalized_direction.x * attributes.a_projected_stroke.z *
164
+ TangramView.u_device_pixel_ratio * 2.0 / TangramView.u_resolution.x * center.w;
165
+ clip_position.y = center.y + normalized_direction.y * attributes.a_projected_stroke.z *
166
+ TangramView.u_device_pixel_ratio * 2.0 / TangramView.u_resolution.y * center.w;
167
+ }
168
+ ` : ''}
169
+ let layer = f32(attributes.a_position.w) +
170
+ TangramTile.u_tile_proxy_order_offset + 1.0;
171
+ clip_position.z -= layer * ${cpuProjection ? LAYER_DELTA * 0.5 : LAYER_DELTA} * clip_position.w;
172
+
173
+ output.position = clip_position;
174
+ output.tile_position = local_position.xy;
175
+ output.color = attributes.a_color;
176
+ output.texcoord = attributes.a_texcoord / 65535.0;
177
+ output.texcoord.y *= TangramLine.u_v_scale_adjust;
178
+ ${configured ? `
179
+ var local_normal = vec3<f32>(0.0, 0.0, 1.0);
180
+ ${terrain ? 'local_normal = tangramTerrainNormal(local_normal, attributes.a_terrain, attributes.a_terrain_previous, vec2<f32>(attributes.a_position.xy) + vec2<f32>(attributes.a_terrain.w, attributes.a_terrain_previous.w));' : ''}
181
+ var normal = normalize(TangramTile.u_normalMatrix * local_normal);
182
+ if (TangramView.u_projection_mode == 1) {
183
+ normal = tangramGlobeNormal((TangramTile.u_model * local_position).xyz, local_normal);
184
+ }
185
+ output.normal = normal;
186
+ output.eye_position = eye_position.xyz - TangramCamera.u_eye;
187
+ output.lighting = ${lighting === 'vertex' ? 'tangramCalculateLighting(output.eye_position, normal, vec4<f32>(1.0))' : 'vec4<f32>(1.0)'};
188
+ ` : ''}
189
+ return output;
190
+ }
191
+
192
+ @fragment
193
+ fn fragmentMain(input: LineVaryings) -> @location(0) vec4<f32> {
194
+ if (TangramTile.u_tile_clip_bounds.z > TangramTile.u_tile_clip_bounds.x &&
195
+ (any(input.tile_position < TangramTile.u_tile_clip_bounds.xy) ||
196
+ any(input.tile_position >= TangramTile.u_tile_clip_bounds.zw))) { discard; }
197
+ var color = input.color;
198
+ if (TangramLine.u_has_line_texture != 0u) {
199
+ let line_texcoord = vec2<f32>(
200
+ input.texcoord.x,
201
+ fract(input.texcoord.y / TangramLine.u_texture_ratio)
202
+ );
203
+ let line_color = textureSample(u_texture, u_textureSampler, line_texcoord);
204
+ let textured_color = color * line_color;
205
+ let dashed_color = mix(
206
+ TangramLine.u_dash_background_color,
207
+ color,
208
+ line_color.a
209
+ );
210
+ color = mix(
211
+ textured_color,
212
+ dashed_color,
213
+ clamp(TangramLine.u_has_dash, 0.0, 1.0)
214
+ );
215
+ if (color.a < 0.001) {
216
+ discard;
217
+ }
218
+ }
219
+ ${animated_fragment}
220
+ ${lighting === 'fragment' ? 'color = tangramCalculateLighting(input.eye_position, normalize(input.normal), color);' : lighting === 'vertex' ? 'color *= input.lighting;' : ''}
221
+ return ${selection ? 'input.selection_color' : 'color'};
222
+ }
223
+ `;
224
+ }
@@ -0,0 +1,125 @@
1
+ // tangram-layers
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {StyleRuntime, StyleInitOptions, BuildMesh, BuildTileData, BuildFeatureStyle} from '../style-runtime-types';
6
+ import type {TextLabelRuntime} from '../text/text_labels';
7
+ import type {TextFeature, TextContext, TextTile, TextGeometry, TextLabelDraw, ParsedTextFeature, TextFeatureQueue, TextLabelCandidate, TextRenderLabel, TextSprite} from '../text/text-types';
8
+ import type {PropertyCache, PointSizeCache, PointSizeImage} from '../property-types';
9
+ import type {LabelLayout, LabelPointCoordinate} from '../../labels/label-types';
10
+ import type {CollisionObject} from '../../labels/collision-types';
11
+ import type LabelPoint from '../../labels/label_point';
12
+ import type VertexData from '../../gl/vertex_data';
13
+ import type VertexLayout from '../../gl/vertex_layout';
14
+ import type {WorkerBuildTile, TileMeshVariant, TileStylePayload} from '../../tile/tile-build-types';
15
+ import type {GeometryMeshVariant} from '../geometry-style-types';
16
+ import type {MeshElementData} from '../../gl/mesh-types';
17
+ import type VBOMesh from '../../gl/vbo_mesh';
18
+ import type {buildQuadForPoint} from '../../builders/points';
19
+
20
+ /** Point evaluation includes the worker build ownership retained by attached text. */
21
+ export interface PointContext extends TextContext {tile: WorkerBuildTile & TextTile; layers: string[];}
22
+ /** Point caches after normalization; authored extension values remain unresolved. */
23
+ export interface PointDraw extends TextLabelDraw {
24
+ layers?: string[];
25
+ group?: string;
26
+ style?: string;
27
+ order?: unknown;
28
+ interactive?: unknown;
29
+ anchor?: string | string[];
30
+ priority?: number | ((context: import('../property-types').PropertyContext) => number);
31
+ color?: PropertyCache;
32
+ alpha?: PropertyCache;
33
+ texture?: string;
34
+ sprite?: unknown;
35
+ sprite_default?: string;
36
+ size?: PointSizeCache;
37
+ outline?: {width?: PropertyCache; color?: PropertyCache; alpha?: PropertyCache};
38
+ placement?: number | string;
39
+ placement_spacing?: PropertyCache;
40
+ placement_min_length_ratio?: PropertyCache;
41
+ offset?: PropertyCache;
42
+ buffer?: PropertyCache;
43
+ repeat_distance?: PropertyCache;
44
+ repeat_group?: string | ((context: import('../property-types').PropertyContext) => string);
45
+ angle?: number | 'auto' | ((context: PointContext) => number);
46
+ tile_edges?: boolean;
47
+ text?: TextLabelDraw & {visible?: boolean; priority?: unknown; optional?: boolean; group?: string; layers?: string[]; order?: unknown; anchor?: string | string[]; interactive?: unknown};
48
+ }
49
+ /** Scratch feature values span parent points and straight/curved attached text. */
50
+ export interface PointFeatureStyle extends BuildFeatureStyle, Partial<LabelLayout> {
51
+ color?: number[];
52
+ alpha?: number;
53
+ texture?: string;
54
+ label_texture?: string | null;
55
+ label_textures?: string[];
56
+ blend_order?: number;
57
+ size?: LabelPointCoordinate | {straight?: LabelPointCoordinate; curved?: LabelPointCoordinate[]};
58
+ texcoords?: number[] | {straight?: TextSprite; curved?: TextSprite[]};
59
+ texcoords_stroke?: number[][];
60
+ outline_width?: number;
61
+ outline_color?: number[];
62
+ outline_edge_pct?: number;
63
+ outline_alpha?: number;
64
+ z?: number;
65
+ label?: TextRenderLabel;
66
+ linked?: CollisionObject['linked'];
67
+ }
68
+ /** Independent texture/blend permutation, separate from vertex-layout permutations. */
69
+ export type PointMeshVariant = GeometryMeshVariant & TileMeshVariant & {shader_point: boolean; point_type: number};
70
+ /** Mutable pre-finalization point mesh; no transferred byte facade is accepted here. */
71
+ export type PointBuildMesh = BuildMesh;
72
+ /** Vertex templates consume layout/variant capabilities, not GPU resource ownership. */
73
+ export interface PointTemplateMesh {vertex_data: {vertex_layout: Pick<VertexLayout, 'index'>}; variant: {shader_point?: unknown; selection?: unknown; point_type?: unknown};}
74
+ /** A point may own optional attached text before collision placement. */
75
+ export interface PointFeatureQueue {feature: TextFeature; draw: PointDraw; context: PointContext; style: PointFeatureStyle; text_feature?: ParsedTextFeature | false | null;}
76
+ /** Collision placement adds a label and optional two-way text linkage. */
77
+ export interface PointCandidate extends Omit<PointFeatureQueue, 'text_feature'>, CollisionObject {label: LabelPoint;}
78
+ /** Attached text retains its parent anchor until the text mixin builds the final label. */
79
+ export interface AttachedTextQueue extends TextFeatureQueue {point_label: LabelPoint; linked: PointCandidate; label?: LabelPoint;}
80
+ /** Point-owned state in addition to inherited base and text-label lifecycles. */
81
+ export interface PointState {
82
+ feature_style: PointFeatureStyle;
83
+ queues: Record<string | number, PointFeatureQueue[]>;
84
+ collision_group_points: string;
85
+ collision_group_text: string;
86
+ fade_in_time: number;
87
+ texture_missing_sprites: Record<string, Record<string, boolean>>;
88
+ texture?: string;
89
+ variants: Record<string, PointMeshVariant>;
90
+ default_anchor: string[];
91
+ }
92
+ /** Checked concrete point operations; inherited base methods retain their own contracts. */
93
+ export interface PointMethods {
94
+ getWGSLShaderSource(selection?: boolean): string;
95
+ init(options?: StyleInitOptions): void;
96
+ setupDefines(): void;
97
+ reset(): void;
98
+ addFeature(feature: TextFeature, draw: PointDraw, context: PointContext): void;
99
+ calcSize(draw: PointDraw, style: PointFeatureStyle, sprite: PointSizeImage | null | undefined, context: PointContext): void;
100
+ hasSprites(style: PointFeatureStyle): unknown;
101
+ getSpriteInfo(style: PointFeatureStyle, sprite?: string): (PointSizeImage & {texcoords: number[]}) | null | undefined;
102
+ parseSprite(style: PointFeatureStyle, draw: PointDraw, context: PointContext): (PointSizeImage & {texcoords: number[]}) | null | undefined;
103
+ queueFeature(feature: PointFeatureQueue, tile: WorkerBuildTile & TextTile): void;
104
+ endData(tile: WorkerBuildTile & TextTile): Promise<BuildTileData<Uint8Array> | null>;
105
+ _preprocess(draw: PointDraw): PointDraw | null;
106
+ computeLayout(target: Partial<LabelLayout>, feature: Pick<TextFeature, 'id' | 'properties'>, draw: PointDraw, context: Pick<TextContext, 'layer'> & Record<string, unknown>, tile: Pick<TextTile, 'units_per_pixel'>): LabelLayout;
107
+ buildTextLabels(tile: TextTile, queue: TextFeatureQueue[]): TextLabelCandidate[];
108
+ buildLabels(size: LabelPointCoordinate, geometry: TextGeometry, layout: LabelLayout): LabelPoint[];
109
+ makeVertexTemplate(style: PointFeatureStyle, mesh: PointTemplateMesh, addCustom?: boolean): number[];
110
+ buildQuad(point: Parameters<typeof buildQuadForPoint>[0], size: LabelPointCoordinate, angle: number,
111
+ angles: Parameters<typeof buildQuadForPoint>[9] | null, preAngles: Parameters<typeof buildQuadForPoint>[7] | null, offset: Parameters<typeof buildQuadForPoint>[5],
112
+ offsets: Parameters<typeof buildQuadForPoint>[6] | null, texcoords: Parameters<typeof buildQuadForPoint>[10], curve: boolean, data: VertexData, template: number[]): number;
113
+ build(style: PointFeatureStyle, context: PointContext): number;
114
+ buildStraightLabel(label: Exclude<TextRenderLabel, {type: 'curved'}>, style: PointFeatureStyle, context: PointContext): number;
115
+ buildCurvedLabel(label: Extract<TextRenderLabel, {num_segments: number}>, style: PointFeatureStyle, context: PointContext): number;
116
+ trackLabel(label: TextRenderLabel, linked: number | string | null | undefined, mesh: PointBuildMesh, count: number, context?: PointContext): void;
117
+ buildLines(lines: number[][][], style: PointFeatureStyle, context: PointContext): number;
118
+ buildPoints(points: number[][], style: PointFeatureStyle, context: PointContext): number;
119
+ buildPolygons(polygons: number[][][][], style: PointFeatureStyle, context: PointContext): number;
120
+ vertexLayoutForMeshVariant(variant: GeometryMeshVariant & TileMeshVariant): VertexLayout;
121
+ meshVariantTypeForDraw(draw: PointFeatureStyle): PointMeshVariant;
122
+ makeMesh(vertices: Uint8Array, elements: MeshElementData, options?: Partial<TileStylePayload>): VBOMesh;
123
+ }
124
+ /** Prototype/mixin style with concrete state and inherited checked operations. */
125
+ export type PointStyleRuntime = Omit<StyleRuntime, keyof PointState | keyof PointMethods> & TextLabelRuntime & PointState & PointMethods;