Skip to content

Commit

Permalink
Symbol improve UBO (maplibre#1893)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcristici authored Nov 28, 2023
1 parent 178454b commit db2e95a
Show file tree
Hide file tree
Showing 16 changed files with 61 additions and 109 deletions.
10 changes: 3 additions & 7 deletions include/mbgl/shaders/gl/drawable_symbol_icon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,15 @@ layout (std140) uniform SymbolDrawableUBO {
highp vec2 u_texsize_icon;
highp float u_gamma_scale;
highp float u_device_pixel_ratio;
highp float u_camera_to_center_distance;
highp float u_pitch;
bool u_rotate_symbol;
highp float u_aspect_ratio;
highp vec2 u_pad1;
};
layout (std140) uniform SymbolDynamicUBO {
highp float u_fade_change;
highp float u_pad7;
highp vec2 u_pad8;
highp float u_camera_to_center_distance;
highp float u_device_pixel_ratio;
highp float u_aspect_ratio;
};
layout (std140) uniform SymbolDrawablePaintUBO {
Expand Down
20 changes: 6 additions & 14 deletions include/mbgl/shaders/gl/drawable_symbol_sdf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,15 @@ layout (std140) uniform SymbolDrawableUBO {
highp vec2 u_texsize_icon;
highp float u_gamma_scale;
highp float u_device_pixel_ratio;
highp float u_camera_to_center_distance;
highp float u_pitch;
bool u_rotate_symbol;
highp float u_aspect_ratio;
highp vec2 u_pad1;
};
layout (std140) uniform SymbolDynamicUBO {
highp float u_fade_change;
highp float u_pad7;
highp vec2 u_pad8;
highp float u_camera_to_center_distance;
highp float u_device_pixel_ratio;
highp float u_aspect_ratio;
};
layout (std140) uniform SymbolDrawablePaintUBO {
Expand Down Expand Up @@ -206,19 +202,15 @@ layout (std140) uniform SymbolDrawableUBO {
highp vec2 u_texsize_icon;
highp float u_gamma_scale;
highp float u_device_pixel_ratio;
highp float u_camera_to_center_distance;
highp float u_pitch;
bool u_rotate_symbol;
highp float u_aspect_ratio;
highp vec2 u_pad1;
};
layout (std140) uniform SymbolDynamicUBO {
highp float u_fade_change;
highp float u_pad7;
highp vec2 u_pad8;
highp float u_camera_to_center_distance;
highp float u_device_pixel_ratio;
highp float u_aspect_ratio;
};
layout (std140) uniform SymbolDrawablePaintUBO {
Expand Down
20 changes: 6 additions & 14 deletions include/mbgl/shaders/gl/drawable_symbol_text_and_icon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,15 @@ layout (std140) uniform SymbolDrawableUBO {
highp vec2 u_texsize_icon;
highp float u_gamma_scale;
highp float u_device_pixel_ratio;
highp float u_camera_to_center_distance;
highp float u_pitch;
bool u_rotate_symbol;
highp float u_aspect_ratio;
highp vec2 u_pad1;
};
layout (std140) uniform SymbolDynamicUBO {
highp float u_fade_change;
highp float u_pad7;
highp vec2 u_pad8;
highp float u_camera_to_center_distance;
highp float u_device_pixel_ratio;
highp float u_aspect_ratio;
};
layout (std140) uniform SymbolDrawablePaintUBO {
Expand Down Expand Up @@ -209,19 +205,15 @@ layout (std140) uniform SymbolDrawableUBO {
highp vec2 u_texsize_icon;
highp float u_gamma_scale;
highp float u_device_pixel_ratio;
highp float u_camera_to_center_distance;
highp float u_pitch;
bool u_rotate_symbol;
highp float u_aspect_ratio;
highp vec2 u_pad1;
};
layout (std140) uniform SymbolDynamicUBO {
highp float u_fade_change;
highp float u_pad7;
highp vec2 u_pad8;
highp float u_camera_to_center_distance;
highp float u_device_pixel_ratio;
highp float u_aspect_ratio;
};
layout (std140) uniform SymbolDrawablePaintUBO {
Expand Down
12 changes: 4 additions & 8 deletions include/mbgl/shaders/mtl/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,20 +228,16 @@ struct alignas(16) SymbolDrawableUBO {
float2 texsize_icon;
float gamma_scale;
float device_pixel_ratio;
float camera_to_center_distance;
float pitch;
/*bool*/ int rotate_symbol;
float aspect_ratio;
float2 pad;
};
static_assert(sizeof(SymbolDrawableUBO) == 15 * 16, "unexpected padding");
static_assert(sizeof(SymbolDrawableUBO) == 14 * 16, "unexpected padding");
struct alignas(16) SymbolDynamicUBO {
float fade_change;
float pad1;
float2 pad2;
float camera_to_center_distance;
float device_pixel_ratio;
float aspect_ratio;
};
static_assert(sizeof(SymbolDynamicUBO) == 16, "unexpected padding");
Expand Down
6 changes: 3 additions & 3 deletions include/mbgl/shaders/mtl/symbol_icon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
const float camera_to_anchor_distance = projectedPoint.w;
// See comments in symbol_sdf.vertex
const float distance_ratio = props.pitch_with_map ?
camera_to_anchor_distance / drawable.camera_to_center_distance :
drawable.camera_to_center_distance / camera_to_anchor_distance;
camera_to_anchor_distance / dynamic.camera_to_center_distance :
dynamic.camera_to_center_distance / camera_to_anchor_distance;
const float perspective_ratio = clamp(
0.5 + 0.5 * distance_ratio,
0.0, // Prevents oversized near-field symbols in pitched/overzoomed tiles
Expand All @@ -89,7 +89,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
const float2 a = projectedPoint.xy / projectedPoint.w;
const float2 b = offsetProjectedPoint.xy / offsetProjectedPoint.w;
symbol_rotation = atan2((b.y - a.y) / drawable.aspect_ratio, b.x - a.x);
symbol_rotation = atan2((b.y - a.y) / dynamic.aspect_ratio, b.x - a.x);
}
const float angle_sin = sin(segment_angle + symbol_rotation);
Expand Down
9 changes: 5 additions & 4 deletions include/mbgl/shaders/mtl/symbol_sdf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
// which makes labels in the distance larger relative to the features around
// them. We counteract part of that effect by dividing by the perspective ratio.
const float distance_ratio = props.pitch_with_map ?
camera_to_anchor_distance / drawable.camera_to_center_distance :
drawable.camera_to_center_distance / camera_to_anchor_distance;
camera_to_anchor_distance / dynamic.camera_to_center_distance :
dynamic.camera_to_center_distance / camera_to_anchor_distance;
const float perspective_ratio = clamp(
0.5 + 0.5 * distance_ratio,
0.0, // Prevents oversized near-field symbols in pitched/overzoomed tiles
Expand All @@ -109,7 +109,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
const float2 a = projectedPoint.xy / projectedPoint.w;
const float2 b = offsetProjectedPoint.xy / offsetProjectedPoint.w;
symbol_rotation = atan2((b.y - a.y) / drawable.aspect_ratio, b.x - a.x);
symbol_rotation = atan2((b.y - a.y) / dynamic.aspect_ratio, b.x - a.x);
}
const float angle_sin = sin(segment_angle + symbol_rotation);
Expand Down Expand Up @@ -140,6 +140,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
device const SymbolDrawableUBO& drawable [[buffer(10)]],
device const SymbolDynamicUBO& dynamic [[buffer(11)]],
device const SymbolDrawableTilePropsUBO& props [[buffer(13)]],
device const SymbolPermutationUBO& permutation [[buffer(15)]],
texture2d<float, access::sample> image [[texture(0)]],
Expand All @@ -148,7 +149,7 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]],
return half4(1.0);
}
const float EDGE_GAMMA = 0.105 / drawable.device_pixel_ratio;
const float EDGE_GAMMA = 0.105 / dynamic.device_pixel_ratio;
const float2 tex = in.data0.xy;
const float gamma_scale = in.data1.x;
Expand Down
9 changes: 5 additions & 4 deletions include/mbgl/shaders/mtl/symbol_text_and_icon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
// which makes labels in the distance larger relative to the features around
// them. We counteract part of that effect by dividing by the perspective ratio.
const float distance_ratio = props.pitch_with_map ?
camera_to_anchor_distance / drawable.camera_to_center_distance :
drawable.camera_to_center_distance / camera_to_anchor_distance;
camera_to_anchor_distance / dynamic.camera_to_center_distance :
dynamic.camera_to_center_distance / camera_to_anchor_distance;
const float perspective_ratio = clamp(
0.5 + 0.5 * distance_ratio,
0.0, // Prevents oversized near-field symbols in pitched/overzoomed tiles
Expand All @@ -111,7 +111,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
const float2 a = projectedPoint.xy / projectedPoint.w;
const float2 b = offsetProjectedPoint.xy / offsetProjectedPoint.w;
symbol_rotation = atan2((b.y - a.y) / drawable.aspect_ratio, b.x - a.x);
symbol_rotation = atan2((b.y - a.y) / dynamic.aspect_ratio, b.x - a.x);
}
const float angle_sin = sin(segment_angle + symbol_rotation);
Expand Down Expand Up @@ -142,6 +142,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
device const SymbolDrawableUBO& drawable [[buffer(9)]],
device const SymbolDynamicUBO& dynamic [[buffer(10)]],
device const SymbolDrawableTilePropsUBO& props [[buffer(12)]],
device const SymbolPermutationUBO& permutation [[buffer(14)]],
texture2d<float, access::sample> glyph_image [[texture(0)]],
Expand All @@ -161,7 +162,7 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]],
}
const float2 tex = in.data0.xy;
const float EDGE_GAMMA = 0.105 / drawable.device_pixel_ratio;
const float EDGE_GAMMA = 0.105 / dynamic.device_pixel_ratio;
const float gamma_scale = in.data1.x;
const float size = in.data1.y;
Expand Down
17 changes: 7 additions & 10 deletions include/mbgl/shaders/symbol_layer_ubo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,19 @@ struct alignas(16) SymbolDrawableUBO {
/* 200 */ std::array<float, 2> texsize_icon;

/* 208 */ float gamma_scale;
/* 212 */ float device_pixel_ratio;
/* 212 */ /*bool*/ int rotate_symbol;

/* 216 */ float camera_to_center_distance;
/* 220 */ float pitch;
/* 224 */ /*bool*/ int rotate_symbol;
/* 228 */ float aspect_ratio;
/* 232 */ std::array<float, 2> pad;
/* 240 */
/* 216 */ std::array<float, 2> pad;
/* 224 */
};
static_assert(sizeof(SymbolDrawableUBO) == 15 * 16);
static_assert(sizeof(SymbolDrawableUBO) == 14 * 16);

