Skip to content

Commit

Permalink
Add occlusion texture transform for meshopt support in gl-native (int…
Browse files Browse the repository at this point in the history
…ernal-1147)

* Support for meshopt in gl-native

* Add colors test
  • Loading branch information
jtorresfabra authored and mourner committed Feb 29, 2024
1 parent d66267c commit cb3622b
Show file tree
Hide file tree
Showing 8 changed files with 563 additions and 2 deletions.
13 changes: 12 additions & 1 deletion 3d-style/shaders/model.fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ in vec4 v_pos_light_view_1;
in float v_depth_shadows;
#endif

#ifdef OCCLUSION_TEXTURE_TRANSFORM
// offset[0], offset[1], scale[0], scale[1]
uniform vec4 u_occlusionTextureTransform;
#endif

#pragma mapbox: define-attribute highp vec3 normal_3f
#pragma mapbox: define-attribute highp vec3 color_3f
#pragma mapbox: define-attribute highp vec4 color_4f
Expand Down Expand Up @@ -445,7 +450,13 @@ vec4 finalColor;
// Ambient Occlusion
float ao = 1.0;
#if defined (HAS_TEXTURE_u_occlusionTexture) && defined(HAS_ATTRIBUTE_a_uv_2f)
ao = (texture(u_occlusionTexture, uv_2f).x - 1.0) * u_aoIntensity + 1.0;

#ifdef OCCLUSION_TEXTURE_TRANSFORM
vec2 uv = uv_2f.xy * u_occlusionTextureTransform.zw + u_occlusionTextureTransform.xy;
#else
vec2 uv = uv_2f;
#endif
ao = (texture(u_occlusionTexture, uv).x - 1.0) * u_aoIntensity + 1.0;
color *= ao;
#endif
// Emission
Expand Down
6 changes: 5 additions & 1 deletion test/ignores/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,11 @@ const skip = [
"render-tests/model-layer/multiple-models-terrain",

// The algorithm for raster colour gradient texels stretching needs an adjustment
"render-tests/raster-color/categorical"
"render-tests/raster-color/categorical",

// Only implemented in native for now
"render-tests/model-layer/landmark-mbx-meshopt",
"render-tests/model-layer/landmark-mbx-meshopt-colors"
];

export default {todo, skip};
Binary file not shown.
Binary file not shown.
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,273 @@
{
"version": 8,
"metadata": {
"test": {
"allowed": 0.00025,
"width": 1024,
"height": 1024
}
},
"lights": [
{
"type": "ambient",
"id": "test_ambient",
"properties": {
"color": "rgba(255, 255, 255, 1)",
"intensity": 0.5
}
},
{
"type": "directional",
"id": "test_directional",
"properties": {
"color": "rgba(255, 255, 255, 1)",
"intensity": 0.5
}
}
],
"sources": {
"file-system-tiles": {
"type": "batched-model",
"maxzoom": 14,
"tiles": [
"local://models/landmark/mbx-meshopt/{x}-{y}-{z}.glb"
]
}
},
"pitch": 70,
"zoom": 18.00,
"bearing": 48,
"center": [
-115.1571,
36.1678
],
"layers": [
{
"type": "background",
"paint": {
"background-color": "lightgray"
},
"id": "land"
},
{
"id": "building-models",
"minzoom": 14.0,
"paint": {
"model-ambient-occlusion-intensity": 0.75,
"model-color": [
"match",
[
"get",
"part"
],
"roof",
[
"hsl",
22,
82,
90
],
"wall",
[
"hsl",
0,
0,
100
],
"window",
[
"interpolate",
[ "linear" ],
[ "measure-light", "brightness" ],
0,
[
"hsl",
[
"random",
0.0,
90.0,
[
"id"
]
],
[
"random",
20.0,
100.0,
[
"id"
]
],
87
],
0.15,
[
"hsl",
[
"random",
200.0,
215.0,
[
"id"
]
],
100,
[
"random",
70.0,
80.0,
[
"id"
]
]
]
],
[
"interpolate",
[ "linear" ],
[ "measure-light", "brightness" ],
0.16,
[
"hsla",
[
"random",
10.0,
70.0,
[
"id"
]
],
55
,
[
"random",
80.0,
90.0,
[
"id"
]
],
1.0
],
0.4,
"hsl(0, 100%, 100%)"
]
],
"model-color-mix-intensity": [
"match",
[
"get",
"part"
],
"logo",
[
"interpolate",
[ "linear" ],
[ "measure-light", "brightness" ],
0.2,
0,
0.4,
0.3
],
1.0
],
"model-emissive-strength": [
"match",
[
"get",
"part"
],
"door",
[
"interpolate",
[ "linear" ],
[ "measure-light", "brightness" ],
0.2,
1.5,
0.4,
2.5
],
"logo",
0.6,
"window",
[
"random",
0.5,
0.8,
[
"id"
]
],
0.0
],
"model-height-based-emissive-strength-multiplier": [
"match",
[
"get",
"part"
],
"window",
[
"literal",
[
0.0,
0.9,
0,
1,
0.5
]
],
[
"literal",
[
1.0,
1.0,
1.0,
1.0,
1.0
]
]
],
"model-opacity": [
"interpolate",
[ "linear" ],
[ "zoom" ],
14.2,
0.0,
14.5,
1.0
],
"model-roughness": [
"match",
[
"get",
"part"
],
"window",
0.0,
1.0
],
"model-scale": [
"interpolate",
[ "linear" ],
[ "zoom" ],
14.2,
[
1.0,
1.0,
0.0
],
14.5,
[
1.0,
1.0,
1.0
]
],
"model-type": "common-3d"
},
"source": "file-system-tiles",
"type": "model"
}
]
}
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 cb3622b

Please sign in to comment.