Skip to content

Commit 69664b8

Browse files
authored
Disabled unsupported Fog rendering, for Terrain3D on Globe
1 parent 51a2efd commit 69664b8

7 files changed

Lines changed: 116 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
### 🐞 Bug fixes
1212
- Fix line-placed map-pitch-aligned texts being too large when viewed from some latitudes on a globe ([#4786](https://github.com/maplibre/maplibre-gl-js/issues/4786))
13+
- Disabled unsupported Fog rendering, for Terrain3D on Globe ([#4963](https://github.com/maplibre/maplibre-gl-js/pull/4963))
1314
- _...Add new stuff here..._
1415

1516
## 5.0.0-pre.4

src/render/draw_terrain.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function drawTerrain(painter: Painter, terrain: Terrain, tiles: Array<Tile>) {
8888
gl.bindTexture(gl.TEXTURE_2D, texture.texture);
8989
const eleDelta = terrain.getMeshFrameDelta(tr.zoom);
9090
const fogMatrix = tr.calculateFogMatrix(tile.tileID.toUnwrapped());
91-
const uniformValues = terrainUniformValues(eleDelta, fogMatrix, painter.style.sky, tr.pitch);
91+
const uniformValues = terrainUniformValues(eleDelta, fogMatrix, painter.style.sky, tr.pitch, painter.style.projection?.name === 'globe');
9292
const projectionData = tr.getProjectionData({overscaledTileID: tile.tileID, ignoreTerrainMatrix: true});
9393
program.draw(context, gl.TRIANGLES, depthMode, StencilMode.disabled, colorMode, CullFaceMode.backCCW, uniformValues, terrainData, projectionData, 'terrain', mesh.vertexBuffer, mesh.indexBuffer, mesh.segments);
9494
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import {terrainUniformValues} from './terrain_program';
2+
import {Sky} from '../../style/sky';
3+
import {mat4} from 'gl-matrix';
4+
5+
describe('terrainUniformValues', () => {
6+
test('disables fog when in globe projection mode', () => {
7+
const eleDelta = 1.0;
8+
const fogMatrix = mat4.create();
9+
const sky = new Sky({});
10+
const pitch = 45;
11+
const isGlobeMode = true;
12+
const uniformValues = terrainUniformValues(eleDelta, fogMatrix, sky, pitch, isGlobeMode);
13+
14+
expect(uniformValues['u_fog_ground_blend_opacity']).toBe(0);
15+
expect(uniformValues['u_ele_delta']).toBe(eleDelta);
16+
expect(uniformValues['u_fog_matrix']).toBe(fogMatrix);
17+
expect(uniformValues['u_fog_color']).toEqual(sky.properties.get('fog-color'));
18+
expect(uniformValues['u_fog_ground_blend']).toBe(sky.properties.get('fog-ground-blend'));
19+
});
20+
21+
test('enables fog when not in globe projection mode', () => {
22+
const eleDelta = 1.0;
23+
const fogMatrix = mat4.create();
24+
const sky = new Sky({});
25+
const pitch = 45;
26+
const isGlobeMode = false;
27+
const uniformValues = terrainUniformValues(eleDelta, fogMatrix, sky, pitch, isGlobeMode);
28+
expect(uniformValues['u_fog_ground_blend_opacity']).toBe(sky.calculateFogBlendOpacity(pitch));
29+
});
30+
});

src/render/program/terrain_program.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,15 @@ const terrainUniformValues = (
7575
eleDelta: number,
7676
fogMatrix: mat4,
7777
sky: Sky,
78-
pitch: number): UniformValues<TerrainUniformsType> => ({
78+
pitch: number,
79+
isGlobeMode: boolean): UniformValues<TerrainUniformsType> => ({
7980
'u_texture': 0,
8081
'u_ele_delta': eleDelta,
8182
'u_fog_matrix': fogMatrix,
8283
'u_fog_color': sky ? sky.properties.get('fog-color') : Color.white,
8384
'u_fog_ground_blend': sky ? sky.properties.get('fog-ground-blend') : 1,
84-
'u_fog_ground_blend_opacity': sky ? sky.calculateFogBlendOpacity(pitch) : 0,
85+
// Set opacity to 0 when in globe mode to disable fog
86+
'u_fog_ground_blend_opacity': isGlobeMode ? 0 : (sky ? sky.calculateFogBlendOpacity(pitch) : 0),
8587
'u_horizon_color': sky ? sky.properties.get('horizon-color') : Color.white,
8688
'u_horizon_fog_blend': sky ? sky.properties.get('horizon-fog-blend') : 1
8789
});

test/examples/sky-with-fog-and-terrain.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@
108108
})
109109
);
110110

111+
112+
map.addControl(
113+
new maplibregl.GlobeControl()
114+
);
115+
116+
111117
map.addControl(
112118
new maplibregl.TerrainControl({
113119
source: 'terrainSource',
50 KB
Loading
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
"version": 8,
3+
"metadata": {
4+
"test": {
5+
"height": 256,
6+
"width": 256,
7+
"maxPitch": 120,
8+
"operations": [
9+
["idle"]
10+
]
11+
}
12+
},
13+
"timeout": 60000,
14+
"center": [
15+
-113.335,
16+
35.96
17+
],
18+
"zoom": 13,
19+
"pitch": 80,
20+
"maxPitch": 180,
21+
"sources": {
22+
"terrain": {
23+
"type": "raster-dem",
24+
"tiles": [
25+
"local://tiles/{z}-{x}-{y}.terrain.png"
26+
],
27+
"maxzoom": 15,
28+
"tileSize": 256
29+
},
30+
"satellite": {
31+
"type": "raster",
32+
"tiles": [
33+
"local://tiles/{z}-{x}-{y}.satellite.png"
34+
],
35+
"maxzoom": 17,
36+
"tileSize": 256
37+
}
38+
},
39+
"layers": [
40+
{
41+
"id": "background",
42+
"type": "background",
43+
"paint": {
44+
"background-color": "blue"
45+
}
46+
},
47+
{
48+
"id": "raster",
49+
"type": "raster",
50+
"source": "satellite",
51+
"paint": {
52+
"raster-opacity": 1.0
53+
}
54+
55+
}
56+
],
57+
"terrain": {
58+
"source": "terrain",
59+
"exaggeration": 2
60+
},
61+
"sky": {
62+
"sky-color": "green",
63+
"sky-horizon-blend": 0.5,
64+
"horizon-color": "red",
65+
"horizon-fog-blend": 0.5,
66+
"fog-color": "blue",
67+
"fog-ground-blend": 0.5,
68+
"atmosphere-blend": 0
69+
},
70+
"projection": {
71+
"type": "globe"
72+
}
73+
}
74+

0 commit comments

Comments
 (0)