Skip to content

Commit cb3622b

Browse files
jtorresfabramourner
authored andcommitted
Add occlusion texture transform for meshopt support in gl-native (internal-1147)
* Support for meshopt in gl-native * Add colors test
1 parent d66267c commit cb3622b

File tree

8 files changed

+563
-2
lines changed

8 files changed

+563
-2
lines changed

3d-style/shaders/model.fragment.glsl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ in vec4 v_pos_light_view_1;
2424
in float v_depth_shadows;
2525
#endif
2626

27+
#ifdef OCCLUSION_TEXTURE_TRANSFORM
28+
// offset[0], offset[1], scale[0], scale[1]
29+
uniform vec4 u_occlusionTextureTransform;
30+
#endif
31+
2732
#pragma mapbox: define-attribute highp vec3 normal_3f
2833
#pragma mapbox: define-attribute highp vec3 color_3f
2934
#pragma mapbox: define-attribute highp vec4 color_4f
@@ -445,7 +450,13 @@ vec4 finalColor;
445450
// Ambient Occlusion
446451
float ao = 1.0;
447452
#if defined (HAS_TEXTURE_u_occlusionTexture) && defined(HAS_ATTRIBUTE_a_uv_2f)
448-
ao = (texture(u_occlusionTexture, uv_2f).x - 1.0) * u_aoIntensity + 1.0;
453+
454+
#ifdef OCCLUSION_TEXTURE_TRANSFORM
455+
vec2 uv = uv_2f.xy * u_occlusionTextureTransform.zw + u_occlusionTextureTransform.xy;
456+
#else
457+
vec2 uv = uv_2f;
458+
#endif
459+
ao = (texture(u_occlusionTexture, uv).x - 1.0) * u_aoIntensity + 1.0;
449460
color *= ao;
450461
#endif
451462
// Emission

test/ignores/all.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,11 @@ const skip = [
187187
"render-tests/model-layer/multiple-models-terrain",
188188

189189
// The algorithm for raster colour gradient texels stretching needs an adjustment
190-
"render-tests/raster-color/categorical"
190+
"render-tests/raster-color/categorical",
191+
192+
// Only implemented in native for now
193+
"render-tests/model-layer/landmark-mbx-meshopt",
194+
"render-tests/model-layer/landmark-mbx-meshopt-colors"
191195
];
192196

