@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,268 @@
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
+ // Polygon rendering style
7
+
8
+ import type {GeometryStyleRuntime, GeometryFeature, GeometryDraw, RawGeometryDraw, GeometryContext, GeometryMeshVariant, PolygonFeatureStyle, GeometryBuildMesh, GeometryExtrusion} from '../geometry-style-types';
9
+ import type {GeometryPolygon} from '../../builders/geometry-types';
10
+
11
+ import {Style} from '../style';
12
+ import StyleParser from '../style_parser';
13
+ import gl from '../../gl/constants'; // web workers don't have access to GL context, so import all GL constants
14
+ import VertexLayout from '../../gl/vertex_layout';
15
+ import {buildPolygons, buildExtrudedPolygons} from '../../builders/polygons';
16
+ import Geo from '../../utils/geo';
17
+
18
+ import polygons_vs from './polygons_vertex.glsl';
19
+ import polygons_fs from './polygons_fragment.glsl';
20
+ import {buildPolygonsWGSL} from './polygons_wgsl';
21
+ import {GLOBE_PROJECTION_GLSL, TERRAIN_DRAPING_GLSL} from '../../scene/projection_shaders';
22
+
23
+ export const Polygons: GeometryStyleRuntime = Object.create(Style);
24
+
25
+ Object.assign(Polygons, {
26
+ name: 'polygons',
27
+ built_in: true,
28
+ vertex_shader_src: polygons_vs.replace('#pragma tangram: projection', GLOBE_PROJECTION_GLSL + TERRAIN_DRAPING_GLSL),
29
+ fragment_shader_src: polygons_fs,
30
+ selection: true, // enable feature selection
31
+
32
+ getWGSLShaderSource(this: GeometryStyleRuntime, selection = false) {
33
+ return buildPolygonsWGSL({ raster: this.raster === 'color', lighting: this.portable_lighting_mode,
34
+ lightCount: this.portable_light_count, cpuProjection: Boolean(this.cpu_projection), terrain: Boolean(this.terrain), selection });
35
+ },
36
+
37
+ init(this: GeometryStyleRuntime) {
38
+ Style.init.apply(this, arguments as unknown as Parameters<typeof Style.init>);
39
+
40
+ // Tell the shader about optional attributes (shader is shared with lines style, which has different config)
41
+ this.defines.TANGRAM_NORMAL_ATTRIBUTE = true;
42
+ this.defines.TANGRAM_TEXTURE_COORDS = this.texcoords;
43
+ this.defines.TANGRAM_CPU_PROJECTED = Boolean(this.cpu_projection && ['polygons', 'raster'].includes(this.baseStyle()));
44
+ const positionBlocks = this.shaders?.blocks?.position;
45
+ const attributes = this.shaders?.attributes;
46
+ const hasPositionBlocks = Array.isArray(positionBlocks) ? positionBlocks.length > 0 : Boolean(positionBlocks);
47
+ const hasAttributes = attributes && typeof attributes === 'object' ? Object.keys(attributes).length > 0 : Boolean(attributes);
48
+ if (this.cpu_projection && ['polygons', 'raster'].includes(this.baseStyle()) &&
49
+ (hasPositionBlocks || hasAttributes)) {
50
+ throw new Error('CPU projection requires unlit polygons without position blocks or custom attributes');
51
+ }
52
+ },
53
+
54
+ _parseFeature (this: GeometryStyleRuntime, feature: GeometryFeature, draw: GeometryDraw, context: GeometryContext) {
55
+ var style = this.feature_style;
56
+
57
+ style.color = this.parseColor(draw.color, context);
58
+ if (!style.color) {
59
+ return null;
60
+ }
61
+
62
+ style.alpha = StyleParser.evalCachedProperty(draw.alpha, context) as number | undefined; // optional alpha override
63
+
64
+ style.variant = draw.variant; // pre-calculated mesh variant
65
+
66
+ style.z = (StyleParser.evalCachedDistanceProperty(draw.z, context) as number) || StyleParser.defaults.z;
67
+ style.z *= Geo.height_scale; // provide sub-meter precision of height values
68
+
69
+ style.extrude = StyleParser.evalProperty(draw.extrude, context) as GeometryExtrusion;
70
+ if (style.extrude) {
71
+ // use feature's height and min_height properties
72
+ if (style.extrude === true) {
73
+ style.height = feature.properties.height || StyleParser.defaults.height;
74
+ style.min_height = feature.properties.min_height || StyleParser.defaults.min_height;
75
+
76
+ }
77
+ // explicit height, no min_height
78
+ else if (typeof style.extrude === 'number') {
79
+ style.height = style.extrude;
80
+ style.min_height = 0;
81
+ }
82
+ // explicit height and min_height
83
+ else if (Array.isArray(style.extrude)) {
84
+ style.min_height = style.extrude[0];
85
+ style.height = style.extrude[1];
86
+ }
87
+
88
+ style.height *= Geo.height_scale; // provide sub-meter precision of height values
89
+ style.min_height *= Geo.height_scale;
90
+ }
91
+
92
+ if (this.cpu_projection) {
93
+ const heights = style.extrude ? [style.z + style.min_height, style.z + style.height] : [style.z];
94
+ if (heights.some(height => !Number.isFinite(height) || height < -32768 || height > 32767)) {
95
+ throw new Error('Projected polygon height exceeds signed 16-bit meter packing');
96
+ }
97
+ if (!this.cpu_projection.allowElevation && heights.some(height => height !== 0)) {
98
+ throw new Error('Projected polygon elevation requires allowElevation');
99
+ }
100
+ }
101
+ style.tile_edges = draw.tile_edges; // usually activated for debugging, or rare visualization needs
102
+
103
+ return style;
104
+ },
105
+
106
+ _preprocess (this: GeometryStyleRuntime, draw: RawGeometryDraw) {
107
+ draw.color = StyleParser.createColorPropertyCache(draw.color);
108
+ draw.alpha = StyleParser.createPropertyCache(draw.alpha);
109
+ draw.z = StyleParser.createPropertyCache(draw.z, StyleParser.parseUnits);
110
+ this.computeVariant(draw);
111
+ // Cache creation is the normalization boundary for authored draw values.
112
+ return draw as GeometryDraw;
113
+ },
114
+
115
+ // Calculate and store mesh variant (unique by draw group but not feature)
116
+ computeVariant (this: GeometryStyleRuntime, draw: GeometryDraw | RawGeometryDraw) {
117
+ // Factors that determine a unique mesh rendering variant
118
+ const selection = (draw.interactive ? 1 : 0); // whether feature has interactivity
119
+ const normal = (draw.extrude != null ? 1 : 0); // whether feature has extrusion (need per-vertex normals)
120
+ const texcoords = (this.texcoords ? 1 : 0); // whether feature has texture UVs
121
+ const blend_order = this.getBlendOrderForDraw(draw);
122
+ const key = [selection, normal, texcoords, blend_order].join('/');
123
+ draw.variant = key;
124
+
125
+ if (this.variants[key] == null) {
126
+ this.variants[key] = {
127
+ key,
128
+ blend_order,
129
+ mesh_order: 0,
130
+ selection,
131
+ normal,
132
+ texcoords
133
+ };
134
+ }
135
+ },
136
+
137
+ // Override
138
+ // Create or return desired vertex layout permutation based on flags
139
+ vertexLayoutForMeshVariant (this: GeometryStyleRuntime, variant: GeometryMeshVariant) {
140
+ if (this.vertex_layouts[variant.key] == null) {
141
+ const portable_normal = this.shader_language === 'wgsl';
142
+ // Attributes for this mesh variant
143
+ // Optional attributes have placeholder values assigned with `static` parameter
144
+ const attribs = [
145
+ { name: 'a_position', size: 4, type: gl.SHORT, normalized: false },
146
+ {
147
+ name: 'a_normal',
148
+ size: portable_normal ? 4 : 3,
149
+ type: gl.BYTE,
150
+ normalized: true,
151
+ static: (variant.normal || portable_normal ? null : [0, 0, 1])
152
+ }, // gets padded to 4-bytes
153
+ { name: 'a_color', size: 4, type: gl.UNSIGNED_BYTE, normalized: true },
154
+ { name: 'a_selection_color', size: 4, type: gl.UNSIGNED_BYTE, normalized: true, static: (variant.selection || portable_normal ? null : [0, 0, 0, 0]) },
155
+ { name: 'a_texcoord', size: 2, type: gl.UNSIGNED_SHORT, normalized: true, static: (variant.texcoords ? null : [0, 0]) }
156
+ ];
157
+
158
+ this.addCustomAttributesToAttributeList(attribs);
159
+ if (this.cpu_projection && ['polygons', 'raster'].includes(this.baseStyle())) {
160
+ attribs.push({name: 'a_projected_position', size: 3, type: gl.FLOAT, normalized: false});
161
+ attribs.push({name: 'a_projected_normal', size: 3, type: gl.FLOAT, normalized: false});
162
+ }
163
+ this.vertex_layouts[variant.key] = new VertexLayout(attribs);
164
+ }
165
+ return this.vertex_layouts[variant.key];
166
+ },
167
+
168
+ // Override
169
+ meshVariantTypeForDraw (this: GeometryStyleRuntime, draw: Pick<GeometryDraw, 'variant'>) {
170
+ return this.variants[draw.variant]; // return pre-calculated mesh variant
171
+ },
172
+
173
+ /**
174
+ * A "template" that sets constant attibutes for each vertex, which is then modified per vertex or per feature.
175
+ * A plain JS array matching the order of the vertex layout.
176
+ */
177
+ makeVertexTemplate(this: GeometryStyleRuntime, style: PolygonFeatureStyle, mesh: GeometryBuildMesh) {
178
+ let i = 0;
179
+
180
+ // a_position.xyz - vertex position
181
+ // a_position.w - layer order
182
+ this.vertex_template[i++] = 0;
183
+ this.vertex_template[i++] = 0;
184
+ this.vertex_template[i++] = style.z || 0;
185
+ this.vertex_template[i++] = this.scaleOrder(style.order);
186
+
187
+ // a_normal.xyz - surface normal
188
+ // only stored per-vertex for extruded features (hardcoded to 'up' for others)
189
+ if (mesh.variant.normal || this.shader_language === 'wgsl') {
190
+ this.vertex_template[i++] = 0;
191
+ this.vertex_template[i++] = 0;
192
+ this.vertex_template[i++] = 1 * 127;
193
+ if (this.shader_language === 'wgsl') {
194
+ this.vertex_template[i++] = 0;
195
+ }
196
+ }
197
+
198
+ // a_color.rgba - feature color
199
+ this.vertex_template[i++] = style.color[0] * 255;
200
+ this.vertex_template[i++] = style.color[1] * 255;
201
+ this.vertex_template[i++] = style.color[2] * 255;
202
+ this.vertex_template[i++] = (style.alpha != null ? style.alpha : style.color[3]) * 255;
203
+
204
+ // a_selection_color.rgba - selection color
205
+ if (mesh.variant.selection || this.shader_language === 'wgsl') {
206
+ this.vertex_template[i++] = style.selection_color[0] * 255;
207
+ this.vertex_template[i++] = style.selection_color[1] * 255;
208
+ this.vertex_template[i++] = style.selection_color[2] * 255;
209
+ this.vertex_template[i++] = style.selection_color[3] * 255;
210
+ }
211
+
212
+ // a_texcoord.uv - texture coordinates
213
+ if (mesh.variant.texcoords) {
214
+ this.vertex_template[i++] = 0;
215
+ this.vertex_template[i++] = 0;
216
+ }
217
+
218
+ this.addCustomAttributesToVertexTemplate(style, i);
219
+ if (this.cpu_projection) {
220
+ const projectedIndex = mesh.vertex_data.vertex_layout.index.a_projected_position;
221
+ this.vertex_template[projectedIndex] = 0;
222
+ this.vertex_template[projectedIndex + 1] = 0;
223
+ this.vertex_template[projectedIndex + 2] = 0;
224
+ const normalIndex = mesh.vertex_data.vertex_layout.index.a_projected_normal;
225
+ if (normalIndex !== undefined) {
226
+ this.vertex_template[normalIndex] = 0;
227
+ this.vertex_template[normalIndex + 1] = 0;
228
+ this.vertex_template[normalIndex + 2] = 1;
229
+ }
230
+ }
231
+ return this.vertex_template;
232
+ },
233
+
234
+ buildPolygons(this: GeometryStyleRuntime, polygons: GeometryPolygon[], style: PolygonFeatureStyle, context: GeometryContext) {
235
+ let mesh = this.getTileMesh(context.tile, this.meshVariantTypeForDraw(style));
236
+ let vertex_data = mesh.vertex_data;
237
+ let vertex_layout = vertex_data.vertex_layout;
238
+ let vertex_template = this.makeVertexTemplate(style, mesh);
239
+ let options = {
240
+ texcoord_index: vertex_layout.index.a_texcoord,
241
+ texcoord_normalize: 65535, // scale UVs to unsigned shorts
242
+ remove_tile_edges: !style.tile_edges,
243
+ tile_edge_tolerance: Geo.tile_scale * context.tile.pad_scale * 4,
244
+ winding: context.winding
245
+ };
246
+
247
+ // Extruded polygons (e.g. 3D buildings)
248
+ if (style.extrude && style.height) {
249
+ return buildExtrudedPolygons(
250
+ polygons,
251
+ style.z, style.height, style.min_height,
252
+ vertex_data, vertex_template,
253
+ vertex_layout.index.a_normal,
254
+ 127, // scale normals to signed bytes
255
+ options
256
+ );
257
+ }
258
+ // Regular polygons
259
+ else {
260
+ return buildPolygons(
261
+ polygons,
262
+ vertex_data, vertex_template,
263
+ options
264
+ );
265
+ }
266
+ }
267
+
268
+ } satisfies Partial<GeometryStyleRuntime>);
@@ -0,0 +1,173 @@
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_meters_per_pixel;
11
+ uniform float u_device_pixel_ratio;
12
+ uniform mat3 u_normalMatrix;
13
+ uniform mat3 u_inverseNormalMatrix;
14
+ #ifndef TANGRAM_UNIFORM_BLOCK_TANGRAMVIEW
15
+ uniform highp int u_projection_mode;
16
+ #endif
17
+
18
+ varying vec4 v_position;
19
+ varying vec3 v_normal;
20
+ varying vec4 v_color;
21
+ varying vec4 v_world_position;
22
+ varying vec2 v_tile_position;
23
+ uniform vec4 u_tile_clip_bounds;
24
+
25
+ #ifdef TANGRAM_EXTRUDE_LINES
26
+ uniform bool u_has_line_texture;
27
+ uniform sampler2D u_texture;
28
+ uniform float u_texture_ratio;
29
+ uniform vec4 u_dash_background_color;
30
+ uniform float u_has_dash;
31
+ #endif
32
+
33
+ #define TANGRAM_NORMAL v_normal
34
+
35
+ #if defined(TANGRAM_TEXTURE_COORDS) || defined(TANGRAM_EXTRUDE_LINES)
36
+ varying vec2 v_texcoord;
37
+ #endif
38
+
39
+ #ifdef TANGRAM_MODEL_POSITION_BASE_ZOOM_VARYING
40
+ varying vec4 v_modelpos_base_zoom;
41
+ #endif
42
+
43
+ #if defined(TANGRAM_LIGHTING_VERTEX)
44
+ varying vec4 v_lighting;
45
+ #endif
46
+
47
+ #pragma tangram: attributes
48
+ #pragma tangram: camera
49
+ #pragma tangram: material
50
+ #pragma tangram: lighting
51
+ #pragma tangram: raster
52
+ #pragma tangram: global
53
+
54
+ void main (void) {
55
+ if (u_tile_clip_bounds.z > u_tile_clip_bounds.x &&
56
+ (any(lessThan(v_tile_position, u_tile_clip_bounds.xy)) ||
57
+ any(greaterThanEqual(v_tile_position, u_tile_clip_bounds.zw)))) discard;
58
+ // Initialize globals
59
+ #pragma tangram: setup
60
+
61
+ vec4 color = v_color;
62
+ // Interpolated radial/tangent normals are not unit length between vertices.
63
+ vec3 normal = u_projection_mode == 1 ? normalize(TANGRAM_NORMAL) : TANGRAM_NORMAL;
64
+
65
+ // Apply raster to vertex color
66
+ #ifdef TANGRAM_RASTER_TEXTURE_COLOR
67
+ vec4 _raster_color = sampleRaster(0);
68
+
69
+ #if defined(TANGRAM_BLEND_OPAQUE) || defined(TANGRAM_BLEND_TRANSLUCENT) || defined(TANGRAM_BLEND_MULTIPLY)
70
+ // Raster sources can optionally mask by the alpha channel, which will render with only full or no alpha.
71
+ // This is used for handling transparency outside the raster image in some blend modes,
72
+ // which either don't support alpha, or would cause transparent pixels to write to the depth buffer,
73
+ // obscuring geometry underneath.
74
+ #ifdef TANGRAM_HAS_MASKED_RASTERS // skip masking logic if no masked raster sources
75
+ #ifndef TANGRAM_ALL_MASKED_RASTERS // skip source check for masking if *all* raster sources are masked
76
+ if (u_raster_mask_alpha) {
77
+ #else
78
+ {
79
+ #endif
80
+ #if defined(TANGRAM_BLEND_TRANSLUCENT) || defined(TANGRAM_BLEND_MULTIPLY)
81
+ if (_raster_color.a < TANGRAM_EPSILON) {
82
+ discard;
83
+ }
84
+ #else // TANGRAM_BLEND_OPAQUE
85
+ if (_raster_color.a < 1. - TANGRAM_EPSILON) {
86
+ discard;
87
+ }
88
+ // only allow full alpha in opaque blend mode (avoids artifacts blending w/canvas tile background)
89
+ _raster_color.a = 1.;
90
+ #endif
91
+ }
92
+ #endif
93
+ #endif
94
+
95
+ color *= _raster_color; // multiplied to tint texture color
96
+ #endif
97
+
98
+ // Apply line texture
99
+ #ifdef TANGRAM_EXTRUDE_LINES
100
+ { // enclose in scope to avoid leakage of internal variables
101
+ if (u_has_line_texture) {
102
+ vec2 _line_st = vec2(v_texcoord.x, fract(v_texcoord.y / u_texture_ratio));
103
+ vec4 _line_color = texture2D(u_texture, _line_st);
104
+
105
+ // If the line has a dash pattern, the line texture indicates if the current fragment should be
106
+ // the dash foreground or background color. If the line doesn't have a dash pattern,
107
+ // the line texture color is used directly (but also tinted by the vertex color).
108
+ color = mix(
109
+ color * _line_color, // no dash: tint the line texture with the vertex color
110
+ mix(u_dash_background_color, color, _line_color.a), // choose dash foreground or background color
111
+ u_has_dash // 0 if no dash, 1 if has dash
112
+ );
113
+
114
+ // Use alpha discard test as a lower-quality substitute for blending
115
+ #if defined(TANGRAM_BLEND_OPAQUE)
116
+ if (color.a < TANGRAM_ALPHA_TEST) {
117
+ discard;
118
+ }
119
+ #endif
120
+ }
121
+ }
122
+ #endif
123
+
124
+ #ifdef TANGRAM_PROJECTED_TRAFFIC
125
+ float direction = v_texcoord.x < .5 ? 1. : -1.;
126
+ float phase = direction > 0. ? 2.75 : 0.;
127
+ float coordinate = v_texcoord.y * .125 - u_time * 1.8 * direction + phase;
128
+ float vehicle_position = fract(coordinate / 6.);
129
+ float derivative = max(fwidth(vehicle_position), .001);
130
+ float half_length = max(.022, derivative * 1.35);
131
+ float distance = abs(vehicle_position - .5);
132
+ float body = 1. - smoothstep(half_length, half_length + derivative, distance);
133
+ float halo = 1. - smoothstep(half_length + derivative, half_length + derivative * 2.5, distance);
134
+ float lane_center = direction > 0. ? .28 : .72;
135
+ float lane_derivative = max(fwidth(v_texcoord.x), .01);
136
+ float half_width = clamp(lane_derivative * .45, .10, .22);
137
+ float lane_edge = clamp(lane_derivative * .35, .02, .18);
138
+ float lane = 1. - smoothstep(half_width, half_width + lane_edge, abs(v_texcoord.x - lane_center));
139
+ color.rgb = mix(color.rgb, vec3(.62, 1., .98), max(body, halo * .35) * lane * .98);
140
+ #endif
141
+
142
+ // First, get normal from raster tile (if applicable)
143
+ #ifdef TANGRAM_RASTER_TEXTURE_NORMAL
144
+ normal = normalize(sampleRaster(0).rgb * 2. - 1.);
145
+ #endif
146
+
147
+ // Second, alter normal with normal map texture (if applicable)
148
+ #if defined(TANGRAM_LIGHTING_FRAGMENT) && defined(TANGRAM_MATERIAL_NORMAL_TEXTURE)
149
+ calculateNormal(normal);
150
+ #endif
151
+
152
+ // Normal modification applied here for fragment lighting or no lighting,
153
+ // and in vertex shader for vertex lighting
154
+ #if !defined(TANGRAM_LIGHTING_VERTEX)
155
+ #pragma tangram: normal
156
+ #endif
157
+
158
+ // Color modification before lighting is applied
159
+ #pragma tangram: color
160
+
161
+ #if defined(TANGRAM_LIGHTING_FRAGMENT)
162
+ // Calculate per-fragment lighting
163
+ color = calculateLighting(v_position.xyz - u_eye, normal, color);
164
+ #elif defined(TANGRAM_LIGHTING_VERTEX)
165
+ // Apply lighting intensity interpolated from vertex shader
166
+ color *= v_lighting;
167
+ #endif
168
+
169
+ // Post-processing effects (modify color after lighting)
170
+ #pragma tangram: filter
171
+
172
+ gl_FragColor = color;
173
+ }
@@ -0,0 +1,213 @@
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 float u_meters_per_pixel;
12
+ uniform float u_device_pixel_ratio;
13
+ #ifndef TANGRAM_UNIFORM_BLOCK_TANGRAMVIEW
14
+ uniform highp int u_projection_mode;
15
+ #endif
16
+ uniform mat4 u_model;
17
+ uniform mat4 u_modelView;
18
+ uniform mat3 u_normalMatrix;
19
+ uniform mat3 u_inverseNormalMatrix;
20
+
21
+ attribute vec4 a_position;
22
+ attribute vec4 a_color;
23
+ #ifdef TANGRAM_CPU_PROJECTED
24
+ attribute vec3 a_projected_position;
25
+ #ifndef TANGRAM_EXTRUDE_LINES
26
+ attribute vec3 a_projected_normal;
27
+ #endif
28
+ #endif
29
+
30
+ // Optional normal attribute, otherwise default to up
31
+ #ifdef TANGRAM_NORMAL_ATTRIBUTE
32
+ attribute vec3 a_normal;
33
+ #define TANGRAM_NORMAL a_normal
34
+ #else
35
+ #define TANGRAM_NORMAL vec3(0., 0., 1.)
36
+ #endif
37
+
38
+ // Optional dynamic line extrusion
39
+ #ifdef TANGRAM_EXTRUDE_LINES
40
+ attribute vec2 a_extrude; // extrusion direction in xy plane
41
+ attribute vec2 a_offset; // offset direction in xy plane
42
+
43
+ // Polygon and line styles have slightly different VBO layouts, saving memory by optimizing vertex packing.
44
+ // All lines have a width scaling factor, but only some have a height (position.z) or offset.
45
+ // The vertex height is stored in different attributes to account for this.
46
+ attribute vec2 a_z_and_offset_scale; // stores vertex height in x, and offset scaling factor in y
47
+ #ifdef TANGRAM_CPU_PROJECTED
48
+ attribute vec4 a_projected_stroke; // projected center.xy, CSS radius, nonzero pixel marker
49
+ #endif
50
+ #define TANGRAM_POSITION_Z a_z_and_offset_scale.x // vertex height is stored in separate line-specific attrib
51
+ #define TANGRAM_OFFSET_SCALING a_z_and_offset_scale.y // zoom scaling factor for line offset
52
+ #define TANGRAM_WIDTH_SCALING a_position.z // zoom scaling factor for line width (stored in position attrib)
53
+
54
+ uniform float u_v_scale_adjust; // scales texture UVs for line dash patterns w/fractional pixel width
55
+ #else
56
+ #define TANGRAM_POSITION_Z a_position.z // vertex height
57
+ #endif
58
+
59
+ varying vec4 v_position;
60
+ varying vec3 v_normal;
61
+ varying vec4 v_color;
62
+ varying vec4 v_world_position;
63
+ varying vec2 v_tile_position;
64
+
65
+ // Optional texture UVs
66
+ #if defined(TANGRAM_TEXTURE_COORDS) || defined(TANGRAM_EXTRUDE_LINES)
67
+ attribute vec2 a_texcoord;
68
+ varying vec2 v_texcoord;
69
+ #endif
70
+
71
+ // Optional model position varying for tile coordinate zoom
72
+ #ifdef TANGRAM_MODEL_POSITION_BASE_ZOOM_VARYING
73
+ varying vec4 v_modelpos_base_zoom;
74
+ #endif
75
+
76
+ #if defined(TANGRAM_LIGHTING_VERTEX)
77
+ varying vec4 v_lighting;
78
+ #endif
79
+
80
+ #define TANGRAM_UNPACK_SCALING(x) (x / 1024.)
81
+
82
+ #pragma tangram: attributes
83
+ #pragma tangram: camera
84
+ #pragma tangram: material
85
+ #pragma tangram: lighting
86
+ #pragma tangram: raster
87
+ #pragma tangram: global
88
+
89
+ #pragma tangram: projection
90
+
91
+ void main() {
92
+ // Initialize globals
93
+ #pragma tangram: setup
94
+
95
+ // Texture UVs
96
+ #ifdef TANGRAM_TEXTURE_COORDS
97
+ v_texcoord = a_texcoord;
98
+ #ifdef TANGRAM_EXTRUDE_LINES
99
+ v_texcoord.y *= u_v_scale_adjust;
100
+ #endif
101
+ #endif
102
+
103
+ // Pass model position to fragment shader
104
+ #ifdef TANGRAM_MODEL_POSITION_BASE_ZOOM_VARYING
105
+ v_modelpos_base_zoom = modelPositionBaseZoom();
106
+ #endif
107
+
108
+ // Position
109
+ vec4 position = vec4(a_position.xy, TANGRAM_POSITION_Z / TANGRAM_HEIGHT_SCALE, 1.); // convert height back to meters
110
+ #ifdef TANGRAM_TERRAIN_DRAPED
111
+ position.z += tangramTerrainHeight();
112
+ #endif
113
+
114
+ #ifdef TANGRAM_EXTRUDE_LINES
115
+ vec2 _extrude = a_extrude.xy;
116
+ vec2 _offset = a_offset.xy;
117
+
118
+ // Adjust line width based on zoom level, to prevent proxied lines
119
+ // from being either too small or too big.
120
+ // "Flattens" the zoom between 1-2 to peg it to 1 (keeps lines from
121
+ // prematurely shrinking), then interpolate and clamp to 4 (keeps lines
122
+ // from becoming too small when far away).
123
+ float _dz = clamp(u_map_position.z - u_tile_origin.z, 0., 4.);
124
+ _dz += step(1., _dz) * (1. - _dz) + mix(0., 2., clamp((_dz - 2.) / 2., 0., 1.));
125
+
126
+ // Interpolate line width between zooms
127
+ float _mdz = (_dz - 0.5) * 2.; // zoom from mid-point
128
+ _extrude -= _extrude * TANGRAM_UNPACK_SCALING(TANGRAM_WIDTH_SCALING) * _mdz;
129
+
130
+ // Interpolate line offset between zooms
131
+ // Scales from the larger value to the smaller one
132
+ float _dwdz = TANGRAM_UNPACK_SCALING(TANGRAM_OFFSET_SCALING);
133
+ float _sdwdz = sign(step(0., _dwdz) - 0.5); // sign indicates "direction" of scaling
134
+ _offset -= _offset * abs(_dwdz) * ((1.-step(0., _sdwdz)) - (_dz * -_sdwdz)); // scale "up" or "down"
135
+
136
+ // Scale line width and offset to be consistent in screen space
137
+ float _ssz = exp2(-_dz - (u_tile_origin.z - u_tile_origin.w));
138
+ _extrude *= _ssz;
139
+ _offset *= _ssz;
140
+
141
+ // Modify line width before extrusion
142
+ #ifdef TANGRAM_BLOCK_WIDTH
143
+ float width = 1.;
144
+ #pragma tangram: width
145
+ _extrude *= width;
146
+ #endif
147
+
148
+ position.xy += _extrude + _offset;
149
+ #ifdef TANGRAM_TERRAIN_DRAPED
150
+ position.z += tangramTerrainRibbonOffset(_extrude + _offset, a_position.xy);
151
+ #endif
152
+ #endif
153
+
154
+ // World coordinates for 3d procedural textures
155
+ v_tile_position = position.xy;
156
+ #ifdef TANGRAM_TERRAIN_DRAPED
157
+ position = tangramTerrainModelView(position, v_world_position);
158
+ #else
159
+ position = tangramModelView(position, v_world_position);
160
+ #endif
161
+ #ifdef TANGRAM_CPU_PROJECTED
162
+ position = vec4(a_projected_position, 1.);
163
+ #endif
164
+ // Geographic orientation requires absolute meters, before the procedural
165
+ // texture precision wrap changes v_world_position's origin.
166
+ vec3 surface_normal = TANGRAM_NORMAL;
167
+ #ifdef TANGRAM_TERRAIN_DRAPED
168
+ surface_normal = tangramTerrainNormal(surface_normal);
169
+ #endif
170
+ v_normal = u_projection_mode == 1
171
+ ? tangramGlobeNormal(v_world_position.xyz, surface_normal)
172
+ : normalize(u_normalMatrix * surface_normal);
173
+ #if defined(TANGRAM_CPU_PROJECTED) && !defined(TANGRAM_EXTRUDE_LINES)
174
+ v_normal = normalize(a_projected_normal);
175
+ #endif
176
+ v_world_position = wrapWorldPosition(v_world_position);
177
+
178
+ // Modify position before camera projection
179
+ #pragma tangram: position
180
+
181
+ // Setup varyings
182
+ v_position = position;
183
+ v_color = a_color;
184
+
185
+ #if defined(TANGRAM_LIGHTING_VERTEX)
186
+ // Vertex lighting
187
+ vec3 normal = v_normal;
188
+
189
+ // Modify normal before lighting
190
+ #pragma tangram: normal
191
+
192
+ // Pass lighting intensity to fragment shader
193
+ v_lighting = calculateLighting(position.xyz - u_eye, normal, vec4(1.));
194
+ #endif
195
+
196
+ // Camera
197
+ cameraProjection(position);
198
+ #if defined(TANGRAM_CPU_PROJECTED) && defined(TANGRAM_EXTRUDE_LINES)
199
+ if (a_projected_stroke.w > 0.) {
200
+ vec4 center = vec4(a_projected_stroke.xy, 0., 1.);
201
+ cameraProjection(center);
202
+ vec2 direction = (position.xy / position.w - center.xy / center.w) * u_resolution;
203
+ float magnitude = length(direction);
204
+ position.xy = center.xy + (magnitude > 0. ? direction / magnitude : vec2(0.)) *
205
+ a_projected_stroke.z * u_device_pixel_ratio * 2. / u_resolution * center.w;
206
+ }
207
+ #endif
208
+
209
+ // +1 is to keep all layers including proxies > 0
210
+ applyLayerOrder(a_position.w + u_tile_proxy_order_offset + 1., position);
211
+
212
+ gl_Position = position;
213
+ }