/// Dynamic UBO
struct alignas(16) SymbolDynamicUBO {
/* 0 */ float fade_change;
/* 4 */ float pad1;
/* 8 */ std::array<float, 2> pad2;
/* 4 */ float camera_to_center_distance;
/* 8 */ float device_pixel_ratio;
/* 12 */ float aspect_ratio;
/* 16 */
};
static_assert(sizeof(SymbolDynamicUBO) == 16);
Expand Down
10 changes: 3 additions & 7 deletions shaders/drawable.symbol_icon.vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,15 @@ layout (std140) uniform SymbolDrawableUBO {
highp vec2 u_texsize_icon;

highp float u_gamma_scale;
highp float u_device_pixel_ratio;

highp float u_camera_to_center_distance;
highp float u_pitch;
bool u_rotate_symbol;
highp float u_aspect_ratio;
highp vec2 u_pad1;
};

layout (std140) uniform SymbolDynamicUBO {
highp float u_fade_change;
highp float u_pad7;
highp vec2 u_pad8;
highp float u_camera_to_center_distance;
highp float u_device_pixel_ratio;
highp float u_aspect_ratio;
};

layout (std140) uniform SymbolDrawablePaintUBO {
Expand Down
10 changes: 3 additions & 7 deletions shaders/drawable.symbol_sdf.fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,15 @@ layout (std140) uniform SymbolDrawableUBO {
highp vec2 u_texsize_icon;

highp float u_gamma_scale;
highp float u_device_pixel_ratio;

highp float u_camera_to_center_distance;
highp float u_pitch;
bool u_rotate_symbol;
highp float u_aspect_ratio;
highp vec2 u_pad1;
};

layout (std140) uniform SymbolDynamicUBO {
highp float u_fade_change;
highp float u_pad7;
highp vec2 u_pad8;
highp float u_camera_to_center_distance;
highp float u_device_pixel_ratio;
highp float u_aspect_ratio;
};

layout (std140) uniform SymbolDrawablePaintUBO {
Expand Down
10 changes: 3 additions & 7 deletions shaders/drawable.symbol_sdf.vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,15 @@ layout (std140) uniform SymbolDrawableUBO {
highp vec2 u_texsize_icon;

highp float u_gamma_scale;
highp float u_device_pixel_ratio;

highp float u_camera_to_center_distance;
highp float u_pitch;
bool u_rotate_symbol;
highp float u_aspect_ratio;
highp vec2 u_pad1;
};

layout (std140) uniform SymbolDynamicUBO {
highp float u_fade_change;
highp float u_pad7;
highp vec2 u_pad8;
highp float u_camera_to_center_distance;
highp float u_device_pixel_ratio;
highp float u_aspect_ratio;
};

layout (std140) uniform SymbolDrawablePaintUBO {
Expand Down
10 changes: 3 additions & 7 deletions shaders/drawable.symbol_text_and_icon.fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,15 @@ layout (std140) uniform SymbolDrawableUBO {
highp vec2 u_texsize_icon;

highp float u_gamma_scale;
highp float u_device_pixel_ratio;

highp float u_camera_to_center_distance;
highp float u_pitch;
bool u_rotate_symbol;
highp float u_aspect_ratio;
highp vec2 u_pad1;
};

layout (std140) uniform SymbolDynamicUBO {
highp float u_fade_change;
highp float u_pad7;
highp vec2 u_pad8;
highp float u_camera_to_center_distance;
highp float u_device_pixel_ratio;
highp float u_aspect_ratio;
};

layout (std140) uniform SymbolDrawablePaintUBO {
Expand Down
10 changes: 3 additions & 7 deletions shaders/drawable.symbol_text_and_icon.vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,15 @@ layout (std140) uniform SymbolDrawableUBO {
highp vec2 u_texsize_icon;

highp float u_gamma_scale;
highp float u_device_pixel_ratio;

highp float u_camera_to_center_distance;
highp float u_pitch;
bool u_rotate_symbol;
highp float u_aspect_ratio;
highp vec2 u_pad1;
};

layout (std140) uniform SymbolDynamicUBO {
highp float u_fade_change;
highp float u_pad7;
highp vec2 u_pad8;
highp float u_camera_to_center_distance;
highp float u_device_pixel_ratio;
highp float u_aspect_ratio;
};

layout (std140) uniform SymbolDrawablePaintUBO {
Expand Down
Loading

0 comments on commit db2e95a

Please sign in to comment.