Skip to content

Commit b48713d

Browse files
stephanheiglgithub-actions[bot]
authored andcommitted
Raster vertex shader: do not declare uv/texcoord vertex attribute in
permutations with position-only layouts. GitOrigin-RevId: 279f0d11ff84525239fb1e1f08db1b58e6bf43eb
1 parent 02108a9 commit b48713d

6 files changed

Lines changed: 107 additions & 8 deletions

File tree

src/render/program/raster_program.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import type RasterStyleLayer from '../../style/style_layer/raster_style_layer';
1919
const lerp = (a: number, b: number, t: number) => { return (1 - t) * a + t * b; };
2020

2121
function computeZBiasFactor(painter: Painter) {
22-
const terrainExaggeration = Math.min(painter.terrain ? painter.terrain.exaggeration() : 0.0, 2.0);
22+
const terrainExaggeration = painter.terrain ? painter.terrain.exaggeration() : 1.0;
2323
const bias = painter.transform.pitch < 15.0 ? lerp(0.07, 0.7, clamp((14.0 - painter.transform.zoom) / (14.0 - 9.0), 0.0, 1.0)) : 0.07;
2424
return bias * terrainExaggeration;
2525
}

src/shaders/raster.vertex.glsl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ void main() {
5151
v_fog_pos = fog_position((u_normalize_matrix * vec4(a_globe_pos, 1.0)).xyz);
5252
#endif // FOG
5353
#else // else GLOBE_POLES
54-
float w = 1.0 + dot(a_texture_pos, u_perspective_transform);
54+
vec4 world_pos;
55+
#ifdef PROJECTION_GLOBE_VIEW
5556
// We are using Int16 for texture position coordinates to give us enough precision for
5657
// fractional coordinates. We use 8192 to scale the texture coordinates in the buffer
5758
// as an arbitrarily high number to preserve adequate precision when rendering.
5859
// This is also the same value as the EXTENT we are using for our tile buffer pos coordinates,
5960
// so math for modifying either is consistent.
6061
uv = a_texture_pos / 8192.0;
61-
#ifdef PROJECTION_GLOBE_VIEW
6262

6363
vec3 decomposed_pos_and_skirt = decomposeToPosAndSkirt(a_pos);
6464
vec3 latLng = u_grid_matrix * vec3(decomposed_pos_and_skirt.xy, 1.0);
@@ -100,9 +100,7 @@ void main() {
100100
globe_pos += normalize(globe_pos) * ele * GLOBE_UPSCALE;
101101
vec4 globe_world_pos = u_globe_matrix * vec4(globe_pos, 1.0);
102102

103-
vec4 interpolated_pos = vec4(mix(globe_world_pos.xyz, merc_world_pos.xyz, u_zoom_transition) * w, w);
104-
105-
gl_Position = u_matrix * interpolated_pos;
103+
world_pos = vec4(mix(globe_world_pos.xyz, merc_world_pos.xyz, u_zoom_transition), 1.0);
106104
#ifdef FOG
107105
v_fog_pos = fog_position((u_normalize_matrix * vec4(globe_pos, 1.0)).xyz);
108106
#endif // FOG
@@ -115,12 +113,16 @@ void main() {
115113
decodedPos = decomposedPosAndSkirt.xy;
116114
uv = decodedPos / 8192.0;
117115
ele = elevation(decodedPos) - skirt;
116+
#else // else ELEVATION_REFERENCE_GROUND
117+
uv = a_texture_pos / 8192.0;
118118
#endif // ELEVATION_REFERENCE_GROUND
119-
gl_Position = u_matrix * vec4(decodedPos * w, (u_raster_elevation + ele) * w, w);
119+
world_pos = vec4(decodedPos, (u_raster_elevation + ele), 1.0);
120120
#ifdef FOG
121121
v_fog_pos = fog_position(decodedPos);
122122
#endif // FOG
123123
#endif // else PROJECTION_GLOBE_VIEW
124+
float w = 1.0 + dot(uv*EXTENT, u_perspective_transform);
125+
gl_Position = u_matrix * world_pos * w;
124126
#endif // else GLOBE_POLES
125127

126128
v_pos0 = uv;
387 KB
Loading
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
{
2+
"version": 8,
3+
"metadata": {
4+
"test": {
5+
"height": 300,
6+
"width": 512,
7+
"allowed": 0.0013,
8+
"operations": [
9+
[
10+
"wait"
11+
]
12+
]
13+
}
14+
},
15+
"projection": {
16+
"name": "globe"
17+
},
18+
"center": [
19+
-107.616,
20+
41.166
21+
],
22+
"zoom": 5.18,
23+
"pitch": 32.0,
24+
"bearing": -100.5,
25+
"terrain": {
26+
"source": "rgbterrain",
27+
"exaggeration": 100.0
28+
},
29+
"sprite": "local://sprites/standard",
30+
"lights": [
31+
{
32+
"type": "ambient",
33+
"id": "test_ambient",
34+
"properties": {
35+
"color": "rgba(255, 255, 255, 1)",
36+
"intensity": 0.2
37+
}
38+
},
39+
{
40+
"type": "directional",
41+
"id": "test_directional",
42+
"properties": {
43+
"cast-shadows": true,
44+
"color": "rgba(255, 255, 255, 1)",
45+
"intensity": 0.8
46+
}
47+
}
48+
],
49+
"sources": {
50+
"rgbterrain": {
51+
"type": "raster-dem",
52+
"tiles": [
53+
"local://tiles/{z}-{x}-{y}.terrain.512.png"
54+
],
55+
"maxzoom": 12,
56+
"tileSize": 512
57+
},
58+
"satellite": {
59+
"type": "raster",
60+
"tiles": [
61+
"local://tiles/{z}-{x}-{y}.satellite.png"
62+
],
63+
"maxzoom": 17,
64+
"tileSize": 256
65+
},
66+
"image": {
67+
"type": "raster",
68+
"tiles": [
69+
"local://tiles/alpha.png"
70+
],
71+
"maxzoom": 17,
72+
"tileSize": 256
73+
}
74+
},
75+
"layers": [
76+
{
77+
"id": "raster",
78+
"type": "raster",
79+
"source": "satellite",
80+
"paint": {
81+
"raster-fade-duration": 0
82+
}
83+
},
84+
{
85+
"id": "image",
86+
"type": "raster",
87+
"source": "image",
88+
"paint": {
89+
"raster-fade-duration": 0,
90+
"raster-opacity": 0.7,
91+
"raster-elevation": 10.0,
92+
"raster-elevation-reference": "ground",
93+
"raster-emissive-strength": 1
94+
}
95+
}
96+
]
97+
}
64.5 KB
Loading

test/integration/render-tests/raster-elevation-tiled/terrain-ground-reference/style.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"image": {
5858
"type": "raster",
5959
"tiles": [
60-
"local://tiles/const/13-4095-4095.color.png"
60+
"local://tiles/alpha.png"
6161
],
6262
"maxzoom": 17,
6363
"tileSize": 256

0 commit comments

Comments
 (0)