Skip to content

Commit

Permalink
Support line layer on Globe with Terrain3D (#4970)
Browse files Browse the repository at this point in the history
  • Loading branch information
birkskyum authored Nov 3, 2024
1 parent 84efc30 commit e4760d0
Show file tree
Hide file tree
Showing 12 changed files with 367 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- _...Add new stuff here..._

### 🐞 Bug fixes
- Fix `line` layer on Globe with Terrain Elevation
- _...Add new stuff here..._

## 5.0.0-pre.5
Expand Down
14 changes: 11 additions & 3 deletions src/render/draw_line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export function drawLine(painter: Painter, sourceCache: SourceCache, layer: Line

const depthMode = painter.getDepthModeForSublayer(0, DepthMode.ReadOnly);
const colorMode = painter.colorModeForRenderPass();

const globeWithTerrain = !!painter.style.map.terrain && painter.style.projection.name === 'globe';

const dasharray = layer.paint.get('line-dasharray');
const patternProperty = layer.paint.get('line-pattern');
const image = patternProperty.constantOr(1 as any);
Expand Down Expand Up @@ -67,7 +68,11 @@ export function drawLine(painter: Painter, sourceCache: SourceCache, layer: Line
if (posTo && posFrom) programConfiguration.setConstantPatternPositions(posTo, posFrom);
}

const projectionData = transform.getProjectionData({overscaledTileID: coord});
const projectionData = transform.getProjectionData({
overscaledTileID: coord,
ignoreGlobeMatrix: globeWithTerrain
});

const pixelRatio = transform.getPixelScale();

const uniformValues = image ? linePatternUniformValues(painter, tile, layer, pixelRatio, crossfade) :
Expand Down Expand Up @@ -117,8 +122,11 @@ export function drawLine(painter: Painter, sourceCache: SourceCache, layer: Line
gradientTexture.bind(layer.stepInterpolant ? gl.NEAREST : gl.LINEAR, gl.CLAMP_TO_EDGE);
}

const [stencilModes] = painter.stencilConfigForOverlap(coords);
const stencil = globeWithTerrain ? stencilModes[coord.overscaledZ] : painter.stencilModeForClipping(coord);

program.draw(context, gl.TRIANGLES, depthMode,
painter.stencilModeForClipping(coord), colorMode, CullFaceMode.disabled, uniformValues, terrainData, projectionData,
stencil, colorMode, CullFaceMode.disabled, uniformValues, terrainData, projectionData,
layer.id, bucket.layoutVertexBuffer, bucket.indexBuffer, bucket.segments,
layer.paint, painter.transform.zoom, programConfiguration, bucket.layoutVertexBuffer2);

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
{
"version": 8,
"metadata": {
"test": {
}
},
"sky": {
"atmosphere-blend": 0.0
},
"center": [
0.0,
0.0
],
"zoom": 1,
"projection": { "type": "globe" },
"terrain": {
"source": "terrain",
"exaggeration": 2
},
"sources": {
"terrain": {
"type": "raster-dem",
"tiles": ["local://tiles/{z}-{x}-{y}.terrain.png"],
"maxzoom": 15,
"tileSize": 256
},
"fill": {
"type": "geojson",
"data": {
"type": "Polygon",
"coordinates": [
[
[
-180,
-90
],
[
-180,
90
],
[
180,
90
],
[
180,
-90
],
[
-180,
-90
]
]
]
}
},
"line": {
"type": "geojson",
"lineMetrics": true,
"data": {
"type": "LineString",
"coordinates": [
[
-90,
-85
],
[
90,
85
]
]
}
}
},
"layers": [
{
"id": "background",
"type": "background",
"paint": {
"background-color": "white"
}
},
{
"id": "fill",
"type": "fill",
"source": "fill",
"paint": {
"fill-antialias": false,
"fill-color": "grey"
}
},
{
"id": "line",
"type": "line",
"source": "line",
"paint": {
"line-width": 10,
"line-gradient": [
"interpolate-lab",
[
"linear"
],
[
"line-progress"
],
0,
"blue",
0.1,
"royalblue",
0.3,
"cyan",
0.5,
"lime",
0.7,
"yellow",
1,
"red"
]
}
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
"version": 8,
"metadata": {
"test": {
}
},
"sky": {
"atmosphere-blend": 0.0
},
"center": [
0.0,
0.0
],
"zoom": 1,
"projection": { "type": "globe" },
"terrain": {
"source": "terrain",
"exaggeration": 2
},
"sources": {
"terrain": {
"type": "raster-dem",
"tiles": ["local://tiles/{z}-{x}-{y}.terrain.png"],
"maxzoom": 15,
"tileSize": 256
},
"fill": {
"type": "geojson",
"data": {
"type": "Polygon",
"coordinates": [
[
[
-180,
-90
],
[
-180,
90
],
[
180,
90
],
[
180,
-90
],
[
-180,
-90
]
]
]
}
},
"line": {
"type": "geojson",
"data": {
"type": "LineString",
"coordinates": [
[
-1440,
-85
],
[
1440,
85
]
]
}
}
},
"layers": [
{
"id": "background",
"type": "background",
"paint": {
"background-color": "white"
}
},
{
"id": "fill",
"type": "fill",
"source": "fill",
"paint": {
"fill-antialias": false,
"fill-color": "grey"
}
},
{
"id": "line",
"type": "line",
"source": "line",
"paint": {
"line-width": 10,
"line-color": "red"
}
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit e4760d0

Please sign in to comment.