193197
export default {todo, skip};
Binary file not shown.
Binary file not shown.
Loading
Lines changed: 273 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,273 @@
1+
{
2+
"version": 8,
3+
"metadata": {
4+
"test": {
5+
"allowed": 0.00025,
6+
"width": 1024,
7+
"height": 1024
8+
}
9+
},
10+
"lights": [
11+
{
12+
"type": "ambient",
13+
"id": "test_ambient",
14+
"properties": {
15+
"color": "rgba(255, 255, 255, 1)",
16+
"intensity": 0.5
17+
}
18+
},
19+
{
20+
"type": "directional",
21+
"id": "test_directional",
22+
"properties": {
23+
"color": "rgba(255, 255, 255, 1)",
24+
"intensity": 0.5
25+
}
26+
}
27+
],
28+
"sources": {
29+
"file-system-tiles": {
30+
"type": "batched-model",
31+
"maxzoom": 14,
32+
"tiles": [
33+
"local://models/landmark/mbx-meshopt/{x}-{y}-{z}.glb"
34+
]
35+
}
36+
},
37+
"pitch": 70,
38+
"zoom": 18.00,
39+
"bearing": 48,
40+
"center": [
41+
-115.1571,
42+
36.1678
43+
],
44+
"layers": [
45+
{
46+
"type": "background",
47+
"paint": {
48+
"background-color": "lightgray"
49+
},
50+
"id": "land"
51+
},
52+
{
53+
"id": "building-models",
54+
"minzoom": 14.0,
55+
"paint": {
56+
"model-ambient-occlusion-intensity": 0.75,
57+
"model-color": [
58+
"match",
59+
[
60+
"get",
61+
"part"
62+
],
63+
"roof",
64+
[
65+
"hsl",
66+
22,
67+
82,
68+
90
69+
],
70+
"wall",
71+
[
72+
"hsl",
73+
0,
74+
0,
75+
100
76+
],
77+
"window",
78+
[
79+
"interpolate",
80+
[ "linear" ],
81+
[ "measure-light", "brightness" ],
82+
0,
83+
[
84+
"hsl",
85+
[
86+
"random",
87+
0.0,
88+
90.0,
89+
[
90+
"id"
91+
]
92+
],
93+
[
94+
"random",
95+
20.0,
96+
100.0,
97+
[
98+
"id"
99+
]
100+
],
101+
87
102+
],
103+
0.15,
104+
[
105+
"hsl",
106+
[
107+
"random",
108+
200.0,
109+
215.0,
110+
[
111+
"id"
112+
]
113+
],
114+
100,
115+
[
116+
"random",
117+
70.0,
118+
80.0,
119+
[
120+
"id"
121+
]
122+
]
123+
]
124+
],
125+
[
126+
"interpolate",
127+
[ "linear" ],
128+
[ "measure-light", "brightness" ],
129+
0.16,
130+
[
131+
"hsla",
132+
[
133+
"random",
134+
10.0,
135+
70.0,
136+
[
137+
"id"
138+
]
139+
],
140+
55
141+
,
142+
[
143+
"random",
144+
80.0,
145+
90.0,
146+
[
147+
"id"
148+
]
149+
],
150+
1.0
151+
],
152+
0.4,
153+
"hsl(0, 100%, 100%)"
154+
]
155+
],
156+
"model-color-mix-intensity": [
157+
"match",
158+
[
159+
"get",
160+
"part"
161+
],
162+
"logo",
163+
[
164+
"interpolate",
165+
[ "linear" ],
166+
[ "measure-light", "brightness" ],
167+
0.2,
168+
0,
169+
0.4,
170+
0.3
171+
],
172+
1.0
173+
],
174+
"model-emissive-strength": [
175+
"match",
176+
[
177+
"get",
178+
"part"
179+
],
180+
"door",
181+
[
182+
"interpolate",
183+
[ "linear" ],
184+
[ "measure-light", "brightness" ],
185+
0.2,
186+
1.5,
187+
0.4,
188+
2.5
189+
],
190+
"logo",
191+
0.6,
192+
"window",
193+
[
194+
"random",
195+
0.5,
196+
0.8,
197+
[
198+
"id"
199+
]
200+
],
201+
0.0
202+
],
203+
"model-height-based-emissive-strength-multiplier": [
204+
"match",
205+
[
206+
"get",
207+
"part"
208+
],
209+
"window",
210+
[
211+
"literal",
212+
[
213+
0.0,
214+
0.9,
215+
0,
216+
1,
217+
0.5
218+
]
219+
],
220+
[
221+
"literal",
222+
[
223+
1.0,
224+
1.0,
225+
1.0,
226+
1.0,
227+
1.0
228+
]
229+
]
230+
],
231+
"model-opacity": [
232+
"interpolate",
233+
[ "linear" ],
234+
[ "zoom" ],
235+
14.2,
236+
0.0,
237+
14.5,
238+
1.0
239+
],
240+
"model-roughness": [
241+
"match",
242+
[
243+
"get",
244+
"part"
245+
],
246+
"window",
247+
0.0,
248+
1.0
249+
],
250+
"model-scale": [
251+
"interpolate",
252+
[ "linear" ],
253+
[ "zoom" ],
254+
14.2,
255+
[
256+
1.0,
257+
1.0,
258+
0.0
259+
],
260+
14.5,
261+
[
262+
1.0,
263+
1.0,
264+
1.0
265+
]
266+
],
267+
"model-type": "common-3d"
268+
},
269+
"source": "file-system-tiles",
270+
"type": "model"
271+
}
272+
]
273+
}
Loading

0 commit comments

Comments
 (0)