Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3.1.0 (bug fixes, performance improvements and new style properties) #13047

Merged
merged 25 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4c10d8d
Clean up shaders (GLSL 3.0, more specific preludes, removing legacy d…
mourner Jan 8, 2024
6d05e5f
Bump postcss from 8.4.32 to 8.4.33 (internal-1032)
dependabot[bot] Jan 9, 2024
f152136
Bump puppeteer-core from 21.6.1 to 21.7.0 (internal-1031)
dependabot[bot] Jan 9, 2024
90dc892
Bump cssnano from 6.0.2 to 6.0.3 (internal-1029)
dependabot[bot] Jan 9, 2024
d967627
Bump eslint-plugin-jsdoc from 47.0.2 to 48.0.2 (internal-1030)
dependabot[bot] Jan 9, 2024
8a757bf
[GLJS-512] Fixed upper layers rendering if nested imports have error …
underoot Jan 9, 2024
91f422d
[MAPS3D-1099] Disable terrain and hillshade if there is noise in the …
astojilj Jan 9, 2024
a0dde83
Switch to Node v18 in CodeBuild (internal-1036)
stepankuzmin Jan 9, 2024
a1ad74c
Add highp for fog limit values in raster fragment shader (internal-1040)
endanke Jan 10, 2024
9c58a08
Adding android/ios sdk version for raster-elevation
woodroof Jan 10, 2024
a2e9d74
Remove image padding from shaping offset (internal-1041)
endanke Jan 11, 2024
689029d
Removed macos sdk version: it's not being displayed in the docs and s…
woodroof Jan 10, 2024
1c5b96f
Add emission strength support for 3D model layers using 2D sources as…
jtorresfabra Jan 11, 2024
1130a07
Symbol icon saturation (internal-1033)
akoylasar Jan 11, 2024
b278045
[GLJS-567] Added posibility to partially update terrain (internal-1044)
underoot Jan 11, 2024
94099bb
Fail on unsuccesful performance test triggers (internal-1039)
endanke Jan 12, 2024
59a7dbb
Allow deferred terrain when fingerprinting protection is enabled (int…
stepankuzmin Jan 15, 2024
e279511
Bump tape from 5.7.2 to 5.7.3 (internal-1049)
dependabot[bot] Jan 16, 2024
7727f7d
[GLJS-592] Allow `null` in TerrainSpecification to override terrain i…
stepankuzmin Jan 16, 2024
9e2b66d
Check for empty layer and source IDs in runtime (internal-1051)
stepankuzmin Jan 16, 2024
ce9883d
Require either "url" or "tiles" for tiled sources (internal-1052)
stepankuzmin Jan 16, 2024
5eed522
[GLJS-640] Trigger map rerender if all source tiles are 404 (internal…
stepankuzmin Jan 16, 2024
5e1ab95
[GLJS-413] Evolving basemap fixes for config options evaluation (inte…
mourner Jan 18, 2024
412793e
Fix types and unit test (internal-1055)
stepankuzmin Jan 18, 2024
d882740
v3.1.0 (internal-1054)
stepankuzmin Jan 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -550,4 +550,11 @@ jobs:
name: Trigger SLA performance tests
command: |
sha=$(git rev-parse HEAD)
curl --location --request POST 'https://circleci.com/api/v2/project/github/mapbox/mapbox-gl-js-performance-internal/pipeline' --header 'Content-Type: application/json' -u $CIRCLECI_API_TOKEN: -d "{ \"parameters\": { \"setup_sha\": \"$sha\", \"setup_source_branch\": \"internal\" } }"
response_code=$(curl --location --write-out "%{http_code}" --output /dev/stderr --request POST 'https://circleci.com/api/v2/project/github/mapbox/mapbox-gl-js-performance-internal/pipeline' --header 'Content-Type: application/json' -u $CIRCLECI_API_TOKEN: -d "{ \"parameters\": { \"setup_sha\": \"$sha\", \"setup_source_branch\": \"internal\" } }")

if [[ "$response_code" =~ ^2 ]]; then
echo "Success: HTTP 2xx response"
else
echo "Error: Non-2xx response code - $response_code"
exit 1
fi
12 changes: 11 additions & 1 deletion 3d-style/render/draw_model.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ function drawMesh(sortedMesh: SortedMesh, painter: Painter, layer: ModelStyleLay
const normalMatrix = mat4.invert([], lightingMatrix);
mat4.transpose(normalMatrix, normalMatrix);

const emissiveStrength = layer.paint.get('model-emissive-strength').constantOr(0.0);

const uniformValues = modelUniformValues(
new Float32Array(sortedMesh.worldViewProjection),
new Float32Array(lightingMatrix),
Expand All @@ -158,6 +160,7 @@ function drawMesh(sortedMesh: SortedMesh, painter: Painter, layer: ModelStyleLay
pbr.metallicFactor,
pbr.roughnessFactor,
material,
emissiveStrength,
layer);

const programOptions: CreateProgramParams = {
Expand Down Expand Up @@ -604,6 +607,8 @@ function drawInstancedNode(painter: Painter, layer: ModelStyleLayer, node: Node,
const pbr = material.pbrMetallicRoughness;
const layerOpacity = layer.paint.get('model-opacity');

const emissiveStrength = layer.paint.get('model-emissive-strength').constantOr(0.0);

uniformValues = modelUniformValues(
coord.expandedProjMatrix,
Float32Array.from(node.matrix),
Expand All @@ -615,8 +620,10 @@ function drawInstancedNode(painter: Painter, layer: ModelStyleLayer, node: Node,
pbr.metallicFactor,
pbr.roughnessFactor,
material,
emissiveStrength,
layer,
cameraPos);
cameraPos
);
if (shadowRenderer) {
if (!renderData.shadowUniformsInitialized) {
shadowRenderer.setupShadows(coord.toUnwrapped(), program, 'model-tile', coord.overscaledZ);
Expand Down Expand Up @@ -814,6 +821,8 @@ function drawBatchedModels(painter: Painter, source: SourceCache, layer: ModelSt
pbr.metallicFactor = 0.9;
pbr.roughnessFactor = 0.5;

// Set emissive strength to zero for landmarks, as it is already used embedded in the PBR buffer.
const emissiveStrength = 0.0;
const uniformValues = modelUniformValues(
new Float32Array(worldViewProjection),
new Float32Array(lightingMatrix),
Expand All @@ -825,6 +834,7 @@ function drawBatchedModels(painter: Painter, source: SourceCache, layer: ModelSt
pbr.metallicFactor,
pbr.roughnessFactor,
material,
emissiveStrength,
layer
);

Expand Down
15 changes: 10 additions & 5 deletions 3d-style/render/program/model_program.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export type ModelUniformsType = {
'u_occlusionTexture': Uniform1i,
'u_emissionTexture': Uniform1i,
'u_color_mix': Uniform4f,
'u_aoIntensity': Uniform1f
'u_aoIntensity': Uniform1f,
'u_emissive_strength': Uniform1f
};

const modelUniforms = (context: Context): ModelUniformsType => ({
Expand All @@ -64,7 +65,8 @@ const modelUniforms = (context: Context): ModelUniformsType => ({
'u_occlusionTexture': new Uniform1i(context),
'u_emissionTexture': new Uniform1i(context),
'u_color_mix': new Uniform4f(context),
'u_aoIntensity': new Uniform1f(context)
'u_aoIntensity': new Uniform1f(context),
'u_emissive_strength' : new Uniform1f(context)

});

Expand All @@ -79,8 +81,10 @@ const modelUniformValues = (
metallicFactor: number,
roughnessFactor: number,
material: Material,
emissiveStrength: number,
layer: ModelStyleLayer,
cameraPos: [number, number, number] = [0, 0, 0]): UniformValues<ModelUniformsType> => {
cameraPos: [number, number, number] = [0, 0, 0]
): UniformValues<ModelUniformsType> => {

const light = painter.style.light;
const _lp = light.properties.get('position');
Expand All @@ -96,7 +100,7 @@ const modelUniformValues = (

const lightColor = light.properties.get('color');

const aoIntensity = layer.paint.get('model-ambient-occlusion-intensity');
const aoIntensity = layer.paint.get('model-ambient-occlusion-intensity');
const colorMix = layer.paint.get('model-color').constantOr(Color.white);
const colorMixIntensity = layer.paint.get('model-color-mix-intensity').constantOr(0.0);

Expand All @@ -122,7 +126,8 @@ const modelUniformValues = (
'u_occlusionTexture': TextureSlots.Occlusion,
'u_emissionTexture': TextureSlots.Emission,
'u_color_mix': [colorMix.r, colorMix.g, colorMix.b, colorMixIntensity],
'u_aoIntensity': aoIntensity
'u_aoIntensity': aoIntensity,
'u_emissive_strength': emissiveStrength
};

return uniformValues;
Expand Down
14 changes: 5 additions & 9 deletions 3d-style/shaders/_prelude_shadow.fragment.glsl
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#ifdef RENDER_SHADOWS

#if defined(NATIVE) && __VERSION__ >= 300
#define TEXTURE_GATHER
#endif

#ifdef DEPTH_TEXTURE
uniform highp sampler2D u_shadowmap_0;
uniform highp sampler2D u_shadowmap_1;
Expand All @@ -23,19 +19,19 @@ uniform highp vec3 u_shadow_bias;
highp float shadow_sample_1(highp vec2 uv, highp float compare) {
highp float shadow_depth;
#ifdef DEPTH_TEXTURE
shadow_depth = texture2D(u_shadowmap_1, uv).r;
shadow_depth = texture(u_shadowmap_1, uv).r;
#else
shadow_depth = unpack_depth(texture2D(u_shadowmap_1, uv)) * 0.5 + 0.5;
shadow_depth = unpack_depth(texture(u_shadowmap_1, uv)) * 0.5 + 0.5;
#endif
return step(shadow_depth, compare);
}

highp float shadow_sample_0(highp vec2 uv, highp float compare) {
highp float shadow_depth;
#ifdef DEPTH_TEXTURE
shadow_depth = texture2D(u_shadowmap_0, uv).r;
shadow_depth = texture(u_shadowmap_0, uv).r;
#else
shadow_depth = unpack_depth(texture2D(u_shadowmap_0, uv)) * 0.5 + 0.5;
shadow_depth = unpack_depth(texture(u_shadowmap_0, uv)) * 0.5 + 0.5;
#endif
return step(shadow_depth, compare);
}
Expand All @@ -50,7 +46,7 @@ float shadow_occlusion_0(highp vec4 pos, highp float bias) {

// Perform percentage-closer filtering with a 2x2 sample grid.
// Edge tap smoothing is used to weight each sample based on their contribution in the overall PCF kernel
#ifdef TEXTURE_GATHER
#ifdef NATIVE
highp vec2 uv = pos.xy;
highp vec4 samples = textureGather(u_shadowmap_0, uv, 0);
lowp vec4 stepSamples = step(samples, vec4(compare0));
Expand Down
4 changes: 2 additions & 2 deletions 3d-style/shaders/fill_extrusion_depth.fragment.glsl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
varying highp float v_depth;
in highp float v_depth;

void main() {
#ifndef DEPTH_TEXTURE
gl_FragColor = pack_depth(v_depth);
glFragColor = pack_depth(v_depth);
#endif
}
6 changes: 3 additions & 3 deletions 3d-style/shaders/fill_extrusion_depth.vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ uniform mat4 u_matrix;
uniform float u_edge_radius;
uniform float u_vertical_scale;

attribute vec4 a_pos_normal_ed;
attribute vec2 a_centroid_pos;
in vec4 a_pos_normal_ed;
in vec2 a_centroid_pos;

#pragma mapbox: define highp float base
#pragma mapbox: define highp float height

varying highp float v_depth;
out highp float v_depth;

void main() {
#pragma mapbox: initialize highp float base
Expand Down
12 changes: 5 additions & 7 deletions 3d-style/shaders/ground_shadow.fragment.glsl
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
#include "_prelude_shadow.fragment.glsl"

#ifdef GL_ES
precision highp float;
#endif

uniform vec3 u_ground_shadow_factor;

varying vec4 v_pos_light_view_0;
varying vec4 v_pos_light_view_1;
varying float v_depth;
in vec4 v_pos_light_view_0;
in vec4 v_pos_light_view_1;
in float v_depth;

#ifdef FOG
varying float v_fog_opacity;
in float v_fog_opacity;
#endif

void main() {
Expand All @@ -29,5 +27,5 @@ void main() {
shadow = mix(shadow, vec3(1.0), 1.0 - applyCutout(vec4(1.0)).r);
#endif

gl_FragColor = vec4(shadow, 1.0);
glFragColor = vec4(shadow, 1.0);
}
10 changes: 5 additions & 5 deletions 3d-style/shaders/ground_shadow.vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ uniform mat4 u_matrix;
uniform mat4 u_light_matrix_0;
uniform mat4 u_light_matrix_1;

attribute vec2 a_pos;
in vec2 a_pos;

varying vec4 v_pos_light_view_0;
varying vec4 v_pos_light_view_1;
varying float v_depth;
out vec4 v_pos_light_view_0;
out vec4 v_pos_light_view_1;
out float v_depth;

#ifdef FOG
varying float v_fog_opacity;
out float v_fog_opacity;
#endif

void main() {
Expand Down
49 changes: 27 additions & 22 deletions 3d-style/shaders/model.fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ uniform float u_roughnessFactor;
uniform float u_emissive_strength;


varying highp vec4 v_position_height;
varying lowp vec4 v_color_mix;
in highp vec4 v_position_height;
in lowp vec4 v_color_mix;

#ifdef RENDER_SHADOWS
varying vec4 v_pos_light_view_0;
varying vec4 v_pos_light_view_1;
varying float v_depth_shadows;
in vec4 v_pos_light_view_0;
in vec4 v_pos_light_view_1;
in float v_depth_shadows;
#endif

#pragma mapbox: define-attribute highp vec3 normal_3f
Expand All @@ -35,8 +35,8 @@ varying float v_depth_shadows;
#pragma mapbox: initialize-attribute highp vec2 uv_2f

#ifdef HAS_ATTRIBUTE_a_pbr
varying lowp vec4 v_roughness_metallic_emissive_alpha;
varying mediump vec4 v_height_based_emission_params;
in lowp vec4 v_roughness_metallic_emissive_alpha;
in mediump vec4 v_height_based_emission_params;
#endif

#ifdef HAS_TEXTURE_u_baseColorTexture
Expand All @@ -61,22 +61,27 @@ uniform sampler2D u_emissionTexture;
#endif

#ifdef TERRAIN_FRAGMENT_OCCLUSION
varying highp float v_depth;
in highp float v_depth;
uniform sampler2D u_depthTexture;
uniform vec2 u_inv_depth_size;

bool isOccluded() {
vec2 coord = gl_FragCoord.xy * u_inv_depth_size;
highp float depth = unpack_depth(texture2D(u_depthTexture, coord));
highp float depth = unpack_depth(texture(u_depthTexture, coord));
// Add some marging to avoid depth precision issues
return v_depth > depth + 0.0005;
}
#endif

const float M_PI = 3.141592653589793;

#define saturate(_x) clamp(_x, 0., 1.)

// linear to sRGB approximation
vec3 linearTosRGB(vec3 color) {
return pow(color, vec3(1./2.2));
}
vec3 sRGBToLinear(vec3 srgbIn) {
return pow(srgbIn, vec3(2.2));
}

float calculate_NdotL(vec3 normal, vec3 lightDir) {
// Use slightly modified dot product for lambertian diffuse shading. This increase the range of NdotL to cover surfaces facing up to 45 degrees away from the light source.
Expand Down Expand Up @@ -125,7 +130,7 @@ vec4 getBaseColor() {

// texture Color
#if defined (HAS_TEXTURE_u_baseColorTexture) && defined (HAS_ATTRIBUTE_a_uv_2f)
vec4 texColor = texture2D(u_baseColorTexture, uv_2f);
vec4 texColor = texture(u_baseColorTexture, uv_2f);
if(u_alphaMask) {
if (texColor.w < u_alphaCutoff) {
discard;
Expand Down Expand Up @@ -198,7 +203,7 @@ highp vec3 getNormal(){

#if defined(HAS_TEXTURE_u_normalTexture) && defined(HAS_ATTRIBUTE_a_uv_2f)
// Perturb normal
vec3 nMap = texture2D( u_normalTexture, uv_2f).xyz;
vec3 nMap = texture( u_normalTexture, uv_2f).xyz;
nMap = normalize(2.0* nMap - vec3(1.0));
highp vec3 v = normalize(-v_position_height.xyz);
highp mat3 TBN = cotangentFrame(n, v, uv_2f);
Expand Down Expand Up @@ -230,7 +235,7 @@ Material getPBRMaterial() {
mat.baseColor.w *= v_roughness_metallic_emissive_alpha.w;
#endif
#if defined(HAS_TEXTURE_u_metallicRoughnessTexture) && defined(HAS_ATTRIBUTE_a_uv_2f)
vec4 mrSample = texture2D(u_metallicRoughnessTexture, uv_2f);
vec4 mrSample = texture(u_metallicRoughnessTexture, uv_2f);
mat.perceptualRoughness *= mrSample.g;
mat.metallic *= mrSample.b;
#endif
Expand Down Expand Up @@ -294,7 +299,7 @@ float D_GGX(highp float NdotH, float alphaRoughness)
{
highp float a4 = alphaRoughness * alphaRoughness;
highp float f = (NdotH * a4 -NdotH) * NdotH + 1.0;
return a4 / (M_PI * f * f);
return a4 / (PI * f * f);
}

// Disney Implementation of diffuse from Physically-Based Shading at Disney by Brent Burley. See Section 5.3.
Expand All @@ -303,7 +308,7 @@ vec3 diffuseBurley(Material mat, float LdotH, float NdotL, float NdotV)
{
float f90 = 2.0 * LdotH * LdotH * mat.alphaRoughness - 0.5;

return (mat.diffuseColor / M_PI) * (1.0 + f90 * pow((1.0 - NdotL), 5.0)) * (1.0 + f90 * pow((1.0 - NdotV), 5.0));
return (mat.diffuseColor / PI) * (1.0 + f90 * pow((1.0 - NdotL), 5.0)) * (1.0 + f90 * pow((1.0 - NdotV), 5.0));
}

vec3 diffuseLambertian(Material mat)
Expand All @@ -313,7 +318,7 @@ vec3 diffuseLambertian(Material mat)
// remove the PI division to achieve more integrated colors
return mat.diffuseColor;
#else
return mat.diffuseColor / M_PI;
return mat.diffuseColor / PI;
#endif

}
Expand Down Expand Up @@ -429,7 +434,7 @@ vec4 finalColor;
// For b3dm tiles where models contains occlusion textures we interpret them similarly to how
// we handle baseColorTexture as an alpha mask (i.e one channel).
// This is why we read the alpha component here (refer to getBaseColor to see how baseColorTexture.w is used to implement alpha masking).
float ao = (texture2D(u_occlusionTexture, uv_2f).r - 1.0) * u_aoIntensity + 1.0;
float ao = (texture(u_occlusionTexture, uv_2f).r - 1.0) * u_aoIntensity + 1.0;
diffuse *= ao;
#endif
finalColor = vec4(diffuse, 1.0) * u_opacity;
Expand All @@ -440,14 +445,14 @@ vec4 finalColor;
// Ambient Occlusion
float ao = 1.0;
#if defined (HAS_TEXTURE_u_occlusionTexture) && defined(HAS_ATTRIBUTE_a_uv_2f)
ao = (texture2D(u_occlusionTexture, uv_2f).x - 1.0) * u_aoIntensity + 1.0;
ao = (texture(u_occlusionTexture, uv_2f).x - 1.0) * u_aoIntensity + 1.0;
color *= ao;
#endif
// Emission
vec4 emissive = u_emissiveFactor;

#if defined(HAS_TEXTURE_u_emissionTexture) && defined(HAS_ATTRIBUTE_a_uv_2f)
emissive.rgb *= sRGBToLinear(texture2D(u_emissionTexture, uv_2f).rgb);
emissive.rgb *= sRGBToLinear(texture(u_emissionTexture, uv_2f).rgb);
#endif
color += emissive.rgb;

Expand Down Expand Up @@ -488,10 +493,10 @@ vec4 finalColor;
finalColor = applyCutout(finalColor);
#endif

gl_FragColor = finalColor;
glFragColor = finalColor;

#ifdef OVERDRAW_INSPECTOR
gl_FragColor = vec4(1.0);
glFragColor = vec4(1.0);
#endif

HANDLE_WIREFRAME_DEBUG;
Expand Down
Loading