diff --git a/include/mbgl/shaders/gl/drawable_symbol_icon.hpp b/include/mbgl/shaders/gl/drawable_symbol_icon.hpp index ea662bd41..9c62bb798 100644 --- a/include/mbgl/shaders/gl/drawable_symbol_icon.hpp +++ b/include/mbgl/shaders/gl/drawable_symbol_icon.hpp @@ -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 { diff --git a/include/mbgl/shaders/gl/drawable_symbol_sdf.hpp b/include/mbgl/shaders/gl/drawable_symbol_sdf.hpp index e32be9b92..be2b56a39 100644 --- a/include/mbgl/shaders/gl/drawable_symbol_sdf.hpp +++ b/include/mbgl/shaders/gl/drawable_symbol_sdf.hpp @@ -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 { @@ -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 { diff --git a/include/mbgl/shaders/gl/drawable_symbol_text_and_icon.hpp b/include/mbgl/shaders/gl/drawable_symbol_text_and_icon.hpp index 3ad6da0a9..9589b057b 100644 --- a/include/mbgl/shaders/gl/drawable_symbol_text_and_icon.hpp +++ b/include/mbgl/shaders/gl/drawable_symbol_text_and_icon.hpp @@ -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 { @@ -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 { diff --git a/include/mbgl/shaders/mtl/common.hpp b/include/mbgl/shaders/mtl/common.hpp index f0e00aa20..c7f20a265 100644 --- a/include/mbgl/shaders/mtl/common.hpp +++ b/include/mbgl/shaders/mtl/common.hpp @@ -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"); diff --git a/include/mbgl/shaders/mtl/symbol_icon.hpp b/include/mbgl/shaders/mtl/symbol_icon.hpp index ffe5e96ad..3de7d6d39 100644 --- a/include/mbgl/shaders/mtl/symbol_icon.hpp +++ b/include/mbgl/shaders/mtl/symbol_icon.hpp @@ -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 @@ -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); diff --git a/include/mbgl/shaders/mtl/symbol_sdf.hpp b/include/mbgl/shaders/mtl/symbol_sdf.hpp index f7a540e12..bff393a78 100644 --- a/include/mbgl/shaders/mtl/symbol_sdf.hpp +++ b/include/mbgl/shaders/mtl/symbol_sdf.hpp @@ -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 @@ -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); @@ -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 image [[texture(0)]], @@ -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; diff --git a/include/mbgl/shaders/mtl/symbol_text_and_icon.hpp b/include/mbgl/shaders/mtl/symbol_text_and_icon.hpp index 4281907eb..51c234efa 100644 --- a/include/mbgl/shaders/mtl/symbol_text_and_icon.hpp +++ b/include/mbgl/shaders/mtl/symbol_text_and_icon.hpp @@ -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 @@ -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); @@ -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 glyph_image [[texture(0)]], @@ -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; diff --git a/include/mbgl/shaders/symbol_layer_ubo.hpp b/include/mbgl/shaders/symbol_layer_ubo.hpp index cb7ce699a..352d12b7a 100644 --- a/include/mbgl/shaders/symbol_layer_ubo.hpp +++ b/include/mbgl/shaders/symbol_layer_ubo.hpp @@ -40,22 +40,19 @@ struct alignas(16) SymbolDrawableUBO { /* 200 */ std::array 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 pad; - /* 240 */ + /* 216 */ std::array 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 pad2; + /* 4 */ float camera_to_center_distance; + /* 8 */ float device_pixel_ratio; + /* 12 */ float aspect_ratio; /* 16 */ }; static_assert(sizeof(SymbolDynamicUBO) == 16); diff --git a/shaders/drawable.symbol_icon.vertex.glsl b/shaders/drawable.symbol_icon.vertex.glsl index f687964c9..eebbe2c27 100644 --- a/shaders/drawable.symbol_icon.vertex.glsl +++ b/shaders/drawable.symbol_icon.vertex.glsl @@ -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 { diff --git a/shaders/drawable.symbol_sdf.fragment.glsl b/shaders/drawable.symbol_sdf.fragment.glsl index 6f78084d0..980d30251 100644 --- a/shaders/drawable.symbol_sdf.fragment.glsl +++ b/shaders/drawable.symbol_sdf.fragment.glsl @@ -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 { diff --git a/shaders/drawable.symbol_sdf.vertex.glsl b/shaders/drawable.symbol_sdf.vertex.glsl index e4d5d4bf2..6c6287f15 100644 --- a/shaders/drawable.symbol_sdf.vertex.glsl +++ b/shaders/drawable.symbol_sdf.vertex.glsl @@ -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 { diff --git a/shaders/drawable.symbol_text_and_icon.fragment.glsl b/shaders/drawable.symbol_text_and_icon.fragment.glsl index 3e0483614..44c4931d2 100644 --- a/shaders/drawable.symbol_text_and_icon.fragment.glsl +++ b/shaders/drawable.symbol_text_and_icon.fragment.glsl @@ -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 { diff --git a/shaders/drawable.symbol_text_and_icon.vertex.glsl b/shaders/drawable.symbol_text_and_icon.vertex.glsl index 83d94cfcc..4c8156c40 100644 --- a/shaders/drawable.symbol_text_and_icon.vertex.glsl +++ b/shaders/drawable.symbol_text_and_icon.vertex.glsl @@ -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 { diff --git a/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp b/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp index aded5a44a..9fa33381a 100644 --- a/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp @@ -101,9 +101,12 @@ void SymbolLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete propertiesUpdated = false; } + const auto camDist = state.getCameraToCenterDistance(); + const SymbolDynamicUBO dynamicUBO = {/*.fade_change=*/parameters.symbolFadeChange, - /*.pad1=*/0, - /*.pad2=*/{0, 0}}; + /*.camera_to_center_distance=*/camDist, + /*.device_pixel_ratio=*/parameters.pixelRatio, + /*.aspect_ratio=*/state.getSize().aspectRatio()}; if (!dynamicBuffer) { dynamicBuffer = parameters.context.createUniformBuffer(&dynamicUBO, sizeof(dynamicUBO)); @@ -153,7 +156,6 @@ void SymbolLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete matrix, pitchWithMap, rotateWithMap, state, pixelsToTileUnits); const mat4 glCoordMatrix = getGlCoordMatrix(matrix, pitchWithMap, rotateWithMap, state, pixelsToTileUnits); - const auto camDist = state.getCameraToCenterDistance(); const float gammaScale = (symbolData.pitchAlignment == AlignmentType::Map ? static_cast(std::cos(state.getPitch())) * camDist : 1.0f); @@ -172,12 +174,7 @@ void SymbolLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete /*.texsize_icon=*/toArray(getTexSize(drawable, idTexIconUniformName)), /*.gamma_scale=*/gammaScale, - /*.device_pixel_ratio=*/parameters.pixelRatio, - - /*.camera_to_center_distance=*/camDist, - /*.pitch=*/static_cast(state.getPitch()), /*.rotate_symbol=*/rotateInShader, - /*.aspect_ratio=*/state.getSize().aspectRatio(), /*.pad=*/{0}, }; diff --git a/src/mbgl/shaders/mtl/symbol_sdf.cpp b/src/mbgl/shaders/mtl/symbol_sdf.cpp index f5a45a7f8..a4d1276d2 100644 --- a/src/mbgl/shaders/mtl/symbol_sdf.cpp +++ b/src/mbgl/shaders/mtl/symbol_sdf.cpp @@ -22,7 +22,7 @@ const std::array ShaderSource ShaderSource::uniforms = { UniformBlockInfo{10, true, true, sizeof(SymbolDrawableUBO), "SymbolDrawableUBO"}, - UniformBlockInfo{11, true, false, sizeof(SymbolDynamicUBO), "SymbolDynamicUBO"}, + UniformBlockInfo{11, true, true, sizeof(SymbolDynamicUBO), "SymbolDynamicUBO"}, UniformBlockInfo{12, true, false, sizeof(SymbolDrawablePaintUBO), "SymbolDrawablePaintUBO"}, UniformBlockInfo{13, true, true, sizeof(SymbolDrawableTilePropsUBO), "SymbolDrawableTilePropsUBO"}, UniformBlockInfo{14, true, false, sizeof(SymbolDrawableInterpolateUBO), "SymbolDrawableInterpolateUBO"}, diff --git a/src/mbgl/shaders/mtl/symbol_text_and_icon.cpp b/src/mbgl/shaders/mtl/symbol_text_and_icon.cpp index 69023d4fc..c22bcc5cf 100644 --- a/src/mbgl/shaders/mtl/symbol_text_and_icon.cpp +++ b/src/mbgl/shaders/mtl/symbol_text_and_icon.cpp @@ -21,7 +21,7 @@ const std::array const std::array ShaderSource::uniforms = { UniformBlockInfo{9, true, true, sizeof(SymbolDrawableUBO), "SymbolDrawableUBO"}, - UniformBlockInfo{10, true, false, sizeof(SymbolDynamicUBO), "SymbolDynamicUBO"}, + UniformBlockInfo{10, true, true, sizeof(SymbolDynamicUBO), "SymbolDynamicUBO"}, UniformBlockInfo{11, true, false, sizeof(SymbolDrawablePaintUBO), "SymbolDrawablePaintUBO"}, UniformBlockInfo{12, true, true, sizeof(SymbolDrawableTilePropsUBO), "SymbolDrawableTilePropsUBO"}, UniformBlockInfo{13, true, false, sizeof(SymbolDrawableInterpolateUBO), "SymbolDrawableInterpolateUBO"},