UBO consolidation (#3089)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -154,7 +154,6 @@ if(MLN_DRAWABLE_RENDERER)
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/gfx/drawable_atlases_tweaker.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/gfx/drawable_custom_layer_host_tweaker.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/gfx/gpu_expression.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/gfx/uniform_block.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/gfx/uniform_buffer.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/gfx/vertex_attribute.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/gfx/texture2d.hpp
|
||||
@@ -178,7 +177,6 @@ if(MLN_DRAWABLE_RENDERER)
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/gfx/line_drawable_data.hpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/gfx/symbol_drawable_data.hpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/gfx/collision_drawable_data.hpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/gfx/uniform_block.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/gfx/uniform_buffer.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/gfx/vertex_attribute.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/renderer/render_target.cpp
|
||||
@@ -1036,6 +1034,7 @@ if(MLN_WITH_OPENGL)
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_circle.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_collision_box.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_collision_circle.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_custom_symbol_icon.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_debug.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_fill.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_fill_outline.hpp
|
||||
@@ -1052,10 +1051,13 @@ if(MLN_WITH_OPENGL)
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_line_gradient.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_line_pattern.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_line_sdf.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_location_indicator.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_location_indicator_textured.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_raster.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_symbol_icon.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_symbol_sdf.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_symbol_text_and_icon.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_wide_vector.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/background_pattern.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/circle.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/clipping_mask.hpp
|
||||
@@ -1140,9 +1142,7 @@ if(MLN_WITH_OPENGL)
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/background_layer_ubo.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/circle_layer_ubo.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/collision_layer_ubo.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/common_ubo.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/style/layers/custom_drawable_layer.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/layermanager/custom_drawable_layer_factory.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/custom_drawable_layer_ubo.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/debug_layer_ubo.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/fill_layer_ubo.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/fill_extrusion_layer_ubo.hpp
|
||||
@@ -1152,17 +1152,18 @@ if(MLN_WITH_OPENGL)
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/hillshade_prepare_layer_ubo.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/layer_ubo.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/line_layer_ubo.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/custom_drawable_layer_ubo.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/location_indicator_ubo.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/raster_layer_ubo.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/shader_defines.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/symbol_layer_ubo.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/widevector_ubo.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/style/layers/custom_drawable_layer.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/layermanager/custom_drawable_layer_factory.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/shader_program_gl.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/gl/buffer_allocator.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/gl/drawable_gl.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/gl/drawable_gl_builder.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/gl/layer_group_gl.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/gl/uniform_block_gl.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/gl/uniform_buffer_gl.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/gl/vertex_attribute_gl.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/gl/texture2d.hpp
|
||||
@@ -1176,7 +1177,6 @@ if(MLN_WITH_OPENGL)
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/gl/drawable_gl_impl.hpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/gl/layer_group_gl.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/gl/texture2d.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/gl/uniform_block_gl.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/gl/uniform_buffer_gl.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/gl/vertex_attribute_gl.cpp
|
||||
)
|
||||
@@ -1207,23 +1207,19 @@ if(MLN_WITH_METAL)
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/mtl/renderable_resource.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/mtl/texture2d.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/mtl/tile_layer_group.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/mtl/uniform_block.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/mtl/uniform_buffer.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/mtl/upload_pass.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/mtl/vertex_attribute.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/mtl/vertex_buffer_resource.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/background.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/background_pattern.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/circle.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/clipping_mask.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/common.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/collision_box.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/collision_circle.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/collision.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/custom_symbol_icon.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/debug.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/fill.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/fill_extrusion.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/fill_extrusion_pattern.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/heatmap.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/heatmap_texture.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/hillshade.hpp
|
||||
@@ -1232,9 +1228,7 @@ if(MLN_WITH_METAL)
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/raster.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/shader_group.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/shader_program.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/symbol_icon.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/symbol_sdf.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/symbol_text_and_icon.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/symbol.hpp
|
||||
)
|
||||
list(APPEND
|
||||
SRC_FILES
|
||||
@@ -1252,32 +1246,27 @@ if(MLN_WITH_METAL)
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/mtl/texture2d.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/mtl/render_pass.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/mtl/tile_layer_group.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/mtl/uniform_block.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/mtl/uniform_buffer.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/mtl/upload_pass.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/mtl/vertex_attribute.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/mtl/vertex_buffer_resource.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/shader_program.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/background.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/background_pattern.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/circle.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/collision_box.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/collision_circle.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/collision.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/clipping_mask.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/custom_symbol_icon.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/debug.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/fill.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/fill_extrusion.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/fill_extrusion_pattern.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/heatmap.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/heatmap_texture.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/hillshade.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/hillshade_prepare.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/line.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/raster.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/symbol_icon.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/symbol_sdf.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/symbol_text_and_icon.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/symbol.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/widevector.cpp
|
||||
)
|
||||
|
||||
find_library(METAL_FRAMEWORK Metal)
|
||||
@@ -1323,11 +1312,15 @@ if(MLN_WITH_VULKAN)
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/vulkan/clipping_mask.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/vulkan/collision.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/vulkan/common.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/vulkan/debug.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/vulkan/custom_symbol_icon.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/vulkan/fill.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/vulkan/fill_extrusion.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/vulkan/heatmap.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/vulkan/heatmap_texture.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/vulkan/hillshade.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/vulkan/hillshade_prepare.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/vulkan/line.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/vulkan/location_indicator.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/vulkan/raster.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/vulkan/symbol.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/vulkan/widevector.hpp
|
||||
@@ -1359,12 +1352,16 @@ if(MLN_WITH_VULKAN)
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/circle.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/clipping_mask.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/collision.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/common.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/custom_symbol_icon.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/debug.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/fill.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/fill_extrusion.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/heatmap.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/heatmap_texture.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/hillshade.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/hillshade_prepare.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/line.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/location_indicator.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/raster.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/symbol.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/widevector.cpp
|
||||
|
||||
@@ -84,6 +84,8 @@ MLN_GENERATED_OPENGL_SHADER_HEADERS = [
|
||||
"include/mbgl/shaders/gl/drawable_line_pattern.hpp",
|
||||
"include/mbgl/shaders/gl/drawable_line_sdf.hpp",
|
||||
"include/mbgl/shaders/gl/drawable_line.hpp",
|
||||
"include/mbgl/shaders/gl/drawable_location_indicator.hpp",
|
||||
"include/mbgl/shaders/gl/drawable_location_indicator_textured.hpp",
|
||||
"include/mbgl/shaders/gl/drawable_raster.hpp",
|
||||
"include/mbgl/shaders/gl/drawable_symbol_icon.hpp",
|
||||
"include/mbgl/shaders/gl/drawable_symbol_sdf.hpp",
|
||||
@@ -941,7 +943,6 @@ MLN_DRAWABLES_SOURCE = [
|
||||
"src/mbgl/gfx/line_drawable_data.hpp",
|
||||
"src/mbgl/gfx/symbol_drawable_data.hpp",
|
||||
"src/mbgl/gfx/collision_drawable_data.hpp",
|
||||
"src/mbgl/gfx/uniform_block.cpp",
|
||||
"src/mbgl/gfx/uniform_buffer.cpp",
|
||||
"src/mbgl/gfx/vertex_attribute.cpp",
|
||||
"src/mbgl/renderer/change_request.cpp",
|
||||
@@ -993,7 +994,6 @@ MLN_DRAWABLES_HEADERS = [
|
||||
"include/mbgl/gfx/drawable_atlases_tweaker.hpp",
|
||||
"include/mbgl/gfx/drawable_custom_layer_host_tweaker.hpp",
|
||||
"include/mbgl/gfx/gpu_expression.hpp",
|
||||
"include/mbgl/gfx/uniform_block.hpp",
|
||||
"include/mbgl/gfx/uniform_buffer.hpp",
|
||||
"include/mbgl/gfx/vertex_attribute.hpp",
|
||||
"include/mbgl/gfx/texture2d.hpp",
|
||||
@@ -1004,7 +1004,6 @@ MLN_DRAWABLES_HEADERS = [
|
||||
"include/mbgl/shaders/background_layer_ubo.hpp",
|
||||
"include/mbgl/shaders/circle_layer_ubo.hpp",
|
||||
"include/mbgl/shaders/collision_layer_ubo.hpp",
|
||||
"include/mbgl/shaders/common_ubo.hpp",
|
||||
"include/mbgl/shaders/custom_drawable_layer_ubo.hpp",
|
||||
"include/mbgl/shaders/debug_layer_ubo.hpp",
|
||||
"include/mbgl/shaders/fill_layer_ubo.hpp",
|
||||
@@ -1015,6 +1014,7 @@ MLN_DRAWABLES_HEADERS = [
|
||||
"include/mbgl/shaders/hillshade_prepare_layer_ubo.hpp",
|
||||
"include/mbgl/shaders/layer_ubo.hpp",
|
||||
"include/mbgl/shaders/line_layer_ubo.hpp",
|
||||
"include/mbgl/shaders/location_indicator_ubo.hpp",
|
||||
"include/mbgl/shaders/raster_layer_ubo.hpp",
|
||||
"include/mbgl/shaders/shader_defines.hpp",
|
||||
"include/mbgl/shaders/shader_program_base.hpp",
|
||||
@@ -1032,7 +1032,6 @@ MLN_DRAWABLES_GL_SOURCE = [
|
||||
"src/mbgl/gl/drawable_gl_impl.hpp",
|
||||
"src/mbgl/gl/layer_group_gl.cpp",
|
||||
"src/mbgl/gl/texture2d.cpp",
|
||||
"src/mbgl/gl/uniform_block_gl.cpp",
|
||||
"src/mbgl/gl/uniform_buffer_gl.cpp",
|
||||
"src/mbgl/gl/vertex_attribute_gl.cpp",
|
||||
"src/mbgl/shaders/gl/shader_info.cpp",
|
||||
@@ -1044,7 +1043,6 @@ MLN_DRAWABLES_GL_HEADERS = [
|
||||
"include/mbgl/gl/drawable_gl.hpp",
|
||||
"include/mbgl/gl/drawable_gl_builder.hpp",
|
||||
"include/mbgl/gl/layer_group_gl.hpp",
|
||||
"include/mbgl/gl/uniform_block_gl.hpp",
|
||||
"include/mbgl/gl/uniform_buffer_gl.hpp",
|
||||
"include/mbgl/gl/vertex_attribute_gl.hpp",
|
||||
"include/mbgl/gl/texture2d.hpp",
|
||||
@@ -1068,32 +1066,27 @@ MLN_DRAWABLES_MTL_SOURCE = [
|
||||
"src/mbgl/mtl/texture2d.cpp",
|
||||
"src/mbgl/mtl/render_pass.cpp",
|
||||
"src/mbgl/mtl/tile_layer_group.cpp",
|
||||
"src/mbgl/mtl/uniform_block.cpp",
|
||||
"src/mbgl/mtl/uniform_buffer.cpp",
|
||||
"src/mbgl/mtl/upload_pass.cpp",
|
||||
"src/mbgl/mtl/vertex_attribute.cpp",
|
||||
"src/mbgl/mtl/vertex_buffer_resource.cpp",
|
||||
"src/mbgl/shaders/mtl/shader_program.cpp",
|
||||
"src/mbgl/shaders/mtl/background.cpp",
|
||||
"src/mbgl/shaders/mtl/background_pattern.cpp",
|
||||
"src/mbgl/shaders/mtl/circle.cpp",
|
||||
"src/mbgl/shaders/mtl/collision_box.cpp",
|
||||
"src/mbgl/shaders/mtl/collision_circle.cpp",
|
||||
"src/mbgl/shaders/mtl/collision.cpp",
|
||||
"src/mbgl/shaders/mtl/clipping_mask.cpp",
|
||||
"src/mbgl/shaders/mtl/custom_symbol_icon.cpp",
|
||||
"src/mbgl/shaders/mtl/debug.cpp",
|
||||
"src/mbgl/shaders/mtl/fill.cpp",
|
||||
"src/mbgl/shaders/mtl/fill_extrusion.cpp",
|
||||
"src/mbgl/shaders/mtl/fill_extrusion_pattern.cpp",
|
||||
"src/mbgl/shaders/mtl/heatmap.cpp",
|
||||
"src/mbgl/shaders/mtl/heatmap_texture.cpp",
|
||||
"src/mbgl/shaders/mtl/hillshade.cpp",
|
||||
"src/mbgl/shaders/mtl/hillshade_prepare.cpp",
|
||||
"src/mbgl/shaders/mtl/line.cpp",
|
||||
"src/mbgl/shaders/mtl/raster.cpp",
|
||||
"src/mbgl/shaders/mtl/symbol_icon.cpp",
|
||||
"src/mbgl/shaders/mtl/symbol_sdf.cpp",
|
||||
"src/mbgl/shaders/mtl/symbol_text_and_icon.cpp",
|
||||
"src/mbgl/shaders/mtl/symbol.cpp",
|
||||
"src/mbgl/shaders/mtl/widevector.cpp",
|
||||
"src/mbgl/style/layers/mtl/custom_layer_render_parameters.cpp",
|
||||
]
|
||||
|
||||
@@ -1112,23 +1105,19 @@ MLN_DRAWABLES_MTL_HEADERS = [
|
||||
"include/mbgl/mtl/renderable_resource.hpp",
|
||||
"include/mbgl/mtl/texture2d.hpp",
|
||||
"include/mbgl/mtl/tile_layer_group.hpp",
|
||||
"include/mbgl/mtl/uniform_block.hpp",
|
||||
"include/mbgl/mtl/uniform_buffer.hpp",
|
||||
"include/mbgl/mtl/upload_pass.hpp",
|
||||
"include/mbgl/mtl/vertex_attribute.hpp",
|
||||
"include/mbgl/mtl/vertex_buffer_resource.hpp",
|
||||
"include/mbgl/shaders/mtl/background.hpp",
|
||||
"include/mbgl/shaders/mtl/background_pattern.hpp",
|
||||
"include/mbgl/shaders/mtl/circle.hpp",
|
||||
"include/mbgl/shaders/mtl/clipping_mask.hpp",
|
||||
"include/mbgl/shaders/mtl/collision_box.hpp",
|
||||
"include/mbgl/shaders/mtl/collision_circle.hpp",
|
||||
"include/mbgl/shaders/mtl/collision.hpp",
|
||||
"include/mbgl/shaders/mtl/common.hpp",
|
||||
"include/mbgl/shaders/mtl/custom_symbol_icon.hpp",
|
||||
"include/mbgl/shaders/mtl/debug.hpp",
|
||||
"include/mbgl/shaders/mtl/fill.hpp",
|
||||
"include/mbgl/shaders/mtl/fill_extrusion.hpp",
|
||||
"include/mbgl/shaders/mtl/fill_extrusion_pattern.hpp",
|
||||
"include/mbgl/shaders/mtl/heatmap.hpp",
|
||||
"include/mbgl/shaders/mtl/heatmap_texture.hpp",
|
||||
"include/mbgl/shaders/mtl/hillshade.hpp",
|
||||
@@ -1137,9 +1126,7 @@ MLN_DRAWABLES_MTL_HEADERS = [
|
||||
"include/mbgl/shaders/mtl/raster.hpp",
|
||||
"include/mbgl/shaders/mtl/shader_group.hpp",
|
||||
"include/mbgl/shaders/mtl/shader_program.hpp",
|
||||
"include/mbgl/shaders/mtl/symbol_icon.hpp",
|
||||
"include/mbgl/shaders/mtl/symbol_sdf.hpp",
|
||||
"include/mbgl/shaders/mtl/symbol_text_and_icon.hpp",
|
||||
"include/mbgl/shaders/mtl/symbol.hpp",
|
||||
"include/mbgl/style/layers/mtl/custom_layer_render_parameters.hpp",
|
||||
"include/mbgl/shaders/mtl/widevector.hpp",
|
||||
]
|
||||
|
||||
@@ -125,7 +125,10 @@ public:
|
||||
/// @param data The data to copy, may be `nullptr`
|
||||
/// @param size The size of the buffer
|
||||
/// @param persistent Performance hint, optimize for few or many uses
|
||||
virtual UniformBufferPtr createUniformBuffer(const void* data, std::size_t size, bool persistent = false) = 0;
|
||||
virtual UniformBufferPtr createUniformBuffer(const void* data,
|
||||
std::size_t size,
|
||||
bool persistent = false,
|
||||
bool ssbo = false) = 0;
|
||||
|
||||
/// Get the generic shader with the specified name
|
||||
virtual gfx::ShaderProgramBasePtr getGenericShader(gfx::ShaderRegistry&, const std::string& name) = 0;
|
||||
|
||||
@@ -251,6 +251,9 @@ public:
|
||||
/// Get drawable user-defined type
|
||||
size_t getType() const { return type; }
|
||||
|
||||
void setUBOIndex(uint32_t uboIndex_) { uboIndex = uboIndex_; }
|
||||
uint32_t getUBOIndex() const { return uboIndex; }
|
||||
|
||||
/// Associate the drawable with a layer tweaker. This is used to manage the lifetime of the tweaker.
|
||||
void setLayerTweaker(LayerTweakerPtr tweaker) { layerTweaker = std::move(tweaker); }
|
||||
const LayerTweakerPtr& getLayerTweaker() const { return layerTweaker; }
|
||||
@@ -305,6 +308,7 @@ protected:
|
||||
|
||||
std::size_t type = 0;
|
||||
std::optional<mbgl::Point<double>> origin;
|
||||
uint32_t uboIndex = 0;
|
||||
};
|
||||
|
||||
using DrawablePtr = std::shared_ptr<Drawable>;
|
||||
|
||||
@@ -1,114 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/shaders/shader_defines.hpp>
|
||||
#include <memory>
|
||||
#include <array>
|
||||
|
||||
namespace mbgl {
|
||||
namespace gfx {
|
||||
|
||||
class UniformBuffer;
|
||||
class UniformBlock;
|
||||
|
||||
using UniqueUniformBlock = std::unique_ptr<UniformBlock>;
|
||||
|
||||
/// @brief This class represents an uniform block
|
||||
class UniformBlock {
|
||||
public:
|
||||
/// @brief Constructor
|
||||
/// @param index_
|
||||
/// @param size_
|
||||
UniformBlock(int index_, std::size_t size_)
|
||||
: index(index_),
|
||||
size(size_) {}
|
||||
UniformBlock(const UniformBlock&) = default;
|
||||
UniformBlock(UniformBlock&& other)
|
||||
: index(other.index),
|
||||
size(other.size) {}
|
||||
/// @brief Destructor
|
||||
virtual ~UniformBlock() = default;
|
||||
|
||||
/// @brief Retrieves the index of this uniform block
|
||||
/// @return int
|
||||
int getIndex() const { return index; }
|
||||
|
||||
/// @brief Get the size of the uniform block
|
||||
/// @return std::size_t
|
||||
std::size_t getSize() const { return size; }
|
||||
|
||||
/// @brief Binds the buffer
|
||||
/// @param uniformBuffer
|
||||
virtual void bindBuffer(const UniformBuffer& uniformBuffer) = 0;
|
||||
|
||||
/// @brief Unbinds the uniform buffer
|
||||
virtual void unbindBuffer() = 0;
|
||||
|
||||
protected:
|
||||
UniformBlock& operator=(const UniformBlock&) = default;
|
||||
UniformBlock& operator=(UniformBlock&& other) {
|
||||
index = other.index;
|
||||
size = other.size;
|
||||
return *this;
|
||||
}
|
||||
|
||||
protected:
|
||||
int index;
|
||||
std::size_t size;
|
||||
};
|
||||
|
||||
/// Stores a collection of uniform blocks by id
|
||||
class UniformBlockArray {
|
||||
public:
|
||||
/// @brief Constructor
|
||||
UniformBlockArray() = default;
|
||||
|
||||
/// @brief Move constructor
|
||||
UniformBlockArray(UniformBlockArray&&);
|
||||
|
||||
/// @brief Copy constructor. Would need to use the virtual assignment operator
|
||||
UniformBlockArray(const UniformBlockArray&) = delete;
|
||||
|
||||
/// @brief Destructor
|
||||
virtual ~UniformBlockArray() = default;
|
||||
|
||||
/// @brief Number of maximum allocated elements
|
||||
std::size_t allocatedSize() const { return uniformBlockVector.size(); }
|
||||
|
||||
/// @brief Get an uniform block element.
|
||||
/// @return Pointer to the element on success, or null if the uniform block doesn't exists.
|
||||
const std::unique_ptr<UniformBlock>& get(const size_t id) const;
|
||||
|
||||
/// @brief Set a new uniform block element.
|
||||
/// @param id
|
||||
/// @param index
|
||||
/// @param size
|
||||
/// @return Pointer to the new element on success, or null if the uniform block already exists.
|
||||
const std::unique_ptr<UniformBlock>& set(const size_t id, const size_t index, std::size_t size);
|
||||
|
||||
/// @brief Move assignment operator
|
||||
UniformBlockArray& operator=(UniformBlockArray&&);
|
||||
|
||||
/// @brief Copy assignment operator
|
||||
UniformBlockArray& operator=(const UniformBlockArray&);
|
||||
|
||||
/// Do something with each block
|
||||
template <typename Func /* void(const UniformBlock&) */>
|
||||
void visit(Func f) {
|
||||
std::for_each(uniformBlockVector.begin(), uniformBlockVector.end(), [&](const auto& block) {
|
||||
if (block) {
|
||||
f(*block);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual std::unique_ptr<UniformBlock> create(int index, std::size_t size) = 0;
|
||||
virtual std::unique_ptr<UniformBlock> copy(const UniformBlock& uniformBlock) = 0;
|
||||
|
||||
protected:
|
||||
std::array<UniqueUniformBlock, shaders::maxUBOCountPerShader> uniformBlockVector;
|
||||
static std::unique_ptr<UniformBlock> nullref;
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mbgl
|
||||
@@ -29,7 +29,7 @@ protected:
|
||||
|
||||
public:
|
||||
virtual ~UniformBuffer() = default;
|
||||
virtual void update(const void* data, std::size_t size_) = 0;
|
||||
virtual void update(const void* data, std::size_t dataSize) = 0;
|
||||
|
||||
std::size_t getSize() const { return size; }
|
||||
|
||||
|
||||
@@ -68,9 +68,6 @@ private:
|
||||
|
||||
void uploadTextures() const;
|
||||
|
||||
void bindUniformBuffers() const;
|
||||
void unbindUniformBuffers() const;
|
||||
|
||||
void bindTextures() const;
|
||||
void unbindTextures() const;
|
||||
};
|
||||
|
||||
@@ -24,9 +24,6 @@ public:
|
||||
|
||||
gfx::UniformBufferArray& mutableUniformBuffers() override { return uniformBuffers; };
|
||||
|
||||
void bindUniformBuffers() const;
|
||||
void unbindUniformBuffers() const;
|
||||
|
||||
protected:
|
||||
UniformBufferArrayGL uniformBuffers;
|
||||
};
|
||||
@@ -46,9 +43,6 @@ public:
|
||||
|
||||
gfx::UniformBufferArray& mutableUniformBuffers() override { return uniformBuffers; };
|
||||
|
||||
void bindUniformBuffers() const;
|
||||
void unbindUniformBuffers() const;
|
||||
|
||||
protected:
|
||||
UniformBufferArrayGL uniformBuffers;
|
||||
};
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/gfx/uniform_block.hpp>
|
||||
#include <mbgl/gfx/uniform_buffer.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace gl {
|
||||
|
||||
class UniformBlockGL final : public gfx::UniformBlock {
|
||||
public:
|
||||
UniformBlockGL(int index_, std::size_t size_)
|
||||
: UniformBlock(index_, size_) {}
|
||||
UniformBlockGL(const UniformBlockGL& other)
|
||||
: UniformBlock(other) {}
|
||||
UniformBlockGL(UniformBlockGL&& other)
|
||||
: UniformBlock(std::move(other)) {}
|
||||
~UniformBlockGL() override = default;
|
||||
void bindBuffer(const gfx::UniformBuffer& uniformBuffer) override;
|
||||
void unbindBuffer() override;
|
||||
};
|
||||
|
||||
/// Stores a collection of uniform blocks by name
|
||||
class UniformBlockArrayGL final : public gfx::UniformBlockArray {
|
||||
public:
|
||||
UniformBlockArrayGL() = default;
|
||||
UniformBlockArrayGL(UniformBlockArrayGL&& other)
|
||||
: UniformBlockArray(std::move(other)) {}
|
||||
UniformBlockArrayGL(const UniformBlockArrayGL&) = delete;
|
||||
|
||||
UniformBlockArrayGL& operator=(UniformBlockArrayGL&& other) {
|
||||
UniformBlockArray::operator=(std::move(other));
|
||||
return *this;
|
||||
}
|
||||
UniformBlockArrayGL& operator=(const UniformBlockArrayGL& other) {
|
||||
UniformBlockArray::operator=(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<gfx::UniformBlock> create(int index, std::size_t size) override {
|
||||
return std::make_unique<UniformBlockGL>(index, size);
|
||||
}
|
||||
std::unique_ptr<gfx::UniformBlock> copy(const gfx::UniformBlock& uniformBlocks) override {
|
||||
return std::make_unique<UniformBlockGL>(static_cast<const UniformBlockGL&>(uniformBlocks));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace gl
|
||||
} // namespace mbgl
|
||||
@@ -24,7 +24,7 @@ public:
|
||||
UniformBufferGL clone() const { return {*this}; }
|
||||
|
||||
// gfx::UniformBuffer
|
||||
void update(const void* data, std::size_t size_) override;
|
||||
void update(const void* data, std::size_t dataSize) override;
|
||||
|
||||
private:
|
||||
// unique id used for debugging and profiling purposes
|
||||
@@ -59,6 +59,9 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
void bind() const;
|
||||
void unbind() const;
|
||||
|
||||
private:
|
||||
std::unique_ptr<gfx::UniformBuffer> copy(const gfx::UniformBuffer& uniformBuffers) override {
|
||||
return std::make_unique<UniformBufferGL>(static_cast<const UniformBufferGL&>(uniformBuffers).clone());
|
||||
|
||||
@@ -83,7 +83,10 @@ public:
|
||||
void reduceMemoryUsage() override {}
|
||||
|
||||
gfx::UniqueDrawableBuilder createDrawableBuilder(std::string name) override;
|
||||
gfx::UniformBufferPtr createUniformBuffer(const void* data, std::size_t size, bool persistent) override;
|
||||
gfx::UniformBufferPtr createUniformBuffer(const void* data,
|
||||
std::size_t size,
|
||||
bool persistent = false,
|
||||
bool ssbo = false) override;
|
||||
|
||||
gfx::ShaderProgramBasePtr getGenericShader(gfx::ShaderRegistry&, const std::string& name) override;
|
||||
|
||||
|
||||
@@ -73,9 +73,6 @@ protected:
|
||||
|
||||
void bindInstanceAttributes(RenderPass&) const noexcept;
|
||||
|
||||
void bindUniformBuffers(RenderPass&) const noexcept;
|
||||
void unbindUniformBuffers(RenderPass&) const noexcept {}
|
||||
|
||||
void bindTextures(RenderPass&) const noexcept;
|
||||
void unbindTextures(RenderPass&) const noexcept;
|
||||
|
||||
|
||||
@@ -26,9 +26,6 @@ public:
|
||||
|
||||
gfx::UniformBufferArray& mutableUniformBuffers() override { return uniformBuffers; };
|
||||
|
||||
void bindUniformBuffers(RenderPass&) const noexcept;
|
||||
void unbindUniformBuffers(RenderPass&) const noexcept {}
|
||||
|
||||
protected:
|
||||
UniformBufferArray uniformBuffers;
|
||||
};
|
||||
|
||||
@@ -45,8 +45,9 @@ public:
|
||||
void addDebugSignpost(const char* name) override;
|
||||
|
||||
void bindVertex(const BufferResource&, std::size_t offset, std::size_t index, std::size_t size = 0);
|
||||
|
||||
void unbindVertex(std::size_t index);
|
||||
void bindFragment(const BufferResource&, std::size_t offset, std::size_t index, std::size_t size = 0);
|
||||
void unbindFragment(std::size_t index);
|
||||
|
||||
private:
|
||||
void pushDebugGroup(const char* name) override;
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/gfx/uniform_block.hpp>
|
||||
#include <mbgl/gfx/uniform_buffer.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace mtl {
|
||||
|
||||
class UniformBlock final : public gfx::UniformBlock {
|
||||
public:
|
||||
UniformBlock(int index_, std::size_t size_)
|
||||
: gfx::UniformBlock(index_, size_) {}
|
||||
UniformBlock(const UniformBlock& other)
|
||||
: gfx::UniformBlock(other) {}
|
||||
UniformBlock(UniformBlock&& other)
|
||||
: gfx::UniformBlock(std::move(other)) {}
|
||||
~UniformBlock() override = default;
|
||||
void bindBuffer(const gfx::UniformBuffer& uniformBuffer) override;
|
||||
void unbindBuffer() override;
|
||||
|
||||
bool getBindVertex() const { return bindVertex; }
|
||||
void setBindVertex(bool value) { bindVertex = value; }
|
||||
|
||||
bool getBindFragment() const { return bindFragment; }
|
||||
void setBindFragment(bool value) { bindFragment = value; }
|
||||
|
||||
protected:
|
||||
bool bindVertex = false;
|
||||
bool bindFragment = false;
|
||||
};
|
||||
|
||||
/// Stores a collection of uniform blocks by name
|
||||
class UniformBlockArray final : public gfx::UniformBlockArray {
|
||||
public:
|
||||
UniformBlockArray() = default;
|
||||
UniformBlockArray(UniformBlockArray&& other)
|
||||
: gfx::UniformBlockArray(std::move(other)) {}
|
||||
UniformBlockArray(const UniformBlockArray&) = delete;
|
||||
|
||||
UniformBlockArray& operator=(UniformBlockArray&& other) {
|
||||
gfx::UniformBlockArray::operator=(std::move(other));
|
||||
return *this;
|
||||
}
|
||||
UniformBlockArray& operator=(const UniformBlockArray& other) {
|
||||
gfx::UniformBlockArray::operator=(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<gfx::UniformBlock> create(int index, std::size_t size) override {
|
||||
return std::make_unique<UniformBlock>(index, size);
|
||||
}
|
||||
std::unique_ptr<gfx::UniformBlock> copy(const gfx::UniformBlock& uniformBlocks) override {
|
||||
return std::make_unique<UniformBlock>(static_cast<const UniformBlock&>(uniformBlocks));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace mtl
|
||||
} // namespace mbgl
|
||||
@@ -6,6 +6,8 @@
|
||||
namespace mbgl {
|
||||
namespace mtl {
|
||||
|
||||
class RenderPass;
|
||||
|
||||
class UniformBuffer final : public gfx::UniformBuffer {
|
||||
public:
|
||||
UniformBuffer(BufferResource&&);
|
||||
@@ -17,7 +19,7 @@ public:
|
||||
|
||||
UniformBuffer clone() const { return {buffer.clone()}; }
|
||||
|
||||
void update(const void* data, std::size_t size_) override;
|
||||
void update(const void* data, std::size_t dataSize) override;
|
||||
|
||||
protected:
|
||||
BufferResource buffer;
|
||||
@@ -40,6 +42,9 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
void bind(RenderPass& renderPass) const noexcept;
|
||||
void unbind(RenderPass& renderPass) const noexcept {};
|
||||
|
||||
private:
|
||||
gfx::UniqueUniformBuffer copy(const gfx::UniformBuffer& buffer) override {
|
||||
return std::make_unique<UniformBuffer>(static_cast<const UniformBuffer&>(buffer).clone());
|
||||
|
||||
@@ -11,31 +11,39 @@ namespace shaders {
|
||||
// Background
|
||||
|
||||
struct alignas(16) BackgroundDrawableUBO {
|
||||
std::array<float, 4 * 4> matrix;
|
||||
/* 0 */ std::array<float, 4 * 4> matrix;
|
||||
/* 64 */
|
||||
};
|
||||
static_assert(sizeof(BackgroundDrawableUBO) == 64);
|
||||
static_assert(sizeof(BackgroundDrawableUBO) == 4 * 16);
|
||||
|
||||
struct alignas(16) BackgroundLayerUBO {
|
||||
/// Evaluated properties that do not depend on the tile
|
||||
struct alignas(16) BackgroundPropsUBO {
|
||||
/* 0 */ Color color;
|
||||
/* 16 */ float opacity;
|
||||
/* 24 */ float pad1, pad2, pad3;
|
||||
/* 20 */ float pad1;
|
||||
/* 24 */ float pad2;
|
||||
/* 28 */ float pad3;
|
||||
/* 32 */
|
||||
};
|
||||
static_assert(sizeof(BackgroundLayerUBO) == 32);
|
||||
static_assert(sizeof(BackgroundPropsUBO) == 2 * 16);
|
||||
|
||||
//
|
||||
// Background pattern
|
||||
|
||||
struct alignas(16) BackgroundPatternDrawableUBO {
|
||||
std::array<float, 4 * 4> matrix;
|
||||
std::array<float, 2> pixel_coord_upper;
|
||||
std::array<float, 2> pixel_coord_lower;
|
||||
float tile_units_to_pixels;
|
||||
float pad1, pad2, pad3;
|
||||
/* 0 */ std::array<float, 4 * 4> matrix;
|
||||
/* 64 */ std::array<float, 2> pixel_coord_upper;
|
||||
/* 72 */ std::array<float, 2> pixel_coord_lower;
|
||||
/* 80 */ float tile_units_to_pixels;
|
||||
/* 84 */ float pad1;
|
||||
/* 88 */ float pad2;
|
||||
/* 92 */ float pad3;
|
||||
/* 96 */
|
||||
};
|
||||
static_assert(sizeof(BackgroundPatternDrawableUBO) == 96);
|
||||
static_assert(sizeof(BackgroundPatternDrawableUBO) == 6 * 16);
|
||||
|
||||
struct alignas(16) BackgroundPatternLayerUBO {
|
||||
/// Evaluated properties that do not depend on the tile
|
||||
struct alignas(16) BackgroundPatternPropsUBO {
|
||||
/* 0 */ std::array<float, 2> pattern_tl_a;
|
||||
/* 8 */ std::array<float, 2> pattern_br_a;
|
||||
/* 16 */ std::array<float, 2> pattern_tl_b;
|
||||
@@ -48,7 +56,16 @@ struct alignas(16) BackgroundPatternLayerUBO {
|
||||
/* 60 */ float opacity;
|
||||
/* 64 */
|
||||
};
|
||||
static_assert(sizeof(BackgroundPatternLayerUBO) == 64);
|
||||
static_assert(sizeof(BackgroundPatternPropsUBO) == 4 * 16);
|
||||
|
||||
#if MLN_UBO_CONSOLIDATION
|
||||
|
||||
union BackgroundDrawableUnionUBO {
|
||||
BackgroundDrawableUBO backgroundDrawableUBO;
|
||||
BackgroundPatternDrawableUBO backgroundPatternDrawableUBO;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace shaders
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -6,45 +6,39 @@ namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
struct alignas(16) CircleDrawableUBO {
|
||||
/* 0 */ std::array<float, 4 * 4> matrix; // composite model-view-projection matrix
|
||||
/* 64 */ std::array<float, 2> extrude_scale;
|
||||
/* 72 */ float pad;
|
||||
/* 80 */
|
||||
};
|
||||
static_assert(sizeof(CircleDrawableUBO) == 5 * 16);
|
||||
/* 0 */ std::array<float, 4 * 4> matrix;
|
||||
/* 64 */ std::array<float, 2> extrude_scale;
|
||||
|
||||
struct alignas(16) CirclePaintParamsUBO {
|
||||
/* 0 */ float camera_to_center_distance;
|
||||
/* 4 */ float pad1, pad2, pad3;
|
||||
/* 16 */
|
||||
// Interpolations
|
||||
/* 72 */ float color_t;
|
||||
/* 76 */ float radius_t;
|
||||
/* 80 */ float blur_t;
|
||||
/* 84 */ float opacity_t;
|
||||
/* 88 */ float stroke_color_t;
|
||||
/* 92 */ float stroke_width_t;
|
||||
/* 96 */ float stroke_opacity_t;
|
||||
/* 100 */ float pad1;
|
||||
/* 104 */ float pad2;
|
||||
/* 108 */ float pad3;
|
||||
/* 112 */
|
||||
};
|
||||
static_assert(sizeof(CirclePaintParamsUBO) == 1 * 16);
|
||||
static_assert(sizeof(CircleDrawableUBO) == 7 * 16);
|
||||
|
||||
/// Evaluated properties that do not depend on the tile
|
||||
struct alignas(16) CircleEvaluatedPropsUBO {
|
||||
Color color;
|
||||
Color stroke_color;
|
||||
float radius;
|
||||
float blur;
|
||||
float opacity;
|
||||
float stroke_width;
|
||||
float stroke_opacity;
|
||||
int scale_with_map;
|
||||
int pitch_with_map;
|
||||
float padding;
|
||||
/* 0 */ Color color;
|
||||
/* 16 */ Color stroke_color;
|
||||
/* 32 */ float radius;
|
||||
/* 36 */ float blur;
|
||||
/* 40 */ float opacity;
|
||||
/* 44 */ float stroke_width;
|
||||
/* 48 */ float stroke_opacity;
|
||||
/* 52 */ int scale_with_map;
|
||||
/* 56 */ int pitch_with_map;
|
||||
/* 60 */ float pad1;
|
||||
/* 64 */
|
||||
};
|
||||
static_assert(sizeof(CircleEvaluatedPropsUBO) % 16 == 0);
|
||||
|
||||
struct alignas(16) CircleInterpolateUBO {
|
||||
float color_t;
|
||||
float radius_t;
|
||||
float blur_t;
|
||||
float opacity_t;
|
||||
float stroke_color_t;
|
||||
float stroke_width_t;
|
||||
float stroke_opacity_t;
|
||||
float padding;
|
||||
};
|
||||
static_assert(sizeof(CircleInterpolateUBO) % 16 == 0);
|
||||
static_assert(sizeof(CircleEvaluatedPropsUBO) == 4 * 16);
|
||||
|
||||
} // namespace shaders
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -5,14 +5,19 @@
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
struct alignas(16) CollisionUBO {
|
||||
std::array<float, 4 * 4> matrix;
|
||||
std::array<float, 2> extrude_scale;
|
||||
float overscale_factor;
|
||||
float pad;
|
||||
struct alignas(16) CollisionDrawableUBO {
|
||||
/* 0 */ std::array<float, 4 * 4> matrix;
|
||||
/* 64 */
|
||||
};
|
||||
static_assert(sizeof(CollisionUBO) % 16 == 0);
|
||||
static_assert(sizeof(CollisionUBO) == 80);
|
||||
static_assert(sizeof(CollisionDrawableUBO) == 4 * 16);
|
||||
|
||||
struct alignas(16) CollisionTilePropsUBO {
|
||||
/* 0 */ std::array<float, 2> extrude_scale;
|
||||
/* 8 */ float overscale_factor;
|
||||
/* 12 */ float pad1;
|
||||
/* 16 */
|
||||
};
|
||||
static_assert(sizeof(CollisionTilePropsUBO) == 16);
|
||||
|
||||
} // namespace shaders
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/shaders/layer_ubo.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
struct alignas(16) CommonUBO {
|
||||
std::array<float, 4 * 4> matrix;
|
||||
Color color;
|
||||
};
|
||||
static_assert(sizeof(CommonUBO) % 16 == 0);
|
||||
|
||||
} // namespace shaders
|
||||
} // namespace mbgl
|
||||
@@ -5,26 +5,21 @@
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
/// Custom Symbol Icon matrix
|
||||
struct alignas(16) CustomSymbolIconDrawableUBO {
|
||||
/* 0 */ std::array<float, 4 * 4> matrix;
|
||||
/* 64 */
|
||||
/* 64 */ std::array<float, 2> extrude_scale;
|
||||
/* 72 */ std::array<float, 2> anchor;
|
||||
/* 80 */ float angle_degrees;
|
||||
/* 84 */ uint32_t scale_with_map;
|
||||
/* 88 */ uint32_t pitch_with_map;
|
||||
/* 92 */ float camera_to_center_distance;
|
||||
/* 96 */ float aspect_ratio;
|
||||
/* 100 */ float pad1;
|
||||
/* 104 */ float pad2;
|
||||
/* 108 */ float pad3;
|
||||
/* 112 */
|
||||
};
|
||||
static_assert(sizeof(CustomSymbolIconDrawableUBO) == 4 * 16);
|
||||
|
||||
/// Custom Symbol Icon Parameters
|
||||
struct alignas(16) CustomSymbolIconParametersUBO {
|
||||
/* 0 */ std::array<float, 2> extrude_scale;
|
||||
/* 8 */ std::array<float, 2> anchor;
|
||||
/* 16 */ float angle_degrees;
|
||||
/* 20 */ uint32_t scale_with_map;
|
||||
/* 24 */ uint32_t pitch_with_map;
|
||||
/* 28 */ float camera_to_center_distance;
|
||||
/* 32 */ float aspect_ratio;
|
||||
/* 36 */ float pad0, pad1, pad2;
|
||||
/* 48 */
|
||||
};
|
||||
static_assert(sizeof(CustomSymbolIconParametersUBO) == 3 * 16);
|
||||
static_assert(sizeof(CustomSymbolIconDrawableUBO) == 7 * 16);
|
||||
|
||||
} // namespace shaders
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -6,12 +6,15 @@ namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
struct alignas(16) DebugUBO {
|
||||
std::array<float, 4 * 4> matrix;
|
||||
Color color;
|
||||
float overlay_scale;
|
||||
float pad1, pad2, pad3;
|
||||
/* 0 */ std::array<float, 4 * 4> matrix;
|
||||
/* 64 */ Color color;
|
||||
/* 80 */ float overlay_scale;
|
||||
/* 84 */ float pad1;
|
||||
/* 88 */ float pad2;
|
||||
/* 92 */ float pad3;
|
||||
/* 96 */
|
||||
};
|
||||
static_assert(sizeof(DebugUBO) % 16 == 0);
|
||||
static_assert(sizeof(DebugUBO) == 6 * 16);
|
||||
|
||||
} // namespace shaders
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -8,15 +8,32 @@ namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
struct alignas(16) FillExtrusionDrawableUBO {
|
||||
/* 0 */ std::array<float, 4 * 4> matrix;
|
||||
/* 64 */ std::array<float, 2> texsize;
|
||||
/* 72 */ std::array<float, 2> pixel_coord_upper;
|
||||
/* 80 */ std::array<float, 2> pixel_coord_lower;
|
||||
/* 88 */ float height_factor;
|
||||
/* 92 */ float tile_ratio;
|
||||
/* 96 */
|
||||
/* 0 */ std::array<float, 4 * 4> matrix;
|
||||
/* 64 */ std::array<float, 2> pixel_coord_upper;
|
||||
/* 72 */ std::array<float, 2> pixel_coord_lower;
|
||||
/* 80 */ float height_factor;
|
||||
/* 84 */ float tile_ratio;
|
||||
|
||||
// Interpolations
|
||||
/* 88 */ float base_t;
|
||||
/* 92 */ float height_t;
|
||||
/* 96 */ float color_t;
|
||||
/* 100 */ float pattern_from_t;
|
||||
/* 104 */ float pattern_to_t;
|
||||
/* 108 */ float pad1;
|
||||
/* 112 */
|
||||
};
|
||||
static_assert(sizeof(FillExtrusionDrawableUBO) == 6 * 16);
|
||||
static_assert(sizeof(FillExtrusionDrawableUBO) == 7 * 16);
|
||||
|
||||
struct alignas(16) FillExtrusionTilePropsUBO {
|
||||
/* 0 */ std::array<float, 4> pattern_from;
|
||||
/* 16 */ std::array<float, 4> pattern_to;
|
||||
/* 32 */ std::array<float, 2> texsize;
|
||||
/* 40 */ float pad1;
|
||||
/* 44 */ float pad2;
|
||||
/* 48 */
|
||||
};
|
||||
static_assert(sizeof(FillExtrusionTilePropsUBO) == 3 * 16);
|
||||
|
||||
/// Evaluated properties that do not depend on the tile
|
||||
struct alignas(16) FillExtrusionPropsUBO {
|
||||
@@ -37,25 +54,5 @@ struct alignas(16) FillExtrusionPropsUBO {
|
||||
};
|
||||
static_assert(sizeof(FillExtrusionPropsUBO) == 5 * 16);
|
||||
|
||||
/// Evaluated properties that depend on the tile
|
||||
struct alignas(16) FillExtrusionTilePropsUBO {
|
||||
/* 0 */ std::array<float, 4> pattern_from;
|
||||
/* 16 */ std::array<float, 4> pattern_to;
|
||||
/* 32 */
|
||||
};
|
||||
static_assert(sizeof(FillExtrusionTilePropsUBO) == 2 * 16);
|
||||
|
||||
/// Attribute interpolations
|
||||
struct alignas(16) FillExtrusionInterpolateUBO {
|
||||
/* 0 */ float base_t;
|
||||
/* 4 */ float height_t;
|
||||
/* 8 */ float color_t;
|
||||
/* 12 */ float pattern_from_t;
|
||||
/* 16 */ float pattern_to_t;
|
||||
/* 20 */ float pad1, pad2, pad3;
|
||||
/* 32 */
|
||||
};
|
||||
static_assert(sizeof(FillExtrusionInterpolateUBO) == 2 * 16);
|
||||
|
||||
} // namespace shaders
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -9,112 +9,127 @@ namespace shaders {
|
||||
// Fill
|
||||
|
||||
struct alignas(16) FillDrawableUBO {
|
||||
/* 0 */ std::array<float, 4 * 4> matrix; // composite model-view-projection matrix
|
||||
/* 64 */
|
||||
};
|
||||
static_assert(sizeof(FillDrawableUBO) == 4 * 16);
|
||||
/* 0 */ std::array<float, 4 * 4> matrix;
|
||||
|
||||
struct alignas(16) FillInterpolateUBO {
|
||||
float color_t;
|
||||
float opacity_t;
|
||||
float pad1, pad2;
|
||||
// Interpolations
|
||||
/* 64 */ float color_t;
|
||||
/* 68 */ float opacity_t;
|
||||
/* 72 */ float pad1;
|
||||
/* 76 */ float pad2;
|
||||
/* 80 */
|
||||
};
|
||||
static_assert(sizeof(FillInterpolateUBO) % 16 == 0);
|
||||
static_assert(sizeof(FillDrawableUBO) == 5 * 16);
|
||||
|
||||
//
|
||||
// Fill outline
|
||||
|
||||
struct alignas(16) FillOutlineDrawableUBO {
|
||||
/* 0 */ std::array<float, 4 * 4> matrix; // composite model-view-projection matrix
|
||||
/* 64 */
|
||||
};
|
||||
static_assert(sizeof(FillOutlineDrawableUBO) == 4 * 16);
|
||||
/* 0 */ std::array<float, 4 * 4> matrix;
|
||||
|
||||
struct alignas(16) FillOutlineInterpolateUBO {
|
||||
float outline_color_t;
|
||||
float opacity_t;
|
||||
float pad1, pad2;
|
||||
// Interpolations
|
||||
/* 64 */ float outline_color_t;
|
||||
/* 68 */ float opacity_t;
|
||||
/* 72 */ float pad1;
|
||||
/* 76 */ float pad2;
|
||||
/* 80 */
|
||||
};
|
||||
static_assert(sizeof(FillOutlineInterpolateUBO) == 1 * 16);
|
||||
static_assert(sizeof(FillOutlineDrawableUBO) == 5 * 16);
|
||||
|
||||
//
|
||||
// Fill Pattern
|
||||
// Fill pattern
|
||||
|
||||
struct alignas(16) FillPatternDrawableUBO {
|
||||
/* 0 */ std::array<float, 4 * 4> matrix; // composite model-view-projection matrix
|
||||
/* 0 */ std::array<float, 4 * 4> matrix;
|
||||
/* 64 */ std::array<float, 2> pixel_coord_upper;
|
||||
/* 72 */ std::array<float, 2> pixel_coord_lower;
|
||||
/* 80 */ std::array<float, 2> texsize;
|
||||
/* 88 */ float tile_ratio;
|
||||
/* 92 */ float pad;
|
||||
/* 80 */ float tile_ratio;
|
||||
|
||||
// Interpolations
|
||||
/* 84 */ float pattern_from_t;
|
||||
/* 88 */ float pattern_to_t;
|
||||
/* 92 */ float opacity_t;
|
||||
/* 96 */
|
||||
};
|
||||
static_assert(sizeof(FillPatternDrawableUBO) == 6 * 16);
|
||||
|
||||
struct alignas(16) FillPatternTilePropsUBO {
|
||||
std::array<float, 4> pattern_from;
|
||||
std::array<float, 4> pattern_to;
|
||||
/* 0 */ std::array<float, 4> pattern_from;
|
||||
/* 16 */ std::array<float, 4> pattern_to;
|
||||
/* 32 */ std::array<float, 2> texsize;
|
||||
/* 40 */ float pad1;
|
||||
/* 44 */ float pad2;
|
||||
/* 48 */
|
||||
};
|
||||
static_assert(sizeof(FillPatternTilePropsUBO) == 2 * 16);
|
||||
|
||||
struct alignas(16) FillPatternInterpolateUBO {
|
||||
float pattern_from_t;
|
||||
float pattern_to_t;
|
||||
float opacity_t;
|
||||
float pad1;
|
||||
};
|
||||
static_assert(sizeof(FillPatternInterpolateUBO) == 1 * 16);
|
||||
static_assert(sizeof(FillPatternTilePropsUBO) == 3 * 16);
|
||||
|
||||
//
|
||||
// Fill pattern outline
|
||||
|
||||
struct alignas(16) FillOutlinePatternDrawableUBO {
|
||||
/* 0 */ std::array<float, 4 * 4> matrix; // composite model-view-projection matrix
|
||||
/* 64 */ std::array<float, 2> pixel_coord_upper;
|
||||
/* 72 */ std::array<float, 2> pixel_coord_lower;
|
||||
/* 80 */ std::array<float, 2> texsize;
|
||||
/* 88 */ float tile_ratio;
|
||||
/* 92 */ float pad;
|
||||
/* 96 */
|
||||
/* 0 */ std::array<float, 4 * 4> matrix;
|
||||
/* 64 */ std::array<float, 2> pixel_coord_upper;
|
||||
/* 72 */ std::array<float, 2> pixel_coord_lower;
|
||||
/* 80 */ float tile_ratio;
|
||||
|
||||
// Interpolations
|
||||
/* 84 */ float pattern_from_t;
|
||||
/* 88 */ float pattern_to_t;
|
||||
/* 92 */ float opacity_t;
|
||||
/* 96 */
|
||||
};
|
||||
static_assert(sizeof(FillOutlinePatternDrawableUBO) == 6 * 16);
|
||||
|
||||
struct alignas(16) FillOutlinePatternTilePropsUBO {
|
||||
std::array<float, 4> pattern_from;
|
||||
std::array<float, 4> pattern_to;
|
||||
/* 0 */ std::array<float, 4> pattern_from;
|
||||
/* 16 */ std::array<float, 4> pattern_to;
|
||||
/* 32 */ std::array<float, 2> texsize;
|
||||
/* 40 */ float pad1;
|
||||
/* 44 */ float pad2;
|
||||
/* 48 */
|
||||
};
|
||||
static_assert(sizeof(FillOutlinePatternTilePropsUBO) == 2 * 16);
|
||||
|
||||
struct alignas(16) FillOutlinePatternInterpolateUBO {
|
||||
float pattern_from_t;
|
||||
float pattern_to_t;
|
||||
float opacity_t;
|
||||
float pad;
|
||||
};
|
||||
static_assert(sizeof(FillOutlinePatternInterpolateUBO) == 1 * 16);
|
||||
static_assert(sizeof(FillOutlinePatternTilePropsUBO) == 3 * 16);
|
||||
|
||||
//
|
||||
// Fill outline triangulated
|
||||
|
||||
struct alignas(16) FillOutlineTriangulatedDrawableUBO {
|
||||
std::array<float, 4 * 4> matrix;
|
||||
float ratio;
|
||||
float pad1, pad2, pad3;
|
||||
/* 0 */ std::array<float, 4 * 4> matrix;
|
||||
/* 64 */ float ratio;
|
||||
/* 68 */ float pad1;
|
||||
/* 72 */ float pad2;
|
||||
/* 76 */ float pad3;
|
||||
/* 80 */
|
||||
};
|
||||
static_assert(sizeof(FillOutlineTriangulatedDrawableUBO) % 16 == 0);
|
||||
|
||||
//
|
||||
// Fill evaluated properties
|
||||
static_assert(sizeof(FillOutlineTriangulatedDrawableUBO) == 5 * 16);
|
||||
|
||||
/// Evaluated properties that do not depend on the tile
|
||||
struct alignas(16) FillEvaluatedPropsUBO {
|
||||
Color color;
|
||||
Color outline_color;
|
||||
float opacity;
|
||||
float fade;
|
||||
float from_scale;
|
||||
float to_scale;
|
||||
/* 0 */ Color color;
|
||||
/* 16 */ Color outline_color;
|
||||
/* 32 */ float opacity;
|
||||
/* 36 */ float fade;
|
||||
/* 40 */ float from_scale;
|
||||
/* 44 */ float to_scale;
|
||||
/* 48 */
|
||||
};
|
||||
static_assert(sizeof(FillEvaluatedPropsUBO) == 3 * 16);
|
||||
|
||||
#if MLN_UBO_CONSOLIDATION
|
||||
|
||||
union FillDrawableUnionUBO {
|
||||
FillDrawableUBO fillDrawableUBO;
|
||||
FillOutlineDrawableUBO fillOutlineDrawableUBO;
|
||||
FillPatternDrawableUBO fillPatternDrawableUBO;
|
||||
FillOutlinePatternDrawableUBO fillOutlinePatternDrawableUBO;
|
||||
FillOutlineTriangulatedDrawableUBO fillOutlineTriangulatedDrawableUBO;
|
||||
};
|
||||
|
||||
union FillTilePropsUnionUBO {
|
||||
FillPatternTilePropsUBO fillPatternTilePropsUBO;
|
||||
FillOutlinePatternTilePropsUBO fillOutlinePatternTilePropsUBO;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace shaders
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -17,10 +17,12 @@ void main() {
|
||||
gl_Position = u_matrix * vec4(a_pos, 0, 1);
|
||||
}
|
||||
)";
|
||||
static constexpr const char* fragment = R"(layout (std140) uniform BackgroundLayerUBO {
|
||||
static constexpr const char* fragment = R"(layout (std140) uniform BackgroundPropsUBO {
|
||||
highp vec4 u_color;
|
||||
highp float u_opacity;
|
||||
highp float layer_pad1, layer_pad2, layer_pad3;
|
||||
lowp float props_pad1;
|
||||
lowp float props_pad2;
|
||||
lowp float props_pad3;
|
||||
};
|
||||
|
||||
void main() {
|
||||
|
||||
@@ -13,9 +13,12 @@ struct ShaderSource<BuiltIn::BackgroundPatternShader, gfx::Backend::Type::OpenGL
|
||||
highp vec2 u_pixel_coord_upper;
|
||||
highp vec2 u_pixel_coord_lower;
|
||||
highp float u_tile_units_to_pixels;
|
||||
highp float drawable_pad1, drawable_pad2, drawable_pad3;
|
||||
lowp float drawable_pad1;
|
||||
lowp float drawable_pad2;
|
||||
lowp float drawable_pad3;
|
||||
};
|
||||
layout (std140) uniform BackgroundPatternLayerUBO {
|
||||
|
||||
layout (std140) uniform BackgroundPatternPropsUBO {
|
||||
highp vec2 u_pattern_tl_a;
|
||||
highp vec2 u_pattern_br_a;
|
||||
highp vec2 u_pattern_tl_b;
|
||||
@@ -47,10 +50,11 @@ void main() {
|
||||
highp float u_symbol_fade_change;
|
||||
highp float u_aspect_ratio;
|
||||
highp float u_pixel_ratio;
|
||||
highp float global_pad1, global_pad2;
|
||||
highp float u_map_zoom;
|
||||
lowp float global_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform BackgroundPatternLayerUBO {
|
||||
layout (std140) uniform BackgroundPatternPropsUBO {
|
||||
highp vec2 u_pattern_tl_a;
|
||||
highp vec2 u_pattern_br_a;
|
||||
highp vec2 u_pattern_tl_b;
|
||||
|
||||
@@ -19,13 +19,24 @@ layout (std140) uniform GlobalPaintParamsUBO {
|
||||
highp float u_symbol_fade_change;
|
||||
highp float u_aspect_ratio;
|
||||
highp float u_pixel_ratio;
|
||||
highp float global_pad1, global_pad2;
|
||||
highp float u_map_zoom;
|
||||
lowp float global_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform CircleDrawableUBO {
|
||||
highp mat4 u_matrix;
|
||||
highp vec2 u_extrude_scale;
|
||||
lowp vec2 drawable_pad1;
|
||||
// Interpolations
|
||||
lowp float u_color_t;
|
||||
lowp float u_radius_t;
|
||||
lowp float u_blur_t;
|
||||
lowp float u_opacity_t;
|
||||
lowp float u_stroke_color_t;
|
||||
lowp float u_stroke_width_t;
|
||||
lowp float u_stroke_opacity_t;
|
||||
lowp float drawable_pad1;
|
||||
lowp float drawable_pad2;
|
||||
lowp float drawable_pad3;
|
||||
};
|
||||
|
||||
layout (std140) uniform CircleEvaluatedPropsUBO {
|
||||
@@ -41,17 +52,6 @@ layout (std140) uniform CircleEvaluatedPropsUBO {
|
||||
lowp float props_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform CircleInterpolateUBO {
|
||||
lowp float u_color_t;
|
||||
lowp float u_radius_t;
|
||||
lowp float u_blur_t;
|
||||
lowp float u_opacity_t;
|
||||
lowp float u_stroke_color_t;
|
||||
lowp float u_stroke_width_t;
|
||||
lowp float u_stroke_opacity_t;
|
||||
lowp float interp_pad1;
|
||||
};
|
||||
|
||||
#ifndef HAS_UNIFORM_u_color
|
||||
layout (location = 1) in highp vec4 a_color;
|
||||
out highp vec4 color;
|
||||
|
||||
@@ -22,14 +22,18 @@ layout (std140) uniform GlobalPaintParamsUBO {
|
||||
highp float u_symbol_fade_change;
|
||||
highp float u_aspect_ratio;
|
||||
highp float u_pixel_ratio;
|
||||
highp float global_pad1, global_pad2;
|
||||
highp float u_map_zoom;
|
||||
lowp float global_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform CollisionUBO {
|
||||
layout (std140) uniform CollisionDrawableUBO {
|
||||
highp mat4 u_matrix;
|
||||
};
|
||||
|
||||
layout (std140) uniform CollisionTilePropsUBO {
|
||||
highp vec2 u_extrude_scale;
|
||||
highp float u_overscale_factor;
|
||||
highp float pad1;
|
||||
lowp float drawable_pad1;
|
||||
};
|
||||
|
||||
out float v_placed;
|
||||
@@ -50,14 +54,7 @@ void main() {
|
||||
v_notUsed = a_placed.y;
|
||||
}
|
||||
)";
|
||||
static constexpr const char* fragment = R"(layout (std140) uniform CollisionUBO {
|
||||
highp mat4 u_matrix;
|
||||
highp vec2 u_extrude_scale;
|
||||
highp float u_overscale_factor;
|
||||
highp float pad1;
|
||||
};
|
||||
|
||||
in float v_placed;
|
||||
static constexpr const char* fragment = R"(in float v_placed;
|
||||
in float v_notUsed;
|
||||
|
||||
void main() {
|
||||
|
||||
@@ -21,14 +21,18 @@ layout (std140) uniform GlobalPaintParamsUBO {
|
||||
highp float u_symbol_fade_change;
|
||||
highp float u_aspect_ratio;
|
||||
highp float u_pixel_ratio;
|
||||
highp float global_pad1, global_pad2;
|
||||
highp float u_map_zoom;
|
||||
lowp float global_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform CollisionUBO {
|
||||
layout (std140) uniform CollisionDrawableUBO {
|
||||
highp mat4 u_matrix;
|
||||
};
|
||||
|
||||
layout (std140) uniform CollisionTilePropsUBO {
|
||||
highp vec2 u_extrude_scale;
|
||||
highp float u_overscale_factor;
|
||||
highp float pad1;
|
||||
lowp float drawable_pad1;
|
||||
};
|
||||
|
||||
out float v_placed;
|
||||
@@ -66,14 +70,14 @@ void main() {
|
||||
highp float u_symbol_fade_change;
|
||||
highp float u_aspect_ratio;
|
||||
highp float u_pixel_ratio;
|
||||
highp float global_pad1, global_pad2;
|
||||
highp float u_map_zoom;
|
||||
lowp float global_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform CollisionUBO {
|
||||
highp mat4 u_matrix;
|
||||
layout (std140) uniform CollisionTilePropsUBO {
|
||||
highp vec2 u_extrude_scale;
|
||||
highp float u_overscale_factor;
|
||||
highp float pad1;
|
||||
lowp float drawable_pad1;
|
||||
};
|
||||
|
||||
in float v_placed;
|
||||
|
||||
@@ -13,9 +13,6 @@ layout(location = 1) in vec2 a_tex;
|
||||
|
||||
layout(std140) uniform CustomSymbolIconDrawableUBO {
|
||||
highp mat4 u_matrix;
|
||||
};
|
||||
|
||||
layout(std140) uniform CustomSymbolIconParametersUBO {
|
||||
highp vec2 u_extrude_scale;
|
||||
highp vec2 u_anchor;
|
||||
highp float u_angle_degrees;
|
||||
@@ -23,7 +20,9 @@ layout(std140) uniform CustomSymbolIconParametersUBO {
|
||||
bool u_pitch_with_map;
|
||||
highp float u_camera_to_center_distance;
|
||||
highp float u_aspect_ratio;
|
||||
highp float params_pad1, params_pad2, params_pad3;
|
||||
lowp float drawable_pad1;
|
||||
lowp float drawable_pad2;
|
||||
lowp float drawable_pad3;
|
||||
};
|
||||
|
||||
out vec2 v_tex;
|
||||
|
||||
@@ -15,9 +15,9 @@ layout (std140) uniform DebugUBO {
|
||||
highp mat4 u_matrix;
|
||||
highp vec4 u_color;
|
||||
highp float u_overlay_scale;
|
||||
highp float pad1;
|
||||
highp float pad2;
|
||||
highp float pad3;
|
||||
lowp float pad1;
|
||||
lowp float pad2;
|
||||
lowp float pad3;
|
||||
};
|
||||
|
||||
void main() {
|
||||
@@ -31,9 +31,9 @@ void main() {
|
||||
highp mat4 u_matrix;
|
||||
highp vec4 u_color;
|
||||
highp float u_overlay_scale;
|
||||
highp float pad1;
|
||||
highp float pad2;
|
||||
highp float pad3;
|
||||
lowp float pad1;
|
||||
lowp float pad2;
|
||||
lowp float pad3;
|
||||
};
|
||||
|
||||
uniform sampler2D u_overlay;
|
||||
|
||||
@@ -10,12 +10,13 @@ struct ShaderSource<BuiltIn::FillShader, gfx::Backend::Type::OpenGL> {
|
||||
static constexpr const char* name = "FillShader";
|
||||
static constexpr const char* vertex = R"(layout (std140) uniform FillDrawableUBO {
|
||||
highp mat4 u_matrix;
|
||||
};
|
||||
layout (std140) uniform FillInterpolateUBO {
|
||||
// Interpolations
|
||||
highp float u_color_t;
|
||||
highp float u_opacity_t;
|
||||
highp float interp_pad1, interp_pad2;
|
||||
lowp float drawable_pad1;
|
||||
lowp float drawable_pad2;
|
||||
};
|
||||
|
||||
layout (std140) uniform FillEvaluatedPropsUBO {
|
||||
highp vec4 u_color;
|
||||
highp vec4 u_outline_color;
|
||||
@@ -51,12 +52,7 @@ lowp float opacity = u_opacity;
|
||||
gl_Position = u_matrix * vec4(a_pos, 0, 1);
|
||||
}
|
||||
)";
|
||||
static constexpr const char* fragment = R"(layout (std140) uniform FillInterpolateUBO {
|
||||
highp float u_color_t;
|
||||
highp float u_opacity_t;
|
||||
highp float interp_pad1, interp_pad2;
|
||||
};
|
||||
layout (std140) uniform FillEvaluatedPropsUBO {
|
||||
static constexpr const char* fragment = R"(layout (std140) uniform FillEvaluatedPropsUBO {
|
||||
highp vec4 u_color;
|
||||
highp vec4 u_outline_color;
|
||||
highp float u_opacity;
|
||||
|
||||
@@ -14,16 +14,31 @@ out vec4 v_color;
|
||||
|
||||
layout (std140) uniform FillExtrusionDrawableUBO {
|
||||
highp mat4 u_matrix;
|
||||
highp vec2 u_texsize;
|
||||
highp vec2 u_pixel_coord_upper;
|
||||
highp vec2 u_pixel_coord_lower;
|
||||
highp float u_height_factor;
|
||||
highp float u_tile_ratio;
|
||||
// Interpolations
|
||||
highp float u_base_t;
|
||||
highp float u_height_t;
|
||||
highp float u_color_t;
|
||||
highp float u_pattern_from_t;
|
||||
highp float u_pattern_to_t;
|
||||
lowp float drawable_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform FillExtrusionTilePropsUBO {
|
||||
highp vec4 u_pattern_from;
|
||||
highp vec4 u_pattern_to;
|
||||
highp vec2 u_texsize;
|
||||
lowp float tileprops_pad1;
|
||||
lowp float tileprops_pad2;
|
||||
};
|
||||
|
||||
layout (std140) uniform FillExtrusionPropsUBO {
|
||||
highp vec4 u_color;
|
||||
highp vec3 u_lightcolor;
|
||||
highp float props_pad1;
|
||||
lowp float props_pad1;
|
||||
highp vec3 u_lightpos;
|
||||
highp float u_base;
|
||||
highp float u_height;
|
||||
@@ -33,20 +48,9 @@ layout (std140) uniform FillExtrusionPropsUBO {
|
||||
highp float u_fade;
|
||||
highp float u_from_scale;
|
||||
highp float u_to_scale;
|
||||
highp float props_pad2;
|
||||
};
|
||||
layout (std140) uniform FillExtrusionTilePropsUBO {
|
||||
highp vec4 u_pattern_from;
|
||||
highp vec4 u_pattern_to;
|
||||
};
|
||||
layout (std140) uniform FillExtrusionInterpolateUBO {
|
||||
highp float u_base_t;
|
||||
highp float u_height_t;
|
||||
highp float u_color_t;
|
||||
highp float u_pattern_from_t;
|
||||
highp float u_pattern_to_t;
|
||||
highp float interp_pad1, interp_pad2, interp_pad3;
|
||||
lowp float props_pad2;
|
||||
};
|
||||
|
||||
#ifndef HAS_UNIFORM_u_base
|
||||
layout (location = 2) in highp vec2 a_base;
|
||||
#endif
|
||||
|
||||
@@ -23,21 +23,37 @@ layout (std140) uniform GlobalPaintParamsUBO {
|
||||
highp float u_symbol_fade_change;
|
||||
highp float u_aspect_ratio;
|
||||
highp float u_pixel_ratio;
|
||||
highp float global_pad1, global_pad2;
|
||||
highp float u_map_zoom;
|
||||
lowp float global_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform FillExtrusionDrawableUBO {
|
||||
highp mat4 u_matrix;
|
||||
highp vec2 u_texsize;
|
||||
highp vec2 u_pixel_coord_upper;
|
||||
highp vec2 u_pixel_coord_lower;
|
||||
highp float u_height_factor;
|
||||
highp float u_tile_ratio;
|
||||
// Interpolations
|
||||
highp float u_base_t;
|
||||
highp float u_height_t;
|
||||
highp float u_color_t;
|
||||
highp float u_pattern_from_t;
|
||||
highp float u_pattern_to_t;
|
||||
lowp float drawable_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform FillExtrusionTilePropsUBO {
|
||||
highp vec4 u_pattern_from;
|
||||
highp vec4 u_pattern_to;
|
||||
highp vec2 u_texsize;
|
||||
lowp float tileprops_pad1;
|
||||
lowp float tileprops_pad2;
|
||||
};
|
||||
|
||||
layout (std140) uniform FillExtrusionPropsUBO {
|
||||
highp vec4 u_color;
|
||||
highp vec3 u_lightcolor;
|
||||
highp float props_pad1;
|
||||
lowp float props_pad1;
|
||||
highp vec3 u_lightpos;
|
||||
highp float u_base;
|
||||
highp float u_height;
|
||||
@@ -47,19 +63,7 @@ layout (std140) uniform FillExtrusionPropsUBO {
|
||||
highp float u_fade;
|
||||
highp float u_from_scale;
|
||||
highp float u_to_scale;
|
||||
highp float props_pad2;
|
||||
};
|
||||
layout (std140) uniform FillExtrusionTilePropsUBO {
|
||||
highp vec4 u_pattern_from;
|
||||
highp vec4 u_pattern_to;
|
||||
};
|
||||
layout (std140) uniform FillExtrusionInterpolateUBO {
|
||||
highp float u_base_t;
|
||||
highp float u_height_t;
|
||||
highp float u_color_t;
|
||||
highp float u_pattern_from_t;
|
||||
highp float u_pattern_to_t;
|
||||
highp float interp_pad1, interp_pad2, interp_pad3;
|
||||
lowp float props_pad2;
|
||||
};
|
||||
|
||||
#ifndef HAS_UNIFORM_u_base
|
||||
@@ -152,18 +156,18 @@ mediump vec4 pattern_to = u_pattern_to;
|
||||
in vec2 v_pos_b;
|
||||
in vec4 v_lighting;
|
||||
|
||||
layout (std140) uniform FillExtrusionDrawableUBO {
|
||||
highp mat4 u_matrix;
|
||||
layout (std140) uniform FillExtrusionTilePropsUBO {
|
||||
highp vec4 u_pattern_from;
|
||||
highp vec4 u_pattern_to;
|
||||
highp vec2 u_texsize;
|
||||
highp vec2 u_pixel_coord_upper;
|
||||
highp vec2 u_pixel_coord_lower;
|
||||
highp float u_height_factor;
|
||||
highp float u_tile_ratio;
|
||||
lowp float tileprops_pad1;
|
||||
lowp float tileprops_pad2;
|
||||
};
|
||||
|
||||
layout (std140) uniform FillExtrusionPropsUBO {
|
||||
highp vec4 u_color;
|
||||
highp vec3 u_lightcolor;
|
||||
highp float props_pad1;
|
||||
lowp float props_pad1;
|
||||
highp vec3 u_lightpos;
|
||||
highp float u_base;
|
||||
highp float u_height;
|
||||
@@ -173,19 +177,7 @@ layout (std140) uniform FillExtrusionPropsUBO {
|
||||
highp float u_fade;
|
||||
highp float u_from_scale;
|
||||
highp float u_to_scale;
|
||||
highp float props_pad2;
|
||||
};
|
||||
layout (std140) uniform FillExtrusionTilePropsUBO {
|
||||
highp vec4 u_pattern_from;
|
||||
highp vec4 u_pattern_to;
|
||||
};
|
||||
layout (std140) uniform FillExtrusionInterpolateUBO {
|
||||
highp float u_base_t;
|
||||
highp float u_height_t;
|
||||
highp float u_color_t;
|
||||
highp float u_pattern_from_t;
|
||||
highp float u_pattern_to_t;
|
||||
highp float interp_pad1, interp_pad2, interp_pad3;
|
||||
lowp float props_pad2;
|
||||
};
|
||||
|
||||
uniform sampler2D u_image;
|
||||
|
||||
@@ -16,17 +16,19 @@ struct ShaderSource<BuiltIn::FillOutlineShader, gfx::Backend::Type::OpenGL> {
|
||||
highp float u_symbol_fade_change;
|
||||
highp float u_aspect_ratio;
|
||||
highp float u_pixel_ratio;
|
||||
highp float global_pad1, global_pad2;
|
||||
highp float u_map_zoom;
|
||||
lowp float global_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform FillOutlineDrawableUBO {
|
||||
highp mat4 u_matrix;
|
||||
};
|
||||
layout (std140) uniform FillOutlineInterpolateUBO {
|
||||
// Interpolations
|
||||
highp float u_outline_color_t;
|
||||
highp float u_opacity_t;
|
||||
highp float interp_pad1;
|
||||
highp float interp_pad2;
|
||||
lowp float drawable_pad1;
|
||||
lowp float drawable_pad2;
|
||||
};
|
||||
|
||||
layout (std140) uniform FillEvaluatedPropsUBO {
|
||||
highp vec4 u_color;
|
||||
highp vec4 u_outline_color;
|
||||
@@ -65,13 +67,7 @@ lowp float opacity = u_opacity;
|
||||
v_pos = (gl_Position.xy / gl_Position.w + 1.0) / 2.0 * u_world_size;
|
||||
}
|
||||
)";
|
||||
static constexpr const char* fragment = R"(layout (std140) uniform FillOutlineInterpolateUBO {
|
||||
highp float u_outline_color_t;
|
||||
highp float u_opacity_t;
|
||||
highp float interp_pad1;
|
||||
highp float interp_pad2;
|
||||
};
|
||||
layout (std140) uniform FillEvaluatedPropsUBO {
|
||||
static constexpr const char* fragment = R"(layout (std140) uniform FillEvaluatedPropsUBO {
|
||||
highp vec4 u_color;
|
||||
highp vec4 u_outline_color;
|
||||
highp float u_opacity;
|
||||
|
||||
@@ -16,26 +16,29 @@ struct ShaderSource<BuiltIn::FillOutlinePatternShader, gfx::Backend::Type::OpenG
|
||||
highp float u_symbol_fade_change;
|
||||
highp float u_aspect_ratio;
|
||||
highp float u_pixel_ratio;
|
||||
highp float global_pad1, global_pad2;
|
||||
highp float u_map_zoom;
|
||||
lowp float global_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform FillOutlinePatternDrawableUBO {
|
||||
highp mat4 u_matrix;
|
||||
highp vec2 u_pixel_coord_upper;
|
||||
highp vec2 u_pixel_coord_lower;
|
||||
highp vec2 u_texsize;
|
||||
highp float u_tile_ratio;
|
||||
highp float drawable_pad1;
|
||||
};
|
||||
layout (std140) uniform FillOutlinePatternTilePropsUBO {
|
||||
highp vec4 u_pattern_from;
|
||||
highp vec4 u_pattern_to;
|
||||
};
|
||||
layout (std140) uniform FillOutlinePatternInterpolateUBO {
|
||||
// Interpolations
|
||||
highp float u_pattern_from_t;
|
||||
highp float u_pattern_to_t;
|
||||
highp float u_opacity_t;
|
||||
highp float interp_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform FillOutlinePatternTilePropsUBO {
|
||||
highp vec4 u_pattern_from;
|
||||
highp vec4 u_pattern_to;
|
||||
highp vec2 u_texsize;
|
||||
lowp float tileprops_pad1;
|
||||
lowp float tileprops_pad2;
|
||||
};
|
||||
|
||||
layout (std140) uniform FillEvaluatedPropsUBO {
|
||||
highp vec4 u_color;
|
||||
highp vec4 u_outline_color;
|
||||
@@ -102,24 +105,14 @@ mediump vec4 pattern_to = u_pattern_to;
|
||||
v_pos = (gl_Position.xy / gl_Position.w + 1.0) / 2.0 * u_world_size;
|
||||
}
|
||||
)";
|
||||
static constexpr const char* fragment = R"(layout (std140) uniform FillOutlinePatternDrawableUBO {
|
||||
highp mat4 u_matrix;
|
||||
highp vec2 u_pixel_coord_upper;
|
||||
highp vec2 u_pixel_coord_lower;
|
||||
highp vec2 u_texsize;
|
||||
highp float u_tile_ratio;
|
||||
highp float drawable_pad1;
|
||||
};
|
||||
layout (std140) uniform FillOutlinePatternTilePropsUBO {
|
||||
static constexpr const char* fragment = R"(layout (std140) uniform FillOutlinePatternTilePropsUBO {
|
||||
highp vec4 u_pattern_from;
|
||||
highp vec4 u_pattern_to;
|
||||
highp vec2 u_texsize;
|
||||
lowp float tileprops_pad1;
|
||||
lowp float tileprops_pad2;
|
||||
};
|
||||
layout (std140) uniform FillOutlinePatternInterpolateUBO {
|
||||
highp float u_pattern_from_t;
|
||||
highp float u_pattern_to_t;
|
||||
highp float u_opacity_t;
|
||||
highp float interp_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform FillEvaluatedPropsUBO {
|
||||
highp vec4 u_color;
|
||||
highp vec4 u_outline_color;
|
||||
|
||||
@@ -27,13 +27,18 @@ layout (std140) uniform GlobalPaintParamsUBO {
|
||||
highp float u_symbol_fade_change;
|
||||
highp float u_aspect_ratio;
|
||||
highp float u_pixel_ratio;
|
||||
highp float global_pad1, global_pad2;
|
||||
highp float u_map_zoom;
|
||||
lowp float global_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform FillOutlineTriangulatedDrawableUBO {
|
||||
highp mat4 u_matrix;
|
||||
mediump float u_ratio;
|
||||
lowp float drawable_pad1, drawable_pad2, drawable_pad3;
|
||||
lowp float drawable_pad1;
|
||||
lowp float drawable_pad2;
|
||||
lowp float drawable_pad3;
|
||||
};
|
||||
|
||||
layout (std140) uniform FillEvaluatedPropsUBO {
|
||||
highp vec4 u_color;
|
||||
highp vec4 u_outline_color;
|
||||
|
||||
@@ -16,26 +16,29 @@ struct ShaderSource<BuiltIn::FillPatternShader, gfx::Backend::Type::OpenGL> {
|
||||
highp float u_symbol_fade_change;
|
||||
highp float u_aspect_ratio;
|
||||
highp float u_pixel_ratio;
|
||||
highp float global_pad1, global_pad2;
|
||||
highp float u_map_zoom;
|
||||
lowp float global_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform FillPatternDrawableUBO {
|
||||
highp mat4 u_matrix;
|
||||
highp vec2 u_pixel_coord_upper;
|
||||
highp vec2 u_pixel_coord_lower;
|
||||
highp vec2 u_texsize;
|
||||
highp float u_tile_ratio;
|
||||
highp float drawable_pad1;
|
||||
};
|
||||
layout (std140) uniform FillPatternTilePropsUBO {
|
||||
highp vec4 u_pattern_from;
|
||||
highp vec4 u_pattern_to;
|
||||
};
|
||||
layout (std140) uniform FillPatternInterpolateUBO {
|
||||
// Interpolations
|
||||
highp float u_pattern_from_t;
|
||||
highp float u_pattern_to_t;
|
||||
highp float u_opacity_t;
|
||||
highp float interp_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform FillPatternTilePropsUBO {
|
||||
highp vec4 u_pattern_from;
|
||||
highp vec4 u_pattern_to;
|
||||
highp vec2 u_texsize;
|
||||
lowp float tileprops_pad1;
|
||||
lowp float tileprops_pad2;
|
||||
};
|
||||
|
||||
layout (std140) uniform FillEvaluatedPropsUBO {
|
||||
highp vec4 u_color;
|
||||
highp vec4 u_outline_color;
|
||||
@@ -98,24 +101,14 @@ mediump vec4 pattern_to = u_pattern_to;
|
||||
v_pos_b = get_pattern_pos(u_pixel_coord_upper, u_pixel_coord_lower, toScale * display_size_b, tileZoomRatio, a_pos);
|
||||
}
|
||||
)";
|
||||
static constexpr const char* fragment = R"(layout (std140) uniform FillPatternDrawableUBO {
|
||||
highp mat4 u_matrix;
|
||||
highp vec2 u_pixel_coord_upper;
|
||||
highp vec2 u_pixel_coord_lower;
|
||||
highp vec2 u_texsize;
|
||||
highp float u_tile_ratio;
|
||||
highp float drawable_pad1;
|
||||
};
|
||||
layout (std140) uniform FillPatternTilePropsUBO {
|
||||
static constexpr const char* fragment = R"(layout (std140) uniform FillPatternTilePropsUBO {
|
||||
highp vec4 u_pattern_from;
|
||||
highp vec4 u_pattern_to;
|
||||
highp vec2 u_texsize;
|
||||
lowp float tileprops_pad1;
|
||||
lowp float tileprops_pad2;
|
||||
};
|
||||
layout (std140) uniform FillPatternInterpolateUBO {
|
||||
highp float u_pattern_from_t;
|
||||
highp float u_pattern_to_t;
|
||||
highp float u_opacity_t;
|
||||
highp float interp_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform FillEvaluatedPropsUBO {
|
||||
highp vec4 u_color;
|
||||
highp vec4 u_outline_color;
|
||||
|
||||
@@ -14,8 +14,10 @@ out vec2 v_extrude;
|
||||
layout (std140) uniform HeatmapDrawableUBO {
|
||||
highp mat4 u_matrix;
|
||||
highp float u_extrude_scale;
|
||||
// Interpolations
|
||||
lowp float u_weight_t;
|
||||
lowp float u_radius_t;
|
||||
lowp float drawable_pad1;
|
||||
lowp vec2 drawable_pad2;
|
||||
};
|
||||
|
||||
layout (std140) uniform HeatmapEvaluatedPropsUBO {
|
||||
@@ -25,12 +27,6 @@ layout (std140) uniform HeatmapEvaluatedPropsUBO {
|
||||
lowp float props_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform HeatmapInterpolateUBO {
|
||||
lowp float u_weight_t;
|
||||
lowp float u_radius_t;
|
||||
lowp vec2 interp_pad1;
|
||||
};
|
||||
|
||||
#ifndef HAS_UNIFORM_u_weight
|
||||
layout (location = 1) in highp vec2 a_weight;
|
||||
out highp float weight;
|
||||
|
||||
@@ -19,12 +19,16 @@ layout (std140) uniform GlobalPaintParamsUBO {
|
||||
highp float u_symbol_fade_change;
|
||||
highp float u_aspect_ratio;
|
||||
highp float u_pixel_ratio;
|
||||
highp float global_pad1, global_pad2;
|
||||
highp float u_map_zoom;
|
||||
lowp float global_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform HeatmapTexturePropsUBO {
|
||||
highp mat4 u_matrix;
|
||||
highp float u_opacity;
|
||||
lowp float props_pad1, props_pad2, props_pad3;
|
||||
lowp float props_pad1;
|
||||
lowp float props_pad2;
|
||||
lowp float props_pad3;
|
||||
};
|
||||
|
||||
void main() {
|
||||
@@ -41,7 +45,9 @@ uniform sampler2D u_color_ramp;
|
||||
layout (std140) uniform HeatmapTexturePropsUBO {
|
||||
highp mat4 u_matrix;
|
||||
highp float u_opacity;
|
||||
lowp float props_pad1, props_pad2, props_pad3;
|
||||
lowp float props_pad1;
|
||||
lowp float props_pad2;
|
||||
lowp float props_pad3;
|
||||
};
|
||||
|
||||
void main() {
|
||||
|
||||
@@ -13,8 +13,6 @@ layout (location = 1) in vec2 a_texture_pos;
|
||||
|
||||
layout (std140) uniform HillshadeDrawableUBO {
|
||||
highp mat4 u_matrix;
|
||||
highp vec2 u_latrange;
|
||||
highp vec2 u_light;
|
||||
};
|
||||
|
||||
out vec2 v_pos;
|
||||
@@ -27,8 +25,7 @@ void main() {
|
||||
static constexpr const char* fragment = R"(in vec2 v_pos;
|
||||
uniform sampler2D u_image;
|
||||
|
||||
layout (std140) uniform HillshadeDrawableUBO {
|
||||
highp mat4 u_matrix;
|
||||
layout (std140) uniform HillshadeTilePropsUBO {
|
||||
highp vec2 u_latrange;
|
||||
highp vec2 u_light;
|
||||
};
|
||||
|
||||
@@ -13,6 +13,9 @@ layout (location = 1) in vec2 a_texture_pos;
|
||||
|
||||
layout (std140) uniform HillshadePrepareDrawableUBO {
|
||||
highp mat4 u_matrix;
|
||||
};
|
||||
|
||||
layout (std140) uniform HillshadePrepareTilePropsUBO {
|
||||
highp vec4 u_unpack;
|
||||
highp vec2 u_dimension;
|
||||
highp float u_zoom;
|
||||
@@ -36,8 +39,7 @@ precision highp float;
|
||||
in vec2 v_pos;
|
||||
uniform sampler2D u_image;
|
||||
|
||||
layout (std140) uniform HillshadePrepareDrawableUBO {
|
||||
highp mat4 u_matrix;
|
||||
layout (std140) uniform HillshadePrepareTilePropsUBO {
|
||||
highp vec4 u_unpack;
|
||||
highp vec2 u_dimension;
|
||||
highp float u_zoom;
|
||||
|
||||
@@ -27,23 +27,21 @@ layout (std140) uniform GlobalPaintParamsUBO {
|
||||
highp float u_symbol_fade_change;
|
||||
highp float u_aspect_ratio;
|
||||
highp float u_pixel_ratio;
|
||||
highp float global_pad1, global_pad2;
|
||||
highp float u_map_zoom;
|
||||
lowp float global_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform LineDrawableUBO {
|
||||
highp mat4 u_matrix;
|
||||
mediump float u_ratio;
|
||||
lowp float drawable_pad1, drawable_pad2, drawable_pad3;
|
||||
};
|
||||
|
||||
layout (std140) uniform LineInterpolationUBO {
|
||||
// Interpolations
|
||||
lowp float u_color_t;
|
||||
lowp float u_blur_t;
|
||||
lowp float u_opacity_t;
|
||||
lowp float u_gapwidth_t;
|
||||
lowp float u_offset_t;
|
||||
lowp float u_width_t;
|
||||
highp vec2 interp_pad1;
|
||||
lowp float drawable_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform LineEvaluatedPropsUBO {
|
||||
@@ -54,8 +52,8 @@ layout (std140) uniform LineEvaluatedPropsUBO {
|
||||
lowp float u_offset;
|
||||
mediump float u_width;
|
||||
lowp float u_floorwidth;
|
||||
highp float props_pad1;
|
||||
highp float props_pad2;
|
||||
lowp float props_pad1;
|
||||
lowp float props_pad2;
|
||||
};
|
||||
|
||||
out vec2 v_normal;
|
||||
@@ -167,23 +165,7 @@ mediump float width = u_width;
|
||||
v_width2 = vec2(outset, inset);
|
||||
}
|
||||
)";
|
||||
static constexpr const char* fragment = R"(layout (std140) uniform LineDrawableUBO {
|
||||
highp mat4 u_matrix;
|
||||
mediump float u_ratio;
|
||||
lowp float drawable_pad1, drawable_pad2, drawable_pad3;
|
||||
};
|
||||
|
||||
layout (std140) uniform LineInterpolationUBO {
|
||||
lowp float u_color_t;
|
||||
lowp float u_blur_t;
|
||||
lowp float u_opacity_t;
|
||||
lowp float u_gapwidth_t;
|
||||
lowp float u_offset_t;
|
||||
lowp float u_width_t;
|
||||
highp vec2 interp_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform LineEvaluatedPropsUBO {
|
||||
static constexpr const char* fragment = R"(layout (std140) uniform LineEvaluatedPropsUBO {
|
||||
highp vec4 u_color;
|
||||
lowp float u_blur;
|
||||
lowp float u_opacity;
|
||||
@@ -191,8 +173,8 @@ layout (std140) uniform LineEvaluatedPropsUBO {
|
||||
lowp float u_offset;
|
||||
mediump float u_width;
|
||||
lowp float u_floorwidth;
|
||||
highp float props_pad1;
|
||||
highp float props_pad2;
|
||||
lowp float props_pad1;
|
||||
lowp float props_pad2;
|
||||
};
|
||||
|
||||
in vec2 v_width2;
|
||||
|
||||
@@ -31,23 +31,21 @@ layout (std140) uniform GlobalPaintParamsUBO {
|
||||
highp float u_symbol_fade_change;
|
||||
highp float u_aspect_ratio;
|
||||
highp float u_pixel_ratio;
|
||||
highp float global_pad1, global_pad2;
|
||||
highp float u_map_zoom;
|
||||
lowp float global_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform LineGradientDrawableUBO {
|
||||
highp mat4 u_matrix;
|
||||
mediump float u_ratio;
|
||||
lowp float drawable_pad1, drawable_pad2, drawable_pad3;
|
||||
};
|
||||
|
||||
layout (std140) uniform LineGradientInterpolationUBO {
|
||||
// Interpolations
|
||||
lowp float u_blur_t;
|
||||
lowp float u_opacity_t;
|
||||
lowp float u_gapwidth_t;
|
||||
lowp float u_offset_t;
|
||||
lowp float u_width_t;
|
||||
highp float interp_pad1;
|
||||
highp vec2 interp_pad2;
|
||||
lowp float drawable_pad1;
|
||||
lowp float drawable_pad2;
|
||||
};
|
||||
|
||||
layout (std140) uniform LineEvaluatedPropsUBO {
|
||||
@@ -58,8 +56,8 @@ layout (std140) uniform LineEvaluatedPropsUBO {
|
||||
lowp float u_offset;
|
||||
mediump float u_width;
|
||||
lowp float u_floorwidth;
|
||||
highp float props_pad1;
|
||||
highp float props_pad2;
|
||||
lowp float props_pad1;
|
||||
lowp float props_pad2;
|
||||
};
|
||||
|
||||
out vec2 v_normal;
|
||||
@@ -162,23 +160,7 @@ mediump float width = u_width;
|
||||
v_width2 = vec2(outset, inset);
|
||||
}
|
||||
)";
|
||||
static constexpr const char* fragment = R"(layout (std140) uniform LineGradientDrawableUBO {
|
||||
highp mat4 u_matrix;
|
||||
mediump float u_ratio;
|
||||
lowp float drawable_pad1, drawable_pad2, drawable_pad3;
|
||||
};
|
||||
|
||||
layout (std140) uniform LineGradientInterpolationUBO {
|
||||
lowp float u_blur_t;
|
||||
lowp float u_opacity_t;
|
||||
lowp float u_gapwidth_t;
|
||||
lowp float u_offset_t;
|
||||
lowp float u_width_t;
|
||||
highp float interp_pad1;
|
||||
highp vec2 interp_pad2;
|
||||
};
|
||||
|
||||
layout (std140) uniform LineEvaluatedPropsUBO {
|
||||
static constexpr const char* fragment = R"(layout (std140) uniform LineEvaluatedPropsUBO {
|
||||
highp vec4 u_color;
|
||||
lowp float u_blur;
|
||||
lowp float u_opacity;
|
||||
@@ -186,8 +168,8 @@ layout (std140) uniform LineEvaluatedPropsUBO {
|
||||
lowp float u_offset;
|
||||
mediump float u_width;
|
||||
lowp float u_floorwidth;
|
||||
highp float props_pad1;
|
||||
highp float props_pad2;
|
||||
lowp float props_pad1;
|
||||
lowp float props_pad2;
|
||||
};
|
||||
|
||||
uniform sampler2D u_image;
|
||||
|
||||
@@ -31,18 +31,13 @@ layout (std140) uniform GlobalPaintParamsUBO {
|
||||
highp float u_symbol_fade_change;
|
||||
highp float u_aspect_ratio;
|
||||
highp float u_pixel_ratio;
|
||||
highp float global_pad1, global_pad2;
|
||||
highp float u_map_zoom;
|
||||
lowp float global_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform LinePatternDrawableUBO {
|
||||
highp mat4 u_matrix;
|
||||
mediump vec4 u_scale;
|
||||
highp vec2 u_texsize;
|
||||
mediump float u_ratio;
|
||||
highp float u_fade;
|
||||
};
|
||||
|
||||
layout (std140) uniform LinePatternInterpolationUBO {
|
||||
// Interpolations
|
||||
lowp float u_blur_t;
|
||||
lowp float u_opacity_t;
|
||||
lowp float u_offset_t;
|
||||
@@ -50,12 +45,15 @@ layout (std140) uniform LinePatternInterpolationUBO {
|
||||
lowp float u_width_t;
|
||||
lowp float u_pattern_from_t;
|
||||
lowp float u_pattern_to_t;
|
||||
highp float interp_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform LinePatternTilePropertiesUBO {
|
||||
layout (std140) uniform LinePatternTilePropsUBO {
|
||||
lowp vec4 u_pattern_from;
|
||||
lowp vec4 u_pattern_to;
|
||||
mediump vec4 u_scale;
|
||||
highp vec2 u_texsize;
|
||||
highp float u_fade;
|
||||
lowp float tileprops_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform LineEvaluatedPropsUBO {
|
||||
@@ -66,8 +64,8 @@ layout (std140) uniform LineEvaluatedPropsUBO {
|
||||
lowp float u_offset;
|
||||
mediump float u_width;
|
||||
lowp float u_floorwidth;
|
||||
highp float props_pad1;
|
||||
highp float props_pad2;
|
||||
lowp float props_pad1;
|
||||
lowp float props_pad2;
|
||||
};
|
||||
|
||||
out vec2 v_normal;
|
||||
@@ -188,28 +186,13 @@ mediump vec4 pattern_to = u_pattern_to;
|
||||
v_width2 = vec2(outset, inset);
|
||||
}
|
||||
)";
|
||||
static constexpr const char* fragment = R"(layout (std140) uniform LinePatternDrawableUBO {
|
||||
highp mat4 u_matrix;
|
||||
mediump vec4 u_scale;
|
||||
highp vec2 u_texsize;
|
||||
mediump float u_ratio;
|
||||
highp float u_fade;
|
||||
};
|
||||
|
||||
layout (std140) uniform LinePatternInterpolationUBO {
|
||||
lowp float u_blur_t;
|
||||
lowp float u_opacity_t;
|
||||
lowp float u_offset_t;
|
||||
lowp float u_gapwidth_t;
|
||||
lowp float u_width_t;
|
||||
lowp float u_pattern_from_t;
|
||||
lowp float u_pattern_to_t;
|
||||
highp float interp_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform LinePatternTilePropertiesUBO {
|
||||
static constexpr const char* fragment = R"(layout (std140) uniform LinePatternTilePropsUBO {
|
||||
lowp vec4 u_pattern_from;
|
||||
lowp vec4 u_pattern_to;
|
||||
mediump vec4 u_scale;
|
||||
highp vec2 u_texsize;
|
||||
highp float u_fade;
|
||||
lowp float tileprops_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform LineEvaluatedPropsUBO {
|
||||
@@ -220,8 +203,8 @@ layout (std140) uniform LineEvaluatedPropsUBO {
|
||||
lowp float u_offset;
|
||||
mediump float u_width;
|
||||
lowp float u_floorwidth;
|
||||
highp float props_pad1;
|
||||
highp float props_pad2;
|
||||
lowp float props_pad1;
|
||||
lowp float props_pad2;
|
||||
};
|
||||
|
||||
uniform sampler2D u_image;
|
||||
|
||||
@@ -31,22 +31,18 @@ layout (std140) uniform GlobalPaintParamsUBO {
|
||||
highp float u_symbol_fade_change;
|
||||
highp float u_aspect_ratio;
|
||||
highp float u_pixel_ratio;
|
||||
highp float global_pad1, global_pad2;
|
||||
highp float u_map_zoom;
|
||||
lowp float global_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform LineSDFDrawableUBO {
|
||||
highp mat4 u_matrix;
|
||||
highp vec2 u_patternscale_a;
|
||||
highp vec2 u_patternscale_b;
|
||||
mediump float u_ratio;
|
||||
highp float u_tex_y_a;
|
||||
highp float u_tex_y_b;
|
||||
highp float u_sdfgamma;
|
||||
highp float u_mix;
|
||||
lowp float drawable_pad1, drawable_pad2, drawable_pad3;
|
||||
};
|
||||
|
||||
layout (std140) uniform LineSDFInterpolationUBO {
|
||||
mediump float u_ratio;
|
||||
// Interpolations
|
||||
lowp float u_color_t;
|
||||
lowp float u_blur_t;
|
||||
lowp float u_opacity_t;
|
||||
@@ -54,7 +50,8 @@ layout (std140) uniform LineSDFInterpolationUBO {
|
||||
lowp float u_offset_t;
|
||||
lowp float u_width_t;
|
||||
lowp float u_floorwidth_t;
|
||||
highp float interp_pad1;
|
||||
lowp float drawable_pad1;
|
||||
lowp float drawable_pad2;
|
||||
};
|
||||
|
||||
layout (std140) uniform LineEvaluatedPropsUBO {
|
||||
@@ -65,8 +62,8 @@ layout (std140) uniform LineEvaluatedPropsUBO {
|
||||
lowp float u_offset;
|
||||
mediump float u_width;
|
||||
lowp float u_floorwidth;
|
||||
highp float props_pad1;
|
||||
highp float props_pad2;
|
||||
lowp float props_pad1;
|
||||
lowp float props_pad2;
|
||||
};
|
||||
|
||||
out vec2 v_normal;
|
||||
@@ -191,28 +188,11 @@ lowp float floorwidth = u_floorwidth;
|
||||
v_width2 = vec2(outset, inset);
|
||||
}
|
||||
)";
|
||||
static constexpr const char* fragment = R"(
|
||||
layout (std140) uniform LineSDFDrawableUBO {
|
||||
highp mat4 u_matrix;
|
||||
highp vec2 u_patternscale_a;
|
||||
highp vec2 u_patternscale_b;
|
||||
mediump float u_ratio;
|
||||
highp float u_tex_y_a;
|
||||
highp float u_tex_y_b;
|
||||
static constexpr const char* fragment = R"(layout (std140) uniform LineSDFTilePropsUBO {
|
||||
highp float u_sdfgamma;
|
||||
highp float u_mix;
|
||||
lowp float drawable_pad1, drawable_pad2, drawable_pad3;
|
||||
};
|
||||
|
||||
layout (std140) uniform LineSDFInterpolationUBO {
|
||||
lowp float u_color_t;
|
||||
lowp float u_blur_t;
|
||||
lowp float u_opacity_t;
|
||||
lowp float u_gapwidth_t;
|
||||
lowp float u_offset_t;
|
||||
lowp float u_width_t;
|
||||
lowp float u_floorwidth_t;
|
||||
highp float interp_pad1;
|
||||
lowp float tileprops_pad1;
|
||||
lowp float tileprops_pad2;
|
||||
};
|
||||
|
||||
layout (std140) uniform LineEvaluatedPropsUBO {
|
||||
@@ -223,8 +203,8 @@ layout (std140) uniform LineEvaluatedPropsUBO {
|
||||
lowp float u_offset;
|
||||
mediump float u_width;
|
||||
lowp float u_floorwidth;
|
||||
highp float props_pad1;
|
||||
highp float props_pad2;
|
||||
lowp float props_pad1;
|
||||
lowp float props_pad2;
|
||||
};
|
||||
|
||||
uniform sampler2D u_image;
|
||||
|
||||
16
include/mbgl/shaders/gl/drawable_location_indicator.hpp
Normal file
16
include/mbgl/shaders/gl/drawable_location_indicator.hpp
Normal file
@@ -0,0 +1,16 @@
|
||||
// Generated code, do not modify this file!
|
||||
#pragma once
|
||||
#include <mbgl/shaders/shader_source.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::LocationIndicatorShader, gfx::Backend::Type::OpenGL> {
|
||||
static constexpr const char* name = "LocationIndicatorShader";
|
||||
static constexpr const char* vertex = R"()";
|
||||
static constexpr const char* fragment = R"()";
|
||||
};
|
||||
|
||||
} // namespace shaders
|
||||
} // namespace mbgl
|
||||
@@ -0,0 +1,16 @@
|
||||
// Generated code, do not modify this file!
|
||||
#pragma once
|
||||
#include <mbgl/shaders/shader_source.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::LocationIndicatorTexturedShader, gfx::Backend::Type::OpenGL> {
|
||||
static constexpr const char* name = "LocationIndicatorTexturedShader";
|
||||
static constexpr const char* vertex = R"()";
|
||||
static constexpr const char* fragment = R"()";
|
||||
};
|
||||
|
||||
} // namespace shaders
|
||||
} // namespace mbgl
|
||||
@@ -22,8 +22,8 @@ layout (std140) uniform RasterEvaluatedPropsUBO {
|
||||
highp float u_brightness_high;
|
||||
highp float u_saturation_factor;
|
||||
highp float u_contrast_factor;
|
||||
highp float props_pad1;
|
||||
highp float props_pad2;
|
||||
lowp float props_pad1;
|
||||
lowp float props_pad2;
|
||||
};
|
||||
|
||||
layout (location = 0) in vec2 a_pos;
|
||||
@@ -54,8 +54,8 @@ void main() {
|
||||
highp float u_brightness_high;
|
||||
highp float u_saturation_factor;
|
||||
highp float u_contrast_factor;
|
||||
highp float props_pad1;
|
||||
highp float props_pad2;
|
||||
lowp float props_pad1;
|
||||
lowp float props_pad2;
|
||||
};
|
||||
uniform sampler2D u_image0;
|
||||
uniform sampler2D u_image1;
|
||||
|
||||
@@ -22,7 +22,8 @@ layout (std140) uniform GlobalPaintParamsUBO {
|
||||
highp float u_symbol_fade_change;
|
||||
highp float u_aspect_ratio;
|
||||
highp float u_pixel_ratio;
|
||||
highp float global_pad1, global_pad2;
|
||||
highp float u_map_zoom;
|
||||
lowp float global_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform SymbolDrawableUBO {
|
||||
@@ -33,29 +34,21 @@ layout (std140) uniform SymbolDrawableUBO {
|
||||
highp vec2 u_texsize;
|
||||
highp vec2 u_texsize_icon;
|
||||
|
||||
highp float u_gamma_scale;
|
||||
bool u_is_text_prop;
|
||||
bool u_rotate_symbol;
|
||||
highp vec2 drawable_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform SymbolTilePropsUBO {
|
||||
bool u_is_text;
|
||||
bool u_is_halo;
|
||||
bool u_pitch_with_map;
|
||||
bool u_is_size_zoom_constant;
|
||||
bool u_is_size_feature_constant;
|
||||
|
||||
highp float u_size_t; // used to interpolate between zoom stops when size is a composite function
|
||||
highp float u_size; // used when size is both zoom and feature constant
|
||||
bool tileprops_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform SymbolInterpolateUBO {
|
||||
// Interpolations
|
||||
highp float u_fill_color_t;
|
||||
highp float u_halo_color_t;
|
||||
highp float u_opacity_t;
|
||||
highp float u_halo_width_t;
|
||||
highp float u_halo_blur_t;
|
||||
highp float interp_pad1, interp_pad2, interp_pad3;
|
||||
};
|
||||
|
||||
layout (std140) uniform SymbolEvaluatedPropsUBO {
|
||||
@@ -64,13 +57,13 @@ layout (std140) uniform SymbolEvaluatedPropsUBO {
|
||||
highp float u_text_opacity;
|
||||
highp float u_text_halo_width;
|
||||
highp float u_text_halo_blur;
|
||||
highp float props_pad1;
|
||||
lowp float props_pad1;
|
||||
highp vec4 u_icon_fill_color;
|
||||
highp vec4 u_icon_halo_color;
|
||||
highp float u_icon_opacity;
|
||||
highp float u_icon_halo_width;
|
||||
highp float u_icon_halo_blur;
|
||||
highp float props_pad2;
|
||||
lowp float props_pad2;
|
||||
};
|
||||
|
||||
out vec2 v_tex;
|
||||
@@ -82,7 +75,7 @@ out lowp float opacity;
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
highp float u_opacity = u_is_text ? u_text_opacity : u_icon_opacity;
|
||||
highp float u_opacity = u_is_text_prop ? u_text_opacity : u_icon_opacity;
|
||||
|
||||
#ifndef HAS_UNIFORM_u_opacity
|
||||
opacity = unpack_mix_vec2(a_opacity, u_opacity_t);
|
||||
@@ -124,7 +117,7 @@ lowp float opacity = u_opacity;
|
||||
|
||||
size *= perspective_ratio;
|
||||
|
||||
float fontScale = u_is_text ? size / 24.0 : size;
|
||||
float fontScale = u_is_text_prop ? size / 24.0 : size;
|
||||
|
||||
highp float symbol_rotation = 0.0;
|
||||
if (u_rotate_symbol) {
|
||||
@@ -155,12 +148,8 @@ lowp float opacity = u_opacity;
|
||||
layout (std140) uniform SymbolTilePropsUBO {
|
||||
bool u_is_text;
|
||||
bool u_is_halo;
|
||||
bool u_pitch_with_map;
|
||||
bool u_is_size_zoom_constant;
|
||||
bool u_is_size_feature_constant;
|
||||
highp float u_size_t; // used to interpolate between zoom stops when size is a composite function
|
||||
highp float u_size; // used when size is both zoom and feature constant
|
||||
bool tileprops_pad1;
|
||||
highp float u_gamma_scale;
|
||||
lowp float tileprops_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform SymbolEvaluatedPropsUBO {
|
||||
@@ -169,13 +158,13 @@ layout (std140) uniform SymbolEvaluatedPropsUBO {
|
||||
highp float u_text_opacity;
|
||||
highp float u_text_halo_width;
|
||||
highp float u_text_halo_blur;
|
||||
highp float props_pad1;
|
||||
lowp float props_pad1;
|
||||
highp vec4 u_icon_fill_color;
|
||||
highp vec4 u_icon_halo_color;
|
||||
highp float u_icon_opacity;
|
||||
highp float u_icon_halo_width;
|
||||
highp float u_icon_halo_blur;
|
||||
highp float props_pad2;
|
||||
lowp float props_pad2;
|
||||
};
|
||||
|
||||
in vec2 v_tex;
|
||||
|
||||
@@ -30,7 +30,8 @@ layout (std140) uniform GlobalPaintParamsUBO {
|
||||
highp float u_symbol_fade_change;
|
||||
highp float u_aspect_ratio;
|
||||
highp float u_pixel_ratio;
|
||||
highp float global_pad1, global_pad2;
|
||||
highp float u_map_zoom;
|
||||
lowp float global_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform SymbolDrawableUBO {
|
||||
@@ -41,29 +42,21 @@ layout (std140) uniform SymbolDrawableUBO {
|
||||
highp vec2 u_texsize;
|
||||
highp vec2 u_texsize_icon;
|
||||
|
||||
highp float u_gamma_scale;
|
||||
bool u_is_text_prop;
|
||||
bool u_rotate_symbol;
|
||||
highp vec2 drawable_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform SymbolTilePropsUBO {
|
||||
bool u_is_text;
|
||||
bool u_is_halo;
|
||||
bool u_pitch_with_map;
|
||||
bool u_is_size_zoom_constant;
|
||||
bool u_is_size_feature_constant;
|
||||
|
||||
highp float u_size_t; // used to interpolate between zoom stops when size is a composite function
|
||||
highp float u_size; // used when size is both zoom and feature constant
|
||||
bool tileprops_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform SymbolInterpolateUBO {
|
||||
// Interpolations
|
||||
highp float u_fill_color_t;
|
||||
highp float u_halo_color_t;
|
||||
highp float u_opacity_t;
|
||||
highp float u_halo_width_t;
|
||||
highp float u_halo_blur_t;
|
||||
highp float interp_pad1, interp_pad2, interp_pad3;
|
||||
};
|
||||
|
||||
layout (std140) uniform SymbolEvaluatedPropsUBO {
|
||||
@@ -72,13 +65,13 @@ layout (std140) uniform SymbolEvaluatedPropsUBO {
|
||||
highp float u_text_opacity;
|
||||
highp float u_text_halo_width;
|
||||
highp float u_text_halo_blur;
|
||||
highp float props_pad1;
|
||||
lowp float props_pad1;
|
||||
highp vec4 u_icon_fill_color;
|
||||
highp vec4 u_icon_halo_color;
|
||||
highp float u_icon_opacity;
|
||||
highp float u_icon_halo_width;
|
||||
highp float u_icon_halo_blur;
|
||||
highp float props_pad2;
|
||||
lowp float props_pad2;
|
||||
};
|
||||
|
||||
out vec2 v_data0;
|
||||
@@ -106,11 +99,11 @@ out lowp float halo_blur;
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
highp vec4 u_fill_color = u_is_text ? u_text_fill_color : u_icon_fill_color;
|
||||
highp vec4 u_halo_color = u_is_text ? u_text_halo_color : u_icon_halo_color;
|
||||
highp float u_opacity = u_is_text ? u_text_opacity : u_icon_opacity;
|
||||
highp float u_halo_width = u_is_text ? u_text_halo_width : u_icon_halo_width;
|
||||
highp float u_halo_blur = u_is_text ? u_text_halo_blur : u_icon_halo_blur;
|
||||
highp vec4 u_fill_color = u_is_text_prop ? u_text_fill_color : u_icon_fill_color;
|
||||
highp vec4 u_halo_color = u_is_text_prop ? u_text_halo_color : u_icon_halo_color;
|
||||
highp float u_opacity = u_is_text_prop ? u_text_opacity : u_icon_opacity;
|
||||
highp float u_halo_width = u_is_text_prop ? u_text_halo_width : u_icon_halo_width;
|
||||
highp float u_halo_blur = u_is_text_prop ? u_text_halo_blur : u_icon_halo_blur;
|
||||
|
||||
#ifndef HAS_UNIFORM_u_fill_color
|
||||
fill_color = unpack_mix_color(a_fill_color, u_fill_color_t);
|
||||
@@ -176,7 +169,7 @@ lowp float halo_blur = u_halo_blur;
|
||||
|
||||
size *= perspective_ratio;
|
||||
|
||||
float fontScale = u_is_text ? size / 24.0 : size;
|
||||
float fontScale = u_is_text_prop ? size / 24.0 : size;
|
||||
|
||||
highp float symbol_rotation = 0.0;
|
||||
if (u_rotate_symbol) {
|
||||
@@ -209,28 +202,11 @@ lowp float halo_blur = u_halo_blur;
|
||||
)";
|
||||
static constexpr const char* fragment = R"(#define SDF_PX 8.0
|
||||
|
||||
layout (std140) uniform SymbolDrawableUBO {
|
||||
highp mat4 u_matrix;
|
||||
highp mat4 u_label_plane_matrix;
|
||||
highp mat4 u_coord_matrix;
|
||||
|
||||
highp vec2 u_texsize;
|
||||
highp vec2 u_texsize_icon;
|
||||
|
||||
highp float u_gamma_scale;
|
||||
bool u_rotate_symbol;
|
||||
highp vec2 drawable_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform SymbolTilePropsUBO {
|
||||
bool u_is_text;
|
||||
bool u_is_halo;
|
||||
bool u_pitch_with_map;
|
||||
bool u_is_size_zoom_constant;
|
||||
bool u_is_size_feature_constant;
|
||||
highp float u_size_t; // used to interpolate between zoom stops when size is a composite function
|
||||
highp float u_size; // used when size is both zoom and feature constant
|
||||
bool tileprops_pad1;
|
||||
highp float u_gamma_scale;
|
||||
lowp float tileprops_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform SymbolEvaluatedPropsUBO {
|
||||
@@ -239,13 +215,13 @@ layout (std140) uniform SymbolEvaluatedPropsUBO {
|
||||
highp float u_text_opacity;
|
||||
highp float u_text_halo_width;
|
||||
highp float u_text_halo_blur;
|
||||
highp float props_pad1;
|
||||
lowp float props_pad1;
|
||||
highp vec4 u_icon_fill_color;
|
||||
highp vec4 u_icon_halo_color;
|
||||
highp float u_icon_opacity;
|
||||
highp float u_icon_halo_width;
|
||||
highp float u_icon_halo_blur;
|
||||
highp float props_pad2;
|
||||
lowp float props_pad2;
|
||||
};
|
||||
|
||||
uniform sampler2D u_texture;
|
||||
|
||||
@@ -1,323 +0,0 @@
|
||||
// Generated code, do not modify this file!
|
||||
#pragma once
|
||||
#include <mbgl/shaders/shader_source.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::SymbolSDFTextShader, gfx::Backend::Type::OpenGL> {
|
||||
static constexpr const char* name = "SymbolSDFTextShader";
|
||||
static constexpr const char* vertex = R"(layout (location = 0) in vec4 a_pos_offset;
|
||||
layout (location = 1) in vec4 a_data;
|
||||
layout (location = 2) in vec4 a_pixeloffset;
|
||||
layout (location = 3) in vec3 a_projected_pos;
|
||||
layout (location = 4) in float a_fade_opacity;
|
||||
|
||||
// contents of a_size vary based on the type of property value
|
||||
// used for {text,icon}-size.
|
||||
// For constants, a_size is disabled.
|
||||
// For source functions, we bind only one value per vertex: the value of {text,icon}-size evaluated for the current feature.
|
||||
// For composite functions:
|
||||
// [ text-size(lowerZoomStop, feature),
|
||||
// text-size(upperZoomStop, feature) ]
|
||||
|
||||
layout (std140) uniform SymbolDrawableUBO {
|
||||
highp mat4 u_matrix;
|
||||
highp mat4 u_label_plane_matrix;
|
||||
highp mat4 u_coord_matrix;
|
||||
|
||||
highp vec2 u_texsize;
|
||||
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;
|
||||
};
|
||||
|
||||
layout (std140) uniform SymbolDrawablePaintUBO {
|
||||
highp vec4 u_fill_color;
|
||||
highp vec4 u_halo_color;
|
||||
highp float u_opacity;
|
||||
highp float u_halo_width;
|
||||
highp float u_halo_blur;
|
||||
highp float u_padding;
|
||||
};
|
||||
|
||||
layout (std140) uniform SymbolDrawableTilePropsUBO {
|
||||
bool u_is_text;
|
||||
bool u_is_halo;
|
||||
bool u_pitch_with_map;
|
||||
bool u_is_size_zoom_constant;
|
||||
bool u_is_size_feature_constant;
|
||||
highp float u_size_t; // used to interpolate between zoom stops when size is a composite function
|
||||
highp float u_size; // used when size is both zoom and feature constant
|
||||
bool u_pad3;
|
||||
};
|
||||
|
||||
layout (std140) uniform SymbolDrawableInterpolateUBO {
|
||||
highp float u_fill_color_t;
|
||||
highp float u_halo_color_t;
|
||||
highp float u_opacity_t;
|
||||
highp float u_halo_width_t;
|
||||
highp float u_halo_blur_t;
|
||||
highp float u_pad4,u_pad5,u_pad6;
|
||||
};
|
||||
|
||||
out vec2 v_data0;
|
||||
out vec3 v_data1;
|
||||
|
||||
#ifndef HAS_UNIFORM_u_fill_color
|
||||
layout (location = 5) in highp vec4 a_fill_color;
|
||||
out highp vec4 fill_color;
|
||||
#endif
|
||||
#ifndef HAS_UNIFORM_u_halo_color
|
||||
layout (location = 6) in highp vec4 a_halo_color;
|
||||
out highp vec4 halo_color;
|
||||
#endif
|
||||
#ifndef HAS_UNIFORM_u_opacity
|
||||
layout (location = 7) in lowp vec2 a_opacity;
|
||||
out lowp float opacity;
|
||||
#endif
|
||||
#ifndef HAS_UNIFORM_u_halo_width
|
||||
layout (location = 8) in lowp vec2 a_halo_width;
|
||||
out lowp float halo_width;
|
||||
#endif
|
||||
#ifndef HAS_UNIFORM_u_halo_blur
|
||||
layout (location = 9) in lowp vec2 a_halo_blur;
|
||||
out lowp float halo_blur;
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
#ifndef HAS_UNIFORM_u_fill_color
|
||||
fill_color = unpack_mix_color(a_fill_color, u_fill_color_t);
|
||||
#else
|
||||
highp vec4 fill_color = u_fill_color;
|
||||
#endif
|
||||
#ifndef HAS_UNIFORM_u_halo_color
|
||||
halo_color = unpack_mix_color(a_halo_color, u_halo_color_t);
|
||||
#else
|
||||
highp vec4 halo_color = u_halo_color;
|
||||
#endif
|
||||
#ifndef HAS_UNIFORM_u_opacity
|
||||
opacity = unpack_mix_vec2(a_opacity, u_opacity_t);
|
||||
#else
|
||||
lowp float opacity = u_opacity;
|
||||
#endif
|
||||
#ifndef HAS_UNIFORM_u_halo_width
|
||||
halo_width = unpack_mix_vec2(a_halo_width, u_halo_width_t);
|
||||
#else
|
||||
lowp float halo_width = u_halo_width;
|
||||
#endif
|
||||
#ifndef HAS_UNIFORM_u_halo_blur
|
||||
halo_blur = unpack_mix_vec2(a_halo_blur, u_halo_blur_t);
|
||||
#else
|
||||
lowp float halo_blur = u_halo_blur;
|
||||
#endif
|
||||
|
||||
vec2 a_pos = a_pos_offset.xy;
|
||||
vec2 a_offset = a_pos_offset.zw;
|
||||
|
||||
vec2 a_tex = a_data.xy;
|
||||
vec2 a_size = a_data.zw;
|
||||
|
||||
float a_size_min = floor(a_size[0] * 0.5);
|
||||
vec2 a_pxoffset = a_pixeloffset.xy;
|
||||
|
||||
highp float segment_angle = -a_projected_pos[2];
|
||||
float size;
|
||||
|
||||
if (!u_is_size_zoom_constant && !u_is_size_feature_constant) {
|
||||
size = mix(a_size_min, a_size[1], u_size_t) / 128.0;
|
||||
} else if (u_is_size_zoom_constant && !u_is_size_feature_constant) {
|
||||
size = a_size_min / 128.0;
|
||||
} else {
|
||||
size = u_size;
|
||||
}
|
||||
|
||||
vec4 projectedPoint = u_matrix * vec4(a_pos, 0, 1);
|
||||
highp float camera_to_anchor_distance = projectedPoint.w;
|
||||
// If the label is pitched with the map, layout is done in pitched space,
|
||||
// which makes labels in the distance smaller relative to viewport space.
|
||||
// We counteract part of that effect by multiplying by the perspective ratio.
|
||||
// If the label isn't pitched with the map, we do layout in viewport space,
|
||||
// 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.
|
||||
highp float distance_ratio = u_pitch_with_map ?
|
||||
camera_to_anchor_distance / u_camera_to_center_distance :
|
||||
u_camera_to_center_distance / camera_to_anchor_distance;
|
||||
highp float perspective_ratio = clamp(
|
||||
0.5 + 0.5 * distance_ratio,
|
||||
0.0, // Prevents oversized near-field symbols in pitched/overzoomed tiles
|
||||
4.0);
|
||||
|
||||
size *= perspective_ratio;
|
||||
|
||||
float fontScale = u_is_text ? size / 24.0 : size;
|
||||
|
||||
highp float symbol_rotation = 0.0;
|
||||
if (u_rotate_symbol) {
|
||||
// Point labels with 'rotation-alignment: map' are horizontal with respect to tile units
|
||||
// To figure out that angle in projected space, we draw a short horizontal line in tile
|
||||
// space, project it, and measure its angle in projected space.
|
||||
vec4 offsetProjectedPoint = u_matrix * vec4(a_pos + vec2(1, 0), 0, 1);
|
||||
|
||||
vec2 a = projectedPoint.xy / projectedPoint.w;
|
||||
vec2 b = offsetProjectedPoint.xy / offsetProjectedPoint.w;
|
||||
|
||||
symbol_rotation = atan((b.y - a.y) / u_aspect_ratio, b.x - a.x);
|
||||
}
|
||||
|
||||
highp float angle_sin = sin(segment_angle + symbol_rotation);
|
||||
highp float angle_cos = cos(segment_angle + symbol_rotation);
|
||||
mat2 rotation_matrix = mat2(angle_cos, -1.0 * angle_sin, angle_sin, angle_cos);
|
||||
|
||||
vec4 projected_pos = u_label_plane_matrix * vec4(a_projected_pos.xy, 0.0, 1.0);
|
||||
gl_Position = u_coord_matrix * vec4(projected_pos.xy / projected_pos.w + rotation_matrix * (a_offset / 32.0 * fontScale + a_pxoffset), 0.0, 1.0);
|
||||
float gamma_scale = gl_Position.w;
|
||||
|
||||
vec2 fade_opacity = unpack_opacity(a_fade_opacity);
|
||||
float fade_change = fade_opacity[1] > 0.5 ? u_fade_change : -u_fade_change;
|
||||
float interpolated_fade_opacity = max(0.0, min(1.0, fade_opacity[0] + fade_change));
|
||||
|
||||
v_data0 = a_tex / u_texsize;
|
||||
v_data1 = vec3(gamma_scale, size, interpolated_fade_opacity);
|
||||
}
|
||||
)";
|
||||
static constexpr const char* fragment = R"(#define SDF_PX 8.0
|
||||
|
||||
layout (std140) uniform SymbolDrawableUBO {
|
||||
highp mat4 u_matrix;
|
||||
highp mat4 u_label_plane_matrix;
|
||||
highp mat4 u_coord_matrix;
|
||||
|
||||
highp vec2 u_texsize;
|
||||
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;
|
||||
};
|
||||
|
||||
layout (std140) uniform SymbolDrawablePaintUBO {
|
||||
highp vec4 u_fill_color;
|
||||
highp vec4 u_halo_color;
|
||||
highp float u_opacity;
|
||||
highp float u_halo_width;
|
||||
highp float u_halo_blur;
|
||||
highp float u_padding;
|
||||
};
|
||||
|
||||
layout (std140) uniform SymbolDrawableTilePropsUBO {
|
||||
bool u_is_text;
|
||||
bool u_is_halo;
|
||||
bool u_pitch_with_map;
|
||||
bool u_is_size_zoom_constant;
|
||||
bool u_is_size_feature_constant;
|
||||
highp float u_size_t; // used to interpolate between zoom stops when size is a composite function
|
||||
highp float u_size; // used when size is both zoom and feature constant
|
||||
bool u_pad3;
|
||||
};
|
||||
|
||||
layout (std140) uniform SymbolDrawableInterpolateUBO {
|
||||
highp float u_fill_color_t;
|
||||
highp float u_halo_color_t;
|
||||
highp float u_opacity_t;
|
||||
highp float u_halo_width_t;
|
||||
highp float u_halo_blur_t;
|
||||
highp float u_pad4,u_pad5,u_pad6;
|
||||
};
|
||||
|
||||
uniform sampler2D u_texture;
|
||||
|
||||
in vec2 v_data0;
|
||||
in vec3 v_data1;
|
||||
|
||||
#ifndef HAS_UNIFORM_u_fill_color
|
||||
in highp vec4 fill_color;
|
||||
#endif
|
||||
#ifndef HAS_UNIFORM_u_halo_color
|
||||
in highp vec4 halo_color;
|
||||
#endif
|
||||
#ifndef HAS_UNIFORM_u_opacity
|
||||
in lowp float opacity;
|
||||
#endif
|
||||
#ifndef HAS_UNIFORM_u_halo_width
|
||||
in lowp float halo_width;
|
||||
#endif
|
||||
#ifndef HAS_UNIFORM_u_halo_blur
|
||||
in lowp float halo_blur;
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
#ifdef HAS_UNIFORM_u_fill_color
|
||||
highp vec4 fill_color = u_fill_color;
|
||||
#endif
|
||||
#ifdef HAS_UNIFORM_u_halo_color
|
||||
highp vec4 halo_color = u_halo_color;
|
||||
#endif
|
||||
#ifdef HAS_UNIFORM_u_opacity
|
||||
lowp float opacity = u_opacity;
|
||||
#endif
|
||||
#ifdef HAS_UNIFORM_u_halo_width
|
||||
lowp float halo_width = u_halo_width;
|
||||
#endif
|
||||
#ifdef HAS_UNIFORM_u_halo_blur
|
||||
lowp float halo_blur = u_halo_blur;
|
||||
#endif
|
||||
|
||||
float EDGE_GAMMA = 0.105 / u_device_pixel_ratio;
|
||||
|
||||
vec2 tex = v_data0.xy;
|
||||
float gamma_scale = v_data1.x;
|
||||
float size = v_data1.y;
|
||||
float fade_opacity = v_data1[2];
|
||||
|
||||
float fontScale = u_is_text ? size / 24.0 : size;
|
||||
|
||||
lowp vec4 color = fill_color;
|
||||
highp float gamma = EDGE_GAMMA / (fontScale * u_gamma_scale);
|
||||
lowp float buff = (256.0 - 64.0) / 256.0;
|
||||
if (u_is_halo) {
|
||||
color = halo_color;
|
||||
gamma = (halo_blur * 1.19 / SDF_PX + EDGE_GAMMA) / (fontScale * u_gamma_scale);
|
||||
buff = (6.0 - halo_width / fontScale) / SDF_PX;
|
||||
}
|
||||
|
||||
lowp float dist = texture(u_texture, tex).a;
|
||||
highp float gamma_scaled = gamma * gamma_scale;
|
||||
highp float alpha = smoothstep(buff - gamma_scaled, buff + gamma_scaled, dist);
|
||||
|
||||
fragColor = color * (alpha * opacity * fade_opacity);
|
||||
|
||||
#ifdef OVERDRAW_INSPECTOR
|
||||
fragColor = vec4(1.0);
|
||||
#endif
|
||||
}
|
||||
)";
|
||||
};
|
||||
|
||||
} // namespace shaders
|
||||
} // namespace mbgl
|
||||
@@ -29,7 +29,8 @@ layout (std140) uniform GlobalPaintParamsUBO {
|
||||
highp float u_symbol_fade_change;
|
||||
highp float u_aspect_ratio;
|
||||
highp float u_pixel_ratio;
|
||||
highp float global_pad1, global_pad2;
|
||||
highp float u_map_zoom;
|
||||
lowp float global_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform SymbolDrawableUBO {
|
||||
@@ -40,29 +41,21 @@ layout (std140) uniform SymbolDrawableUBO {
|
||||
highp vec2 u_texsize;
|
||||
highp vec2 u_texsize_icon;
|
||||
|
||||
highp float u_gamma_scale;
|
||||
bool u_is_text_prop;
|
||||
bool u_rotate_symbol;
|
||||
highp vec2 drawable_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform SymbolTilePropsUBO {
|
||||
bool u_is_text;
|
||||
bool u_is_halo;
|
||||
bool u_pitch_with_map;
|
||||
bool u_is_size_zoom_constant;
|
||||
bool u_is_size_feature_constant;
|
||||
|
||||
highp float u_size_t; // used to interpolate between zoom stops when size is a composite function
|
||||
highp float u_size; // used when size is both zoom and feature constant
|
||||
bool tileprops_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform SymbolInterpolateUBO {
|
||||
// Interpolations
|
||||
highp float u_fill_color_t;
|
||||
highp float u_halo_color_t;
|
||||
highp float u_opacity_t;
|
||||
highp float u_halo_width_t;
|
||||
highp float u_halo_blur_t;
|
||||
highp float interp_pad1, interp_pad2, interp_pad3;
|
||||
};
|
||||
|
||||
layout (std140) uniform SymbolEvaluatedPropsUBO {
|
||||
@@ -71,13 +64,13 @@ layout (std140) uniform SymbolEvaluatedPropsUBO {
|
||||
highp float u_text_opacity;
|
||||
highp float u_text_halo_width;
|
||||
highp float u_text_halo_blur;
|
||||
highp float props_pad1;
|
||||
lowp float props_pad1;
|
||||
highp vec4 u_icon_fill_color;
|
||||
highp vec4 u_icon_halo_color;
|
||||
highp float u_icon_opacity;
|
||||
highp float u_icon_halo_width;
|
||||
highp float u_icon_halo_blur;
|
||||
highp float props_pad2;
|
||||
lowp float props_pad2;
|
||||
};
|
||||
|
||||
out vec4 v_data0;
|
||||
@@ -105,11 +98,11 @@ out lowp float halo_blur;
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
highp vec4 u_fill_color = u_is_text ? u_text_fill_color : u_icon_fill_color;
|
||||
highp vec4 u_halo_color = u_is_text ? u_text_halo_color : u_icon_halo_color;
|
||||
highp float u_opacity = u_is_text ? u_text_opacity : u_icon_opacity;
|
||||
highp float u_halo_width = u_is_text ? u_text_halo_width : u_icon_halo_width;
|
||||
highp float u_halo_blur = u_is_text ? u_text_halo_blur : u_icon_halo_blur;
|
||||
highp vec4 u_fill_color = u_is_text_prop ? u_text_fill_color : u_icon_fill_color;
|
||||
highp vec4 u_halo_color = u_is_text_prop ? u_text_halo_color : u_icon_halo_color;
|
||||
highp float u_opacity = u_is_text_prop ? u_text_opacity : u_icon_opacity;
|
||||
highp float u_halo_width = u_is_text_prop ? u_text_halo_width : u_icon_halo_width;
|
||||
highp float u_halo_blur = u_is_text_prop ? u_text_halo_blur : u_icon_halo_blur;
|
||||
|
||||
#ifndef HAS_UNIFORM_u_fill_color
|
||||
fill_color = unpack_mix_color(a_fill_color, u_fill_color_t);
|
||||
@@ -212,28 +205,11 @@ lowp float halo_blur = u_halo_blur;
|
||||
#define SDF 1.0
|
||||
#define ICON 0.0
|
||||
|
||||
layout (std140) uniform SymbolDrawableUBO {
|
||||
highp mat4 u_matrix;
|
||||
highp mat4 u_label_plane_matrix;
|
||||
highp mat4 u_coord_matrix;
|
||||
|
||||
highp vec2 u_texsize;
|
||||
highp vec2 u_texsize_icon;
|
||||
|
||||
highp float u_gamma_scale;
|
||||
bool u_rotate_symbol;
|
||||
highp vec2 drawable_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform SymbolTilePropsUBO {
|
||||
bool u_is_text;
|
||||
bool u_is_halo;
|
||||
bool u_pitch_with_map;
|
||||
bool u_is_size_zoom_constant;
|
||||
bool u_is_size_feature_constant;
|
||||
highp float u_size_t; // used to interpolate between zoom stops when size is a composite function
|
||||
highp float u_size; // used when size is both zoom and feature constant
|
||||
bool tileprops_pad1;
|
||||
highp float u_gamma_scale;
|
||||
lowp float tileprops_pad1;
|
||||
};
|
||||
|
||||
layout (std140) uniform SymbolEvaluatedPropsUBO {
|
||||
@@ -242,13 +218,13 @@ layout (std140) uniform SymbolEvaluatedPropsUBO {
|
||||
highp float u_text_opacity;
|
||||
highp float u_text_halo_width;
|
||||
highp float u_text_halo_blur;
|
||||
highp float props_pad1;
|
||||
lowp float props_pad1;
|
||||
highp vec4 u_icon_fill_color;
|
||||
highp vec4 u_icon_halo_color;
|
||||
highp float u_icon_opacity;
|
||||
highp float u_icon_halo_width;
|
||||
highp float u_icon_halo_blur;
|
||||
highp float props_pad2;
|
||||
lowp float props_pad2;
|
||||
};
|
||||
|
||||
uniform sampler2D u_texture;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/gl/context.hpp>
|
||||
#include <mbgl/gl/uniform_block_gl.hpp>
|
||||
#include <mbgl/gl/vertex_attribute_gl.hpp>
|
||||
#include <mbgl/shaders/shader_source.hpp>
|
||||
#include <mbgl/shaders/shader_program_base.hpp>
|
||||
@@ -20,10 +19,7 @@ public:
|
||||
using SamplerLocationArray = std::array<std::optional<size_t>, shaders::maxTextureCountPerShader>;
|
||||
|
||||
ShaderProgramGL(UniqueProgram&& glProgram_);
|
||||
ShaderProgramGL(UniqueProgram&&,
|
||||
UniformBlockArrayGL&& uniformBlocks,
|
||||
VertexAttributeArrayGL&& attributes,
|
||||
SamplerLocationArray&& samplerLocations);
|
||||
ShaderProgramGL(UniqueProgram&&, VertexAttributeArrayGL&& attributes, SamplerLocationArray&& samplerLocations);
|
||||
ShaderProgramGL(ShaderProgramGL&& other);
|
||||
~ShaderProgramGL() noexcept override = default;
|
||||
|
||||
@@ -42,21 +38,15 @@ public:
|
||||
|
||||
std::optional<size_t> getSamplerLocation(const size_t id) const override;
|
||||
|
||||
const gfx::UniformBlockArray& getUniformBlocks() const override { return uniformBlocks; }
|
||||
|
||||
const gfx::VertexAttributeArray& getVertexAttributes() const override { return vertexAttributes; }
|
||||
|
||||
const gfx::VertexAttributeArray& getInstanceAttributes() const override { return instanceAttributes; }
|
||||
|
||||
ProgramID getGLProgramID() const { return glProgram; }
|
||||
|
||||
protected:
|
||||
gfx::UniformBlockArray& mutableUniformBlocks() override { return uniformBlocks; }
|
||||
|
||||
protected:
|
||||
UniqueProgram glProgram;
|
||||
|
||||
UniformBlockArrayGL uniformBlocks;
|
||||
VertexAttributeArrayGL vertexAttributes;
|
||||
VertexAttributeArrayGL instanceAttributes;
|
||||
SamplerLocationArray samplerLocations;
|
||||
|
||||
@@ -6,26 +6,26 @@ namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
struct alignas(16) HeatmapDrawableUBO {
|
||||
std::array<float, 4 * 4> matrix;
|
||||
float extrude_scale;
|
||||
std::array<float, 3> padding;
|
||||
};
|
||||
static_assert(sizeof(HeatmapDrawableUBO) % 16 == 0);
|
||||
/* 0 */ std::array<float, 4 * 4> matrix;
|
||||
/* 64 */ float extrude_scale;
|
||||
|
||||
// Interpolations
|
||||
/* 68 */ float weight_t;
|
||||
/* 72 */ float radius_t;
|
||||
/* 76 */ float pad1;
|
||||
/* 80 */
|
||||
};
|
||||
static_assert(sizeof(HeatmapDrawableUBO) == 5 * 16);
|
||||
|
||||
/// Evaluated properties that do not depend on the tile
|
||||
struct alignas(16) HeatmapEvaluatedPropsUBO {
|
||||
float weight;
|
||||
float radius;
|
||||
float intensity;
|
||||
float padding;
|
||||
/* 0 */ float weight;
|
||||
/* 4 */ float radius;
|
||||
/* 8 */ float intensity;
|
||||
/* 12 */ float padding;
|
||||
/* 16 */
|
||||
};
|
||||
static_assert(sizeof(HeatmapEvaluatedPropsUBO) % 16 == 0);
|
||||
|
||||
struct alignas(16) HeatmapInterpolateUBO {
|
||||
float weight_t;
|
||||
float radius_t;
|
||||
std::array<float, 2> padding;
|
||||
};
|
||||
static_assert(sizeof(HeatmapInterpolateUBO) % 16 == 0);
|
||||
static_assert(sizeof(HeatmapEvaluatedPropsUBO) == 16);
|
||||
|
||||
} // namespace shaders
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -6,11 +6,14 @@ namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
struct alignas(16) HeatmapTexturePropsUBO {
|
||||
std::array<float, 4 * 4> matrix;
|
||||
float opacity;
|
||||
float pad1, pad2, pad3;
|
||||
/* 0 */ std::array<float, 4 * 4> matrix;
|
||||
/* 64 */ float opacity;
|
||||
/* 68 */ float pad1;
|
||||
/* 72 */ float pad2;
|
||||
/* 76 */ float pad3;
|
||||
/* 80 */
|
||||
};
|
||||
static_assert(sizeof(HeatmapTexturePropsUBO) % 16 == 0);
|
||||
static_assert(sizeof(HeatmapTexturePropsUBO) == 5 * 16);
|
||||
|
||||
} // namespace shaders
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -6,18 +6,26 @@ namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
struct alignas(16) HillshadeDrawableUBO {
|
||||
std::array<float, 4 * 4> matrix;
|
||||
std::array<float, 2> latrange;
|
||||
std::array<float, 2> light;
|
||||
/* 0 */ std::array<float, 4 * 4> matrix;
|
||||
/* 64 */
|
||||
};
|
||||
static_assert(sizeof(HillshadeDrawableUBO) == 16 * 5);
|
||||
static_assert(sizeof(HillshadeDrawableUBO) == 4 * 16);
|
||||
|
||||
struct alignas(16) HillshadeEvaluatedPropsUBO {
|
||||
Color highlight;
|
||||
Color shadow;
|
||||
Color accent;
|
||||
struct alignas(16) HillshadeTilePropsUBO {
|
||||
/* 0 */ std::array<float, 2> latrange;
|
||||
/* 8 */ std::array<float, 2> light;
|
||||
/* 16 */
|
||||
};
|
||||
static_assert(sizeof(HillshadeEvaluatedPropsUBO) % 16 == 0);
|
||||
static_assert(sizeof(HillshadeTilePropsUBO) == 16);
|
||||
|
||||
/// Evaluated properties that do not depend on the tile
|
||||
struct alignas(16) HillshadeEvaluatedPropsUBO {
|
||||
/* 0 */ Color highlight;
|
||||
/* 16 */ Color shadow;
|
||||
/* 32 */ Color accent;
|
||||
/* 48 */
|
||||
};
|
||||
static_assert(sizeof(HillshadeEvaluatedPropsUBO) == 3 * 16);
|
||||
|
||||
} // namespace shaders
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -6,13 +6,19 @@ namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
struct alignas(16) HillshadePrepareDrawableUBO {
|
||||
std::array<float, 4 * 4> matrix;
|
||||
std::array<float, 4> unpack;
|
||||
std::array<float, 2> dimension;
|
||||
float zoom;
|
||||
float maxzoom;
|
||||
/* 0 */ std::array<float, 4 * 4> matrix;
|
||||
/* 64 */
|
||||
};
|
||||
static_assert(sizeof(HillshadePrepareDrawableUBO) % 16 == 0);
|
||||
static_assert(sizeof(HillshadePrepareDrawableUBO) == 4 * 16);
|
||||
|
||||
struct alignas(16) HillshadePrepareTilePropsUBO {
|
||||
/* 0 */ std::array<float, 4> unpack;
|
||||
/* 16 */ std::array<float, 2> dimension;
|
||||
/* 24 */ float zoom;
|
||||
/* 28 */ float maxzoom;
|
||||
/* 32 */
|
||||
};
|
||||
static_assert(sizeof(HillshadePrepareTilePropsUBO) == 2 * 16);
|
||||
|
||||
} // namespace shaders
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -37,25 +37,45 @@ static_assert(sizeof(Attribute) == 8);
|
||||
// Global UBOs
|
||||
|
||||
struct alignas(16) GlobalPaintParamsUBO {
|
||||
std::array<float, 2> pattern_atlas_texsize;
|
||||
std::array<float, 2> units_to_pixels;
|
||||
std::array<float, 2> world_size;
|
||||
float camera_to_center_distance;
|
||||
float symbol_fade_change;
|
||||
float aspect_ratio;
|
||||
float pixel_ratio;
|
||||
float zoom;
|
||||
float pad1;
|
||||
/* 0 */ std::array<float, 2> pattern_atlas_texsize;
|
||||
/* 8 */ std::array<float, 2> units_to_pixels;
|
||||
/* 16 */ std::array<float, 2> world_size;
|
||||
/* 24 */ float camera_to_center_distance;
|
||||
/* 28 */ float symbol_fade_change;
|
||||
/* 32 */ float aspect_ratio;
|
||||
/* 36 */ float pixel_ratio;
|
||||
/* 40 */ float map_zoom;
|
||||
/* 44 */ float pad1;
|
||||
/* 48 */
|
||||
};
|
||||
static_assert(sizeof(GlobalPaintParamsUBO) == 3 * 16);
|
||||
|
||||
#if MLN_RENDER_BACKEND_VULKAN
|
||||
struct alignas(16) GlobalPlatformParamsUBO {
|
||||
/* 0 */ alignas(16) std::array<float, 2> rotation0;
|
||||
/* 16 */ alignas(16) std::array<float, 2> rotation1;
|
||||
/* 32 */
|
||||
};
|
||||
static_assert(sizeof(GlobalPlatformParamsUBO) == 2 * 16);
|
||||
#endif
|
||||
|
||||
enum {
|
||||
idGlobalPaintParamsUBO,
|
||||
#if MLN_RENDER_BACKEND_VULKAN
|
||||
PlatformParamsUBO,
|
||||
#if MLN_RENDER_BACKEND_METAL
|
||||
idGlobalUBOIndex,
|
||||
#elif MLN_RENDER_BACKEND_VULKAN
|
||||
idGlobalPlatformParamsUBO,
|
||||
#endif
|
||||
globalUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idDrawableReservedVertexOnlyUBO = globalUBOCount,
|
||||
idDrawableReservedFragmentOnlyUBO,
|
||||
drawableReservedUBOCount
|
||||
};
|
||||
|
||||
#define MLN_UBO_CONSOLIDATION (MLN_RENDER_BACKEND_METAL || MLN_RENDER_BACKEND_VULKAN)
|
||||
|
||||
} // namespace shaders
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -11,6 +11,109 @@
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
//
|
||||
// Line
|
||||
|
||||
struct alignas(16) LineDrawableUBO {
|
||||
/* 0 */ std::array<float, 4 * 4> matrix;
|
||||
/* 64 */ float ratio;
|
||||
|
||||
// Interpolations
|
||||
/* 68 */ float color_t;
|
||||
/* 72 */ float blur_t;
|
||||
/* 76 */ float opacity_t;
|
||||
/* 80 */ float gapwidth_t;
|
||||
/* 84 */ float offset_t;
|
||||
/* 88 */ float width_t;
|
||||
/* 92 */ float pad1;
|
||||
/* 96 */
|
||||
};
|
||||
static_assert(sizeof(LineDrawableUBO) == 6 * 16);
|
||||
|
||||
//
|
||||
// Line gradient
|
||||
|
||||
struct alignas(16) LineGradientDrawableUBO {
|
||||
/* 0 */ std::array<float, 4 * 4> matrix;
|
||||
/* 64 */ float ratio;
|
||||
|
||||
// Interpolations
|
||||
/* 68 */ float blur_t;
|
||||
/* 72 */ float opacity_t;
|
||||
/* 76 */ float gapwidth_t;
|
||||
/* 80 */ float offset_t;
|
||||
/* 84 */ float width_t;
|
||||
/* 88 */ float pad1;
|
||||
/* 92 */ float pad2;
|
||||
/* 96 */
|
||||
};
|
||||
static_assert(sizeof(LineGradientDrawableUBO) == 6 * 16);
|
||||
|
||||
//
|
||||
// Line pattern
|
||||
|
||||
struct alignas(16) LinePatternDrawableUBO {
|
||||
/* 0 */ std::array<float, 4 * 4> matrix;
|
||||
/* 64 */ float ratio;
|
||||
|
||||
// Interpolations
|
||||
/* 68 */ float blur_t;
|
||||
/* 72 */ float opacity_t;
|
||||
/* 76 */ float gapwidth_t;
|
||||
/* 80 */ float offset_t;
|
||||
/* 84 */ float width_t;
|
||||
/* 88 */ float pattern_from_t;
|
||||
/* 92 */ float pattern_to_t;
|
||||
/* 96 */
|
||||
};
|
||||
static_assert(sizeof(LinePatternDrawableUBO) == 6 * 16);
|
||||
|
||||
struct alignas(16) LinePatternTilePropsUBO {
|
||||
/* 0 */ std::array<float, 4> pattern_from;
|
||||
/* 16 */ std::array<float, 4> pattern_to;
|
||||
/* 32 */ std::array<float, 4> scale;
|
||||
/* 48 */ std::array<float, 2> texsize;
|
||||
/* 56 */ float fade;
|
||||
/* 60 */ float pad1;
|
||||
/* 64 */
|
||||
};
|
||||
static_assert(sizeof(LinePatternTilePropsUBO) == 4 * 16);
|
||||
|
||||
//
|
||||
// Line SDF
|
||||
|
||||
struct alignas(16) LineSDFDrawableUBO {
|
||||
/* 0 */ std::array<float, 4 * 4> matrix;
|
||||
/* 64 */ std::array<float, 2> patternscale_a;
|
||||
/* 72 */ std::array<float, 2> patternscale_b;
|
||||
/* 80 */ float tex_y_a;
|
||||
/* 84 */ float tex_y_b;
|
||||
/* 88 */ float ratio;
|
||||
|
||||
// Interpolations
|
||||
/* 92 */ float color_t;
|
||||
/* 96 */ float blur_t;
|
||||
/* 100 */ float opacity_t;
|
||||
/* 104 */ float gapwidth_t;
|
||||
/* 108 */ float offset_t;
|
||||
/* 112 */ float width_t;
|
||||
/* 116 */ float floorwidth_t;
|
||||
/* 120 */ float pad1;
|
||||
/* 124 */ float pad2;
|
||||
/* 128 */
|
||||
};
|
||||
static_assert(sizeof(LineSDFDrawableUBO) == 8 * 16);
|
||||
|
||||
struct alignas(16) LineSDFTilePropsUBO {
|
||||
/* 0 */ float sdfgamma;
|
||||
/* 4 */ float mix;
|
||||
/* 8 */ float pad1;
|
||||
/* 12 */ float pad2;
|
||||
/* 16 */
|
||||
};
|
||||
static_assert(sizeof(LineSDFTilePropsUBO) == 16);
|
||||
|
||||
/// Expression properties that do not depend on the tile
|
||||
enum class LineExpressionMask : uint32_t {
|
||||
None = 0,
|
||||
Color = 1 << 0,
|
||||
@@ -22,27 +125,6 @@ enum class LineExpressionMask : uint32_t {
|
||||
Offset = 1 << 6,
|
||||
};
|
||||
|
||||
//
|
||||
// Line
|
||||
|
||||
struct alignas(16) LineDrawableUBO {
|
||||
std::array<float, 4 * 4> matrix;
|
||||
float ratio;
|
||||
float pad1, pad2, pad3;
|
||||
};
|
||||
static_assert(sizeof(LineDrawableUBO) % 16 == 0);
|
||||
|
||||
struct alignas(16) LineInterpolationUBO {
|
||||
float color_t;
|
||||
float blur_t;
|
||||
float opacity_t;
|
||||
float gapwidth_t;
|
||||
float offset_t;
|
||||
float width_t;
|
||||
float pad1, pad2;
|
||||
};
|
||||
static_assert(sizeof(LineInterpolationUBO) % 16 == 0);
|
||||
|
||||
struct alignas(16) LineExpressionUBO {
|
||||
gfx::GPUExpression color;
|
||||
gfx::GPUExpression blur;
|
||||
@@ -54,94 +136,36 @@ struct alignas(16) LineExpressionUBO {
|
||||
};
|
||||
static_assert(sizeof(LineExpressionUBO) % 16 == 0);
|
||||
|
||||
//
|
||||
// Line gradient
|
||||
|
||||
using LineGradientDrawableUBO = LineDrawableUBO;
|
||||
|
||||
struct alignas(16) LineGradientInterpolationUBO {
|
||||
float blur_t;
|
||||
float opacity_t;
|
||||
float gapwidth_t;
|
||||
float offset_t;
|
||||
float width_t;
|
||||
float pad1, pad2, pad3;
|
||||
};
|
||||
static_assert(sizeof(LineGradientInterpolationUBO) % 16 == 0);
|
||||
|
||||
//
|
||||
// Line pattern
|
||||
|
||||
struct alignas(16) LinePatternDrawableUBO {
|
||||
std::array<float, 4 * 4> matrix;
|
||||
std::array<float, 4> scale;
|
||||
std::array<float, 2> texsize;
|
||||
float ratio;
|
||||
float fade;
|
||||
};
|
||||
static_assert(sizeof(LinePatternDrawableUBO) % 16 == 0);
|
||||
|
||||
struct alignas(16) LinePatternInterpolationUBO {
|
||||
float blur_t;
|
||||
float opacity_t;
|
||||
float offset_t;
|
||||
float gapwidth_t;
|
||||
float width_t;
|
||||
float pattern_from_t;
|
||||
float pattern_to_t;
|
||||
float pad1;
|
||||
};
|
||||
static_assert(sizeof(LinePatternInterpolationUBO) % 16 == 0);
|
||||
|
||||
struct alignas(16) LinePatternTilePropertiesUBO {
|
||||
std::array<float, 4> pattern_from;
|
||||
std::array<float, 4> pattern_to;
|
||||
};
|
||||
static_assert(sizeof(LinePatternTilePropertiesUBO) % 16 == 0);
|
||||
|
||||
//
|
||||
// Line SDF
|
||||
|
||||
struct alignas(16) LineSDFDrawableUBO {
|
||||
std::array<float, 4 * 4> matrix;
|
||||
std::array<float, 2> patternscale_a;
|
||||
std::array<float, 2> patternscale_b;
|
||||
float ratio;
|
||||
float tex_y_a;
|
||||
float tex_y_b;
|
||||
float sdfgamma;
|
||||
float mix;
|
||||
float pad1, pad2, pad3;
|
||||
};
|
||||
static_assert(sizeof(LineSDFDrawableUBO) % 16 == 0);
|
||||
|
||||
struct alignas(16) LineSDFInterpolationUBO {
|
||||
float color_t;
|
||||
float blur_t;
|
||||
float opacity_t;
|
||||
float gapwidth_t;
|
||||
float offset_t;
|
||||
float width_t;
|
||||
float floorwidth_t;
|
||||
float pad1;
|
||||
};
|
||||
static_assert(sizeof(LineSDFInterpolationUBO) % 16 == 0);
|
||||
|
||||
//
|
||||
// Line evaluated properties
|
||||
|
||||
/// Evaluated properties that do not depend on the tile
|
||||
struct alignas(16) LineEvaluatedPropsUBO {
|
||||
Color color;
|
||||
float blur;
|
||||
float opacity;
|
||||
float gapwidth;
|
||||
float offset;
|
||||
float width;
|
||||
float floorwidth;
|
||||
LineExpressionMask expressionMask;
|
||||
float pad1;
|
||||
/* 0 */ Color color;
|
||||
/* 16 */ float blur;
|
||||
/* 20 */ float opacity;
|
||||
/* 24 */ float gapwidth;
|
||||
/* 28 */ float offset;
|
||||
/* 32 */ float width;
|
||||
/* 36 */ float floorwidth;
|
||||
/* 40 */ LineExpressionMask expressionMask;
|
||||
/* 44 */ float pad1;
|
||||
/* 48 */
|
||||
};
|
||||
static_assert(sizeof(LineEvaluatedPropsUBO) % 16 == 0);
|
||||
static_assert(sizeof(LineEvaluatedPropsUBO) == 3 * 16);
|
||||
|
||||
#if MLN_UBO_CONSOLIDATION
|
||||
|
||||
union LineDrawableUnionUBO {
|
||||
LineDrawableUBO lineDrawableUBO;
|
||||
LineGradientDrawableUBO lineGradientDrawableUBO;
|
||||
LinePatternDrawableUBO linePatternDrawableUBO;
|
||||
LineSDFDrawableUBO lineSDFDrawableUBO;
|
||||
};
|
||||
|
||||
union LineTilePropsUnionUBO {
|
||||
LinePatternTilePropsUBO linePatternTilePropsUBO;
|
||||
LineSDFTilePropsUBO lineSDFTilePropsUBO;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace shaders
|
||||
} // namespace mbgl
|
||||
|
||||
16
include/mbgl/shaders/location_indicator_ubo.hpp
Normal file
16
include/mbgl/shaders/location_indicator_ubo.hpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/shaders/layer_ubo.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
struct alignas(16) LocationIndicatorDrawableUBO {
|
||||
/* 0 */ std::array<float, 4 * 4> matrix;
|
||||
/* 64 */ Color color;
|
||||
/* 80 */
|
||||
};
|
||||
static_assert(sizeof(LocationIndicatorDrawableUBO) == 5 * 16);
|
||||
|
||||
} // namespace shaders
|
||||
} // namespace mbgl
|
||||
@@ -2,58 +2,189 @@
|
||||
|
||||
#include <mbgl/shaders/shader_source.hpp>
|
||||
#include <mbgl/shaders/background_layer_ubo.hpp>
|
||||
#include <mbgl/shaders/mtl/common.hpp>
|
||||
#include <mbgl/shaders/mtl/shader_program.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
#define BACKGROUND_SHADER_COMMON \
|
||||
R"(
|
||||
|
||||
enum {
|
||||
idBackgroundDrawableUBO = idDrawableReservedVertexOnlyUBO,
|
||||
idBackgroundPropsUBO = drawableReservedUBOCount,
|
||||
backgroundUBOCount
|
||||
};
|
||||
|
||||
//
|
||||
// Background
|
||||
|
||||
struct alignas(16) BackgroundDrawableUBO {
|
||||
/* 0 */ float4x4 matrix;
|
||||
/* 64 */
|
||||
};
|
||||
static_assert(sizeof(BackgroundDrawableUBO) == 4 * 16, "wrong size");
|
||||
|
||||
/// Evaluated properties that do not depend on the tile
|
||||
struct alignas(16) BackgroundPropsUBO {
|
||||
/* 0 */ float4 color;
|
||||
/* 16 */ float opacity;
|
||||
/* 20 */ float pad1;
|
||||
/* 24 */ float pad2;
|
||||
/* 28 */ float pad3;
|
||||
/* 32 */
|
||||
};
|
||||
static_assert(sizeof(BackgroundPropsUBO) == 2 * 16, "wrong size");
|
||||
|
||||
//
|
||||
// Background pattern
|
||||
|
||||
struct alignas(16) BackgroundPatternDrawableUBO {
|
||||
/* 0 */ float4x4 matrix;
|
||||
/* 64 */ float2 pixel_coord_upper;
|
||||
/* 72 */ float2 pixel_coord_lower;
|
||||
/* 80 */ float tile_units_to_pixels;
|
||||
/* 84 */ float pad1;
|
||||
/* 88 */ float pad2;
|
||||
/* 92 */ float pad3;
|
||||
/* 96 */
|
||||
};
|
||||
static_assert(sizeof(BackgroundPatternDrawableUBO) == 6 * 16, "wrong size");
|
||||
|
||||
/// Evaluated properties that do not depend on the tile
|
||||
struct alignas(16) BackgroundPatternPropsUBO {
|
||||
/* 0 */ float2 pattern_tl_a;
|
||||
/* 8 */ float2 pattern_br_a;
|
||||
/* 16 */ float2 pattern_tl_b;
|
||||
/* 24 */ float2 pattern_br_b;
|
||||
/* 32 */ float2 pattern_size_a;
|
||||
/* 40 */ float2 pattern_size_b;
|
||||
/* 48 */ float scale_a;
|
||||
/* 52 */ float scale_b;
|
||||
/* 56 */ float mix;
|
||||
/* 60 */ float opacity;
|
||||
/* 64 */
|
||||
};
|
||||
static_assert(sizeof(BackgroundPatternPropsUBO) == 4 * 16, "wrong size");
|
||||
|
||||
union BackgroundDrawableUnionUBO {
|
||||
BackgroundDrawableUBO backgroundDrawableUBO;
|
||||
BackgroundPatternDrawableUBO backgroundPatternDrawableUBO;
|
||||
};
|
||||
|
||||
)"
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::BackgroundShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto name = "BackgroundShader";
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static const std::array<UniformBlockInfo, 2> uniforms;
|
||||
static const std::array<AttributeInfo, 1> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static const std::array<TextureInfo, 0> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
static constexpr auto source = BACKGROUND_SHADER_COMMON R"(
|
||||
#include <metal_stdlib>
|
||||
using namespace metal;
|
||||
|
||||
struct VertexStage {
|
||||
short2 position [[attribute(3)]];
|
||||
short2 position [[attribute(backgroundUBOCount + 0)]];
|
||||
};
|
||||
|
||||
struct FragmentStage {
|
||||
float4 position [[position, invariant]];
|
||||
};
|
||||
|
||||
struct alignas(16) BackgroundDrawableUBO {
|
||||
float4x4 matrix;
|
||||
};
|
||||
struct alignas(16) BackgroundLayerUBO {
|
||||
float4 color;
|
||||
float opacity;
|
||||
float pad1, pad2, pad3;
|
||||
};
|
||||
|
||||
FragmentStage vertex vertexMain(VertexStage in [[stage_in]],
|
||||
device const BackgroundDrawableUBO& drawableUBO [[buffer(1)]]) {
|
||||
device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]],
|
||||
device const BackgroundDrawableUnionUBO* drawableVector [[buffer(idBackgroundDrawableUBO)]]) {
|
||||
|
||||
device const BackgroundDrawableUBO& drawable = drawableVector[uboIndex].backgroundDrawableUBO;
|
||||
|
||||
return {
|
||||
.position = drawableUBO.matrix * float4(float2(in.position.xy), 0, 1)
|
||||
.position = drawable.matrix * float4(float2(in.position.xy), 0, 1)
|
||||
};
|
||||
}
|
||||
|
||||
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
|
||||
device const BackgroundLayerUBO& layerUBO [[buffer(2)]]) {
|
||||
device const BackgroundPropsUBO& props [[buffer(idBackgroundPropsUBO)]]) {
|
||||
#if defined(OVERDRAW_INSPECTOR)
|
||||
return half4(1.0);
|
||||
#endif
|
||||
|
||||
return half4(layerUBO.color * layerUBO.opacity);
|
||||
return half4(props.color * props.opacity);
|
||||
}
|
||||
)";
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::BackgroundPatternShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto name = "BackgroundPatternShader";
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static const std::array<AttributeInfo, 1> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static const std::array<TextureInfo, 1> textures;
|
||||
|
||||
static constexpr auto source = BACKGROUND_SHADER_COMMON R"(
|
||||
#include <metal_stdlib>
|
||||
using namespace metal;
|
||||
|
||||
struct VertexStage {
|
||||
short2 position [[attribute(backgroundUBOCount + 0)]];
|
||||
};
|
||||
|
||||
struct FragmentStage {
|
||||
float4 position [[position, invariant]];
|
||||
float2 pos_a;
|
||||
float2 pos_b;
|
||||
};
|
||||
|
||||
FragmentStage vertex vertexMain(VertexStage in [[stage_in]],
|
||||
device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]],
|
||||
device const BackgroundDrawableUnionUBO* drawableVector [[buffer(idBackgroundDrawableUBO)]],
|
||||
device const BackgroundPatternPropsUBO& props [[buffer(idBackgroundPropsUBO)]]) {
|
||||
|
||||
device const BackgroundPatternDrawableUBO& drawable = drawableVector[uboIndex].backgroundPatternDrawableUBO;
|
||||
|
||||
const float2 pos = float2(in.position);
|
||||
const float2 pos_a = get_pattern_pos(drawable.pixel_coord_upper,
|
||||
drawable.pixel_coord_lower,
|
||||
props.scale_a * props.pattern_size_a,
|
||||
drawable.tile_units_to_pixels,
|
||||
pos);
|
||||
const float2 pos_b = get_pattern_pos(drawable.pixel_coord_upper,
|
||||
drawable.pixel_coord_lower,
|
||||
props.scale_b * props.pattern_size_b,
|
||||
drawable.tile_units_to_pixels,
|
||||
pos);
|
||||
return {
|
||||
.position = drawable.matrix * float4(float2(in.position.xy), 0, 1),
|
||||
.pos_a = pos_a,
|
||||
.pos_b = pos_b,
|
||||
};
|
||||
}
|
||||
|
||||
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
|
||||
device const GlobalPaintParamsUBO& paintParamsUBO [[buffer(idGlobalPaintParamsUBO)]],
|
||||
device const BackgroundPatternPropsUBO& props [[buffer(idBackgroundPropsUBO)]],
|
||||
texture2d<float, access::sample> image [[texture(0)]],
|
||||
sampler image_sampler [[sampler(0)]]) {
|
||||
#if defined(OVERDRAW_INSPECTOR)
|
||||
return half4(1.0);
|
||||
#endif
|
||||
|
||||
const float2 texsize = paintParamsUBO.pattern_atlas_texsize;
|
||||
const float2 imagecoord = glMod(float2(in.pos_a), 1.0);
|
||||
const float2 pos = mix(props.pattern_tl_a / texsize, props.pattern_br_a / texsize, imagecoord);
|
||||
const float4 color1 = image.sample(image_sampler, pos);
|
||||
const float2 imagecoord_b = glMod(float2(in.pos_b), 1.0);
|
||||
const float2 pos2 = mix(props.pattern_tl_b / texsize, props.pattern_br_b / texsize, imagecoord_b);
|
||||
const float4 color2 = image.sample(image_sampler, pos2);
|
||||
|
||||
return half4(mix(color1, color2, props.mix) * props.opacity);
|
||||
}
|
||||
)";
|
||||
};
|
||||
|
||||
@@ -1,97 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/shaders/mtl/background.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::BackgroundPatternShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto name = "BackgroundPatternShader";
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static const std::array<UniformBlockInfo, 3> uniforms;
|
||||
static const std::array<AttributeInfo, 1> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static const std::array<TextureInfo, 1> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
#include <metal_stdlib>
|
||||
using namespace metal;
|
||||
|
||||
struct VertexStage {
|
||||
short2 position [[attribute(3)]];
|
||||
};
|
||||
|
||||
struct FragmentStage {
|
||||
float4 position [[position, invariant]];
|
||||
float2 pos_a;
|
||||
float2 pos_b;
|
||||
};
|
||||
|
||||
struct alignas(16) BackgroundPatternDrawableUBO {
|
||||
float4x4 matrix;
|
||||
float2 pixel_coord_upper;
|
||||
float2 pixel_coord_lower;
|
||||
float tile_units_to_pixels;
|
||||
float pad1, pad2, pad3;
|
||||
};
|
||||
struct alignas(16) BackgroundPatternLayerUBO {
|
||||
float2 pattern_tl_a;
|
||||
float2 pattern_br_a;
|
||||
float2 pattern_tl_b;
|
||||
float2 pattern_br_b;
|
||||
float2 pattern_size_a;
|
||||
float2 pattern_size_b;
|
||||
float scale_a;
|
||||
float scale_b;
|
||||
float mix;
|
||||
float opacity;
|
||||
};
|
||||
|
||||
FragmentStage vertex vertexMain(VertexStage in [[stage_in]],
|
||||
device const BackgroundPatternDrawableUBO& drawableUBO [[buffer(1)]],
|
||||
device const BackgroundPatternLayerUBO& layerUBO [[buffer(2)]]) {
|
||||
const float2 pos = float2(in.position);
|
||||
const float2 pos_a = get_pattern_pos(drawableUBO.pixel_coord_upper,
|
||||
drawableUBO.pixel_coord_lower,
|
||||
layerUBO.scale_a * layerUBO.pattern_size_a,
|
||||
drawableUBO.tile_units_to_pixels,
|
||||
pos);
|
||||
const float2 pos_b = get_pattern_pos(drawableUBO.pixel_coord_upper,
|
||||
drawableUBO.pixel_coord_lower,
|
||||
layerUBO.scale_b * layerUBO.pattern_size_b,
|
||||
drawableUBO.tile_units_to_pixels,
|
||||
pos);
|
||||
return {
|
||||
.position = drawableUBO.matrix * float4(float2(in.position.xy), 0, 1),
|
||||
.pos_a = pos_a,
|
||||
.pos_b = pos_b,
|
||||
};
|
||||
}
|
||||
|
||||
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
|
||||
device const GlobalPaintParamsUBO& paintParamsUBO [[buffer(0)]],
|
||||
device const BackgroundPatternLayerUBO& layerUBO [[buffer(2)]],
|
||||
texture2d<float, access::sample> image [[texture(0)]],
|
||||
sampler image_sampler [[sampler(0)]]) {
|
||||
#if defined(OVERDRAW_INSPECTOR)
|
||||
return half4(1.0);
|
||||
#endif
|
||||
|
||||
const float2 texsize = paintParamsUBO.pattern_atlas_texsize;
|
||||
const float2 imagecoord = glMod(float2(in.pos_a), 1.0);
|
||||
const float2 pos = mix(layerUBO.pattern_tl_a / texsize, layerUBO.pattern_br_a / texsize, imagecoord);
|
||||
const float4 color1 = image.sample(image_sampler, pos);
|
||||
const float2 imagecoord_b = glMod(float2(in.pos_b), 1.0);
|
||||
const float2 pos2 = mix(layerUBO.pattern_tl_b / texsize, layerUBO.pattern_br_b / texsize, imagecoord_b);
|
||||
const float4 color2 = image.sample(image_sampler, pos2);
|
||||
|
||||
return half4(mix(color1, color2, layerUBO.mix) * layerUBO.opacity);
|
||||
}
|
||||
)";
|
||||
};
|
||||
|
||||
} // namespace shaders
|
||||
} // namespace mbgl
|
||||
@@ -2,47 +2,91 @@
|
||||
|
||||
#include <mbgl/shaders/circle_layer_ubo.hpp>
|
||||
#include <mbgl/shaders/shader_source.hpp>
|
||||
#include <mbgl/shaders/mtl/common.hpp>
|
||||
#include <mbgl/shaders/mtl/shader_program.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
#define CIRCLE_SHADER_PRELUDE \
|
||||
R"(
|
||||
|
||||
enum {
|
||||
idCircleDrawableUBO = idDrawableReservedVertexOnlyUBO,
|
||||
idCircleEvaluatedPropsUBO = drawableReservedUBOCount,
|
||||
circleUBOCount
|
||||
};
|
||||
|
||||
struct alignas(16) CircleDrawableUBO {
|
||||
/* 0 */ float4x4 matrix;
|
||||
/* 64 */ float2 extrude_scale;
|
||||
|
||||
// Interpolations
|
||||
/* 72 */ float color_t;
|
||||
/* 76 */ float radius_t;
|
||||
/* 80 */ float blur_t;
|
||||
/* 84 */ float opacity_t;
|
||||
/* 88 */ float stroke_color_t;
|
||||
/* 92 */ float stroke_width_t;
|
||||
/* 96 */ float stroke_opacity_t;
|
||||
/* 100 */ float pad1;
|
||||
/* 104 */ float pad2;
|
||||
/* 108 */ float pad3;
|
||||
/* 112 */
|
||||
};
|
||||
static_assert(sizeof(CircleDrawableUBO) == 7 * 16, "wrong size");
|
||||
|
||||
/// Evaluated properties that do not depend on the tile
|
||||
struct alignas(16) CircleEvaluatedPropsUBO {
|
||||
/* 0 */ float4 color;
|
||||
/* 16 */ float4 stroke_color;
|
||||
/* 32 */ float radius;
|
||||
/* 36 */ float blur;
|
||||
/* 40 */ float opacity;
|
||||
/* 44 */ float stroke_width;
|
||||
/* 48 */ float stroke_opacity;
|
||||
/* 52 */ int scale_with_map;
|
||||
/* 56 */ int pitch_with_map;
|
||||
/* 60 */ float pad1;
|
||||
/* 64 */
|
||||
};
|
||||
static_assert(sizeof(CircleEvaluatedPropsUBO) == 4 * 16, "wrong size");
|
||||
|
||||
)"
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::CircleShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto name = "CircleShader";
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static const std::array<UniformBlockInfo, 4> uniforms;
|
||||
static const std::array<AttributeInfo, 8> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static const std::array<TextureInfo, 0> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
static constexpr auto source = CIRCLE_SHADER_PRELUDE R"(
|
||||
struct VertexStage {
|
||||
short2 position [[attribute(4)]];
|
||||
short2 position [[attribute(circleUBOCount + 0)]];
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_color)
|
||||
float4 color [[attribute(5)]];
|
||||
float4 color [[attribute(circleUBOCount + 1)]];
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_radius)
|
||||
float2 radius [[attribute(6)]];
|
||||
float2 radius [[attribute(circleUBOCount + 2)]];
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_blur)
|
||||
float2 blur [[attribute(7)]];
|
||||
float2 blur [[attribute(circleUBOCount + 3)]];
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_opacity)
|
||||
float2 opacity [[attribute(8)]];
|
||||
float2 opacity [[attribute(circleUBOCount + 4)]];
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_stroke_color)
|
||||
float4 stroke_color [[attribute(9)]];
|
||||
float4 stroke_color [[attribute(circleUBOCount + 5)]];
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_stroke_width)
|
||||
float2 stroke_width [[attribute(10)]];
|
||||
float2 stroke_width [[attribute(circleUBOCount + 6)]];
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_stroke_opacity)
|
||||
float2 stroke_opacity [[attribute(11)]];
|
||||
float2 stroke_opacity [[attribute(circleUBOCount + 7)]];
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -74,55 +118,24 @@ struct FragmentStage {
|
||||
#endif
|
||||
};
|
||||
|
||||
struct alignas(16) CircleDrawableUBO {
|
||||
float4x4 matrix;
|
||||
float2 extrude_scale;
|
||||
float2 padding;
|
||||
};
|
||||
struct alignas(16) CirclePaintParamsUBO {
|
||||
float camera_to_center_distance;
|
||||
float pad1,pad2,pad3;
|
||||
};
|
||||
struct alignas(16) CircleEvaluatedPropsUBO {
|
||||
float4 color;
|
||||
float4 stroke_color;
|
||||
float radius;
|
||||
float blur;
|
||||
float opacity;
|
||||
float stroke_width;
|
||||
float stroke_opacity;
|
||||
int scale_with_map;
|
||||
int pitch_with_map;
|
||||
float padding;
|
||||
};
|
||||
|
||||
struct alignas(16) CircleInterpolateUBO {
|
||||
float color_t;
|
||||
float radius_t;
|
||||
float blur_t;
|
||||
float opacity_t;
|
||||
float stroke_color_t;
|
||||
float stroke_width_t;
|
||||
float stroke_opacity_t;
|
||||
float pad1_;
|
||||
};
|
||||
|
||||
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
device const GlobalPaintParamsUBO& paintParams [[buffer(0)]],
|
||||
device const CircleDrawableUBO& drawable [[buffer(1)]],
|
||||
device const CircleInterpolateUBO& interp [[buffer(2)]],
|
||||
device const CircleEvaluatedPropsUBO& props [[buffer(3)]]) {
|
||||
device const GlobalPaintParamsUBO& paintParams [[buffer(idGlobalPaintParamsUBO)]],
|
||||
device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]],
|
||||
device const CircleDrawableUBO* drawableVector [[buffer(idCircleDrawableUBO)]],
|
||||
device const CircleEvaluatedPropsUBO& props [[buffer(idCircleEvaluatedPropsUBO)]]) {
|
||||
|
||||
device const CircleDrawableUBO& drawable = drawableVector[uboIndex];
|
||||
|
||||
#if defined(HAS_UNIFORM_u_radius)
|
||||
const auto radius = props.radius;
|
||||
#else
|
||||
const auto radius = unpack_mix_float(vertx.radius, interp.radius_t);
|
||||
const auto radius = unpack_mix_float(vertx.radius, drawable.radius_t);
|
||||
#endif
|
||||
|
||||
#if defined(HAS_UNIFORM_u_stroke_width)
|
||||
const auto stroke_width = props.stroke_width;
|
||||
#else
|
||||
const auto stroke_width = unpack_mix_float(vertx.stroke_width, interp.stroke_width_t);
|
||||
const auto stroke_width = unpack_mix_float(vertx.stroke_width, drawable.stroke_width_t);
|
||||
#endif
|
||||
|
||||
// unencode the extrusion vector that we snuck into the a_pos vector
|
||||
@@ -165,31 +178,31 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
.antialiasblur = antialiasblur,
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_color)
|
||||
.color = half4(unpack_mix_color(vertx.color, interp.color_t)),
|
||||
.color = half4(unpack_mix_color(vertx.color, drawable.color_t)),
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_radius)
|
||||
.radius = radius,
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_blur)
|
||||
.blur = half(unpack_mix_float(vertx.blur, interp.blur_t)),
|
||||
.blur = half(unpack_mix_float(vertx.blur, drawable.blur_t)),
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_opacity)
|
||||
.opacity = half(unpack_mix_float(vertx.opacity, interp.opacity_t)),
|
||||
.opacity = half(unpack_mix_float(vertx.opacity, drawable.opacity_t)),
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_stroke_color)
|
||||
.stroke_color = half4(unpack_mix_color(vertx.stroke_color, interp.stroke_color_t)),
|
||||
.stroke_color = half4(unpack_mix_color(vertx.stroke_color, drawable.stroke_color_t)),
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_stroke_width)
|
||||
.stroke_width = half(stroke_width),
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_stroke_opacity)
|
||||
.stroke_opacity = half(unpack_mix_float(vertx.stroke_opacity, interp.stroke_opacity_t)),
|
||||
.stroke_opacity = half(unpack_mix_float(vertx.stroke_opacity, drawable.stroke_opacity_t)),
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
||||
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
|
||||
device const CircleEvaluatedPropsUBO& props [[buffer(3)]]) {
|
||||
device const CircleEvaluatedPropsUBO& props [[buffer(idCircleEvaluatedPropsUBO)]]) {
|
||||
#if defined(OVERDRAW_INSPECTOR)
|
||||
return half4(1.0);
|
||||
#endif
|
||||
|
||||
@@ -9,36 +9,49 @@ namespace shaders {
|
||||
struct alignas(16) ClipUBO {
|
||||
/* 0 */ std::array<float, 4 * 4> matrix;
|
||||
/* 64 */ std::uint32_t stencil_ref;
|
||||
/* 68 */ std::uint32_t pad1, pad2, pad3;
|
||||
/* 68 */ float pad1;
|
||||
/* 72 */ float pad2;
|
||||
/* 76 */ float pad3;
|
||||
/* 80 */
|
||||
};
|
||||
static_assert(sizeof(ClipUBO) == 5 * 16);
|
||||
|
||||
#define CLIPPING_MASK_SHADER_PRELUDE \
|
||||
R"(
|
||||
|
||||
#include <metal_stdlib>
|
||||
using namespace metal;
|
||||
|
||||
enum {
|
||||
idClippingMaskUBO = idDrawableReservedVertexOnlyUBO,
|
||||
clippingMaskUBOCount = drawableReservedUBOCount
|
||||
};
|
||||
|
||||
struct alignas(16) ClipUBO {
|
||||
/* 0 */ float4x4 matrix;
|
||||
/* 64 */ uint32_t stencil_ref;
|
||||
/* 68 */ float pad1;
|
||||
/* 72 */ float pad2;
|
||||
/* 76 */ float pad3;
|
||||
/* 80 */
|
||||
};
|
||||
static_assert(sizeof(ClipUBO) == 5 * 16, "wrong size");
|
||||
|
||||
)"
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::ClippingMaskProgram, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto name = "ClippingMaskProgram";
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static const std::array<UniformBlockInfo, 1> uniforms;
|
||||
static const std::array<AttributeInfo, 1> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static const std::array<TextureInfo, 0> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
#include <metal_stdlib>
|
||||
using namespace metal;
|
||||
|
||||
struct alignas(16) ClipUBO {
|
||||
/* 0 */ float4x4 matrix;
|
||||
/* 64 */ uint32_t stencil_ref;
|
||||
/* 68 */ uint32_t pad1, pad2, pad3;
|
||||
/* 80 */
|
||||
};
|
||||
static_assert(sizeof(ClipUBO) == 5 * 16, "unexpected padding");
|
||||
|
||||
static constexpr auto source = CLIPPING_MASK_SHADER_PRELUDE R"(
|
||||
struct VertexStage {
|
||||
short2 position [[attribute(2)]];
|
||||
short2 position [[attribute(clippingMaskUBOCount + 0)]];
|
||||
};
|
||||
|
||||
struct FragmentStage {
|
||||
@@ -51,7 +64,7 @@ struct FragmentResult {
|
||||
};
|
||||
|
||||
FragmentStage vertex vertexMain(VertexStage in [[stage_in]],
|
||||
device const ClipUBO& clipUBO [[buffer(1)]]) {
|
||||
device const ClipUBO& clipUBO [[buffer(idClippingMaskUBO)]]) {
|
||||
return { clipUBO.matrix * float4(float2(in.position.xy), 0, 1) };
|
||||
}
|
||||
|
||||
|
||||
202
include/mbgl/shaders/mtl/collision.hpp
Normal file
202
include/mbgl/shaders/mtl/collision.hpp
Normal file
@@ -0,0 +1,202 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/shaders/collision_layer_ubo.hpp>
|
||||
#include <mbgl/shaders/shader_source.hpp>
|
||||
#include <mbgl/shaders/mtl/shader_program.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
#define COLLISION_SHADER_COMMON \
|
||||
R"(
|
||||
|
||||
enum {
|
||||
idCollisionDrawableUBO = idDrawableReservedVertexOnlyUBO,
|
||||
idCollisionTilePropsUBO = drawableReservedUBOCount,
|
||||
collisionUBOCount
|
||||
};
|
||||
|
||||
struct alignas(16) CollisionDrawableUBO {
|
||||
/* 0 */ float4x4 matrix;
|
||||
/* 64 */
|
||||
};
|
||||
static_assert(sizeof(CollisionDrawableUBO) == 4 * 16, "wrong size");
|
||||
|
||||
struct alignas(16) CollisionTilePropsUBO {
|
||||
/* 0 */ float2 extrude_scale;
|
||||
/* 8 */ float overscale_factor;
|
||||
/* 12 */ float pad1;
|
||||
/* 16 */
|
||||
};
|
||||
static_assert(sizeof(CollisionTilePropsUBO) == 16, "wrong size");
|
||||
|
||||
)"
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::CollisionBoxShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto name = "CollisionBoxShader";
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static const std::array<AttributeInfo, 5> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static const std::array<TextureInfo, 0> textures;
|
||||
|
||||
static constexpr auto source = COLLISION_SHADER_COMMON R"(
|
||||
|
||||
struct VertexStage {
|
||||
short2 pos [[attribute(collisionUBOCount + 0)]];
|
||||
short2 anchor_pos [[attribute(collisionUBOCount + 1)]];
|
||||
short2 extrude [[attribute(collisionUBOCount + 2)]];
|
||||
ushort2 placed [[attribute(collisionUBOCount + 3)]];
|
||||
float2 shift [[attribute(collisionUBOCount + 4)]];
|
||||
};
|
||||
|
||||
struct FragmentStage {
|
||||
float4 position [[position, invariant]];
|
||||
float placed;
|
||||
float notUsed;
|
||||
};
|
||||
|
||||
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
device const GlobalPaintParamsUBO& paintParams [[buffer(idGlobalPaintParamsUBO)]],
|
||||
device const CollisionDrawableUBO& drawable [[buffer(idCollisionDrawableUBO)]],
|
||||
device const CollisionTilePropsUBO& tileProps [[buffer(idCollisionTilePropsUBO)]]) {
|
||||
|
||||
float4 projectedPoint = drawable.matrix * float4(float2(vertx.anchor_pos), 0, 1);
|
||||
float camera_to_anchor_distance = projectedPoint.w;
|
||||
float collision_perspective_ratio = clamp(
|
||||
0.5 + 0.5 * (paintParams.camera_to_center_distance / camera_to_anchor_distance),
|
||||
0.0, // Prevents oversized near-field boxes in pitched/overzoomed tiles
|
||||
4.0);
|
||||
|
||||
float4 position = drawable.matrix * float4(float2(vertx.pos), 0.0, 1.0);
|
||||
position.xy += (float2(vertx.extrude) + vertx.shift) * tileProps.extrude_scale * position.w * collision_perspective_ratio;
|
||||
|
||||
float placed = float(vertx.placed.x);
|
||||
float notUsed = float(vertx.placed.y);
|
||||
|
||||
return {
|
||||
.position = position,
|
||||
.placed = placed,
|
||||
.notUsed = notUsed,
|
||||
};
|
||||
}
|
||||
|
||||
half4 fragment fragmentMain(FragmentStage in [[stage_in]]) {
|
||||
|
||||
float alpha = 0.5;
|
||||
|
||||
// Red = collision, hide label
|
||||
float4 color = float4(1.0, 0.0, 0.0, 1.0) * alpha;
|
||||
|
||||
// Blue = no collision, label is showing
|
||||
if (in.placed > 0.5) {
|
||||
color = float4(0.0, 0.0, 1.0, 0.5) * alpha;
|
||||
}
|
||||
|
||||
if (in.notUsed > 0.5) {
|
||||
// This box not used, fade it out
|
||||
color *= 0.1;
|
||||
}
|
||||
|
||||
return half4(color);
|
||||
}
|
||||
)";
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::CollisionCircleShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto name = "CollisionCircleShader";
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static const std::array<AttributeInfo, 4> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static const std::array<TextureInfo, 0> textures;
|
||||
|
||||
static constexpr auto source = COLLISION_SHADER_COMMON R"(
|
||||
|
||||
struct VertexStage {
|
||||
short2 pos [[attribute(collisionUBOCount + 0)]];
|
||||
short2 anchor_pos [[attribute(collisionUBOCount + 1)]];
|
||||
short2 extrude [[attribute(collisionUBOCount + 2)]];
|
||||
ushort2 placed [[attribute(collisionUBOCount + 3)]];
|
||||
};
|
||||
|
||||
struct FragmentStage {
|
||||
float4 position [[position, invariant]];
|
||||
float placed;
|
||||
float notUsed;
|
||||
float radius;
|
||||
float2 extrude;
|
||||
float2 extrude_scale;
|
||||
};
|
||||
|
||||
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
device const GlobalPaintParamsUBO& paintParams [[buffer(idGlobalPaintParamsUBO)]],
|
||||
device const CollisionDrawableUBO& drawable [[buffer(idCollisionDrawableUBO)]],
|
||||
device const CollisionTilePropsUBO& tileProps [[buffer(idCollisionTilePropsUBO)]]) {
|
||||
|
||||
float4 projectedPoint = drawable.matrix * float4(float2(vertx.anchor_pos), 0, 1);
|
||||
float camera_to_anchor_distance = projectedPoint.w;
|
||||
float collision_perspective_ratio = clamp(
|
||||
0.5 + 0.5 * (paintParams.camera_to_center_distance / camera_to_anchor_distance),
|
||||
0.0, // Prevents oversized near-field circles in pitched/overzoomed tiles
|
||||
4.0);
|
||||
|
||||
float4 position = drawable.matrix * float4(float2(vertx.pos), 0.0, 1.0);
|
||||
|
||||
float padding_factor = 1.2; // Pad the vertices slightly to make room for anti-alias blur
|
||||
position.xy += float2(vertx.extrude) * tileProps.extrude_scale * padding_factor * position.w * collision_perspective_ratio;
|
||||
|
||||
float placed = float(vertx.placed.x);
|
||||
float notUsed = float(vertx.placed.y);
|
||||
float radius = abs(float(vertx.extrude.y)); // We don't pitch the circles, so both units of the extrusion vector are equal in magnitude to the radius
|
||||
|
||||
float2 extrude = float2(vertx.extrude) * padding_factor;
|
||||
float2 extrude_scale = tileProps.extrude_scale * paintParams.camera_to_center_distance * collision_perspective_ratio;
|
||||
|
||||
return {
|
||||
.position = position,
|
||||
.placed = placed,
|
||||
.notUsed = notUsed,
|
||||
.radius = radius,
|
||||
.extrude = extrude,
|
||||
.extrude_scale = extrude_scale,
|
||||
};
|
||||
}
|
||||
|
||||
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
|
||||
device const CollisionTilePropsUBO& tileProps [[buffer(idCollisionTilePropsUBO)]]) {
|
||||
|
||||
float alpha = 0.5;
|
||||
|
||||
// Red = collision, hide label
|
||||
float4 color = float4(1.0, 0.0, 0.0, 1.0) * alpha;
|
||||
|
||||
// Blue = no collision, label is showing
|
||||
if (in.placed > 0.5) {
|
||||
color = float4(0.0, 0.0, 1.0, 0.5) * alpha;
|
||||
}
|
||||
|
||||
if (in.notUsed > 0.5) {
|
||||
// This box not used, fade it out
|
||||
color *= 0.2;
|
||||
}
|
||||
|
||||
float extrude_scale_length = length(in.extrude_scale);
|
||||
float extrude_length = length(in.extrude) * extrude_scale_length;
|
||||
float stroke_width = 15.0 * extrude_scale_length / tileProps.overscale_factor;
|
||||
float radius = in.radius * extrude_scale_length;
|
||||
|
||||
float distance_to_edge = abs(extrude_length - radius);
|
||||
float opacity_t = smoothstep(-stroke_width, 0.0, -distance_to_edge);
|
||||
|
||||
return half4(opacity_t * color);
|
||||
}
|
||||
)";
|
||||
};
|
||||
|
||||
} // namespace shaders
|
||||
} // namespace mbgl
|
||||
@@ -1,93 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/shaders/collision_layer_ubo.hpp>
|
||||
#include <mbgl/shaders/shader_source.hpp>
|
||||
#include <mbgl/shaders/mtl/common.hpp>
|
||||
#include <mbgl/shaders/mtl/shader_program.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::CollisionBoxShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto name = "CollisionBoxShader";
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static const std::array<UniformBlockInfo, 1> uniforms;
|
||||
static const std::array<AttributeInfo, 5> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static const std::array<TextureInfo, 0> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
|
||||
struct VertexStage {
|
||||
short2 pos [[attribute(2)]];
|
||||
short2 anchor_pos [[attribute(3)]];
|
||||
short2 extrude [[attribute(4)]];
|
||||
ushort2 placed [[attribute(5)]];
|
||||
float2 shift [[attribute(6)]];
|
||||
};
|
||||
|
||||
struct FragmentStage {
|
||||
float4 position [[position, invariant]];
|
||||
float placed;
|
||||
float notUsed;
|
||||
};
|
||||
|
||||
struct alignas(16) CollisionBoxUBO {
|
||||
float4x4 matrix;
|
||||
float2 extrude_scale;
|
||||
float overscale_factor;
|
||||
float pad1;
|
||||
};
|
||||
|
||||
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
device const GlobalPaintParamsUBO& paintParams [[buffer(0)]],
|
||||
device const CollisionBoxUBO& drawable [[buffer(1)]]) {
|
||||
|
||||
float4 projectedPoint = drawable.matrix * float4(float2(vertx.anchor_pos), 0, 1);
|
||||
float camera_to_anchor_distance = projectedPoint.w;
|
||||
float collision_perspective_ratio = clamp(
|
||||
0.5 + 0.5 * (paintParams.camera_to_center_distance / camera_to_anchor_distance),
|
||||
0.0, // Prevents oversized near-field boxes in pitched/overzoomed tiles
|
||||
4.0);
|
||||
|
||||
float4 position = drawable.matrix * float4(float2(vertx.pos), 0.0, 1.0);
|
||||
position.xy += (float2(vertx.extrude) + vertx.shift) * drawable.extrude_scale * position.w * collision_perspective_ratio;
|
||||
|
||||
float placed = float(vertx.placed.x);
|
||||
float notUsed = float(vertx.placed.y);
|
||||
|
||||
return {
|
||||
.position = position,
|
||||
.placed = placed,
|
||||
.notUsed = notUsed,
|
||||
};
|
||||
}
|
||||
|
||||
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
|
||||
device const CollisionBoxUBO& drawable [[buffer(1)]]) {
|
||||
|
||||
float alpha = 0.5;
|
||||
|
||||
// Red = collision, hide label
|
||||
float4 color = float4(1.0, 0.0, 0.0, 1.0) * alpha;
|
||||
|
||||
// Blue = no collision, label is showing
|
||||
if (in.placed > 0.5) {
|
||||
color = float4(0.0, 0.0, 1.0, 0.5) * alpha;
|
||||
}
|
||||
|
||||
if (in.notUsed > 0.5) {
|
||||
// This box not used, fade it out
|
||||
color *= 0.1;
|
||||
}
|
||||
|
||||
return half4(color);
|
||||
}
|
||||
)";
|
||||
};
|
||||
|
||||
} // namespace shaders
|
||||
} // namespace mbgl
|
||||
@@ -1,112 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/shaders/collision_layer_ubo.hpp>
|
||||
#include <mbgl/shaders/shader_source.hpp>
|
||||
#include <mbgl/shaders/mtl/common.hpp>
|
||||
#include <mbgl/shaders/mtl/shader_program.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::CollisionCircleShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto name = "CollisionCircleShader";
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static const std::array<UniformBlockInfo, 1> uniforms;
|
||||
static const std::array<AttributeInfo, 4> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static const std::array<TextureInfo, 0> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
|
||||
struct VertexStage {
|
||||
short2 pos [[attribute(2)]];
|
||||
short2 anchor_pos [[attribute(3)]];
|
||||
short2 extrude [[attribute(4)]];
|
||||
ushort2 placed [[attribute(5)]];
|
||||
};
|
||||
|
||||
struct FragmentStage {
|
||||
float4 position [[position, invariant]];
|
||||
float placed;
|
||||
float notUsed;
|
||||
float radius;
|
||||
float2 extrude;
|
||||
float2 extrude_scale;
|
||||
};
|
||||
|
||||
struct alignas(16) CollisionCircleUBO {
|
||||
float4x4 matrix;
|
||||
float2 extrude_scale;
|
||||
float overscale_factor;
|
||||
float pad1;
|
||||
};
|
||||
|
||||
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
device const GlobalPaintParamsUBO& paintParams [[buffer(0)]],
|
||||
device const CollisionCircleUBO& drawable [[buffer(1)]]) {
|
||||
|
||||
float4 projectedPoint = drawable.matrix * float4(float2(vertx.anchor_pos), 0, 1);
|
||||
float camera_to_anchor_distance = projectedPoint.w;
|
||||
float collision_perspective_ratio = clamp(
|
||||
0.5 + 0.5 * (paintParams.camera_to_center_distance / camera_to_anchor_distance),
|
||||
0.0, // Prevents oversized near-field circles in pitched/overzoomed tiles
|
||||
4.0);
|
||||
|
||||
float4 position = drawable.matrix * float4(float2(vertx.pos), 0.0, 1.0);
|
||||
|
||||
float padding_factor = 1.2; // Pad the vertices slightly to make room for anti-alias blur
|
||||
position.xy += float2(vertx.extrude) * drawable.extrude_scale * padding_factor * position.w * collision_perspective_ratio;
|
||||
|
||||
float placed = float(vertx.placed.x);
|
||||
float notUsed = float(vertx.placed.y);
|
||||
float radius = abs(float(vertx.extrude.y)); // We don't pitch the circles, so both units of the extrusion vector are equal in magnitude to the radius
|
||||
|
||||
float2 extrude = float2(vertx.extrude) * padding_factor;
|
||||
float2 extrude_scale = drawable.extrude_scale * paintParams.camera_to_center_distance * collision_perspective_ratio;
|
||||
|
||||
return {
|
||||
.position = position,
|
||||
.placed = placed,
|
||||
.notUsed = notUsed,
|
||||
.radius = radius,
|
||||
.extrude = extrude,
|
||||
.extrude_scale = extrude_scale,
|
||||
};
|
||||
}
|
||||
|
||||
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
|
||||
device const CollisionCircleUBO& drawable [[buffer(1)]]) {
|
||||
|
||||
float alpha = 0.5;
|
||||
|
||||
// Red = collision, hide label
|
||||
float4 color = float4(1.0, 0.0, 0.0, 1.0) * alpha;
|
||||
|
||||
// Blue = no collision, label is showing
|
||||
if (in.placed > 0.5) {
|
||||
color = float4(0.0, 0.0, 1.0, 0.5) * alpha;
|
||||
}
|
||||
|
||||
if (in.notUsed > 0.5) {
|
||||
// This box not used, fade it out
|
||||
color *= 0.2;
|
||||
}
|
||||
|
||||
float extrude_scale_length = length(in.extrude_scale);
|
||||
float extrude_length = length(in.extrude) * extrude_scale_length;
|
||||
float stroke_width = 15.0 * extrude_scale_length / drawable.overscale_factor;
|
||||
float radius = in.radius * extrude_scale_length;
|
||||
|
||||
float distance_to_edge = abs(extrude_length - radius);
|
||||
float opacity_t = smoothstep(-stroke_width, 0.0, -distance_to_edge);
|
||||
|
||||
return half4(opacity_t * color);
|
||||
}
|
||||
)";
|
||||
};
|
||||
|
||||
} // namespace shaders
|
||||
} // namespace mbgl
|
||||
@@ -54,7 +54,12 @@ float4 unpack_mix_color(const float4 packedColors, const float t) {
|
||||
decode_color(float2(packedColors[2], packedColors[3])), t);
|
||||
}
|
||||
|
||||
|
||||
// Unpack pattern position
|
||||
inline float2 get_pattern_pos(const float2 pixel_coord_upper, const float2 pixel_coord_lower,
|
||||
const float2 pattern_size, const float tile_units_to_pixels, const float2 pos) {
|
||||
const float2 offset = glMod(glMod(glMod(pixel_coord_upper, pattern_size) * 256.0, pattern_size) * 256.0 + pixel_coord_lower, pattern_size);
|
||||
return (tile_units_to_pixels * pos + offset) / pattern_size;
|
||||
}
|
||||
|
||||
template<class ForwardIt, class T>
|
||||
ForwardIt upper_bound(ForwardIt first, ForwardIt last, thread const T& value)
|
||||
@@ -196,49 +201,9 @@ struct alignas(16) GPUExpression {
|
||||
|
||||
float4 getColor(size_t index) device const { return decode_color(stops.colors[index]); }
|
||||
};
|
||||
static_assert(sizeof(GPUExpression) == 32 + (4 + 8) * maxExprStops, "wrong alignment");
|
||||
static_assert(sizeof(GPUExpression) == 32 + (4 + 8) * maxExprStops, "wrong size");
|
||||
static_assert(sizeof(GPUExpression) % 16 == 0, "wrong alignment");
|
||||
|
||||
|
||||
enum {
|
||||
idGlobalPaintParamsUBO,
|
||||
globalUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idLineDrawableUBO = globalUBOCount,
|
||||
idLineInterpolationUBO,
|
||||
idLineTilePropertiesUBO,
|
||||
idLineEvaluatedPropsUBO,
|
||||
idLineExpressionUBO,
|
||||
lineUBOCount
|
||||
};
|
||||
|
||||
|
||||
enum class LineExpressionMask : uint32_t {
|
||||
None = 0,
|
||||
Color = 1 << 0,
|
||||
Opacity = 1 << 1,
|
||||
Blur = 1 << 2,
|
||||
Width = 1 << 3,
|
||||
GapWidth = 1 << 4,
|
||||
FloorWidth = 1 << 5,
|
||||
Offset = 1 << 6,
|
||||
};
|
||||
bool operator&(LineExpressionMask a, LineExpressionMask b) { return (uint32_t)a & (uint32_t)b; }
|
||||
|
||||
struct alignas(16) LineExpressionUBO {
|
||||
GPUExpression color;
|
||||
GPUExpression blur;
|
||||
GPUExpression opacity;
|
||||
GPUExpression gapwidth;
|
||||
GPUExpression offset;
|
||||
GPUExpression width;
|
||||
GPUExpression floorwidth;
|
||||
};
|
||||
static_assert(sizeof(LineExpressionUBO) % 16 == 0, "wrong alignment");
|
||||
|
||||
|
||||
struct alignas(16) GlobalPaintParamsUBO {
|
||||
/* 0 */ float2 pattern_atlas_texsize;
|
||||
/* 8 */ float2 units_to_pixels;
|
||||
@@ -247,136 +212,23 @@ struct alignas(16) GlobalPaintParamsUBO {
|
||||
/* 28 */ float symbol_fade_change;
|
||||
/* 32 */ float aspect_ratio;
|
||||
/* 36 */ float pixel_ratio;
|
||||
/* 40 */ float zoom;
|
||||
/* 40 */ float map_zoom;
|
||||
/* 44 */ float pad1;
|
||||
/* 48 */
|
||||
};
|
||||
static_assert(sizeof(GlobalPaintParamsUBO) == 3 * 16, "unexpected padding");
|
||||
static_assert(sizeof(GlobalPaintParamsUBO) == 3 * 16, "wrong size");
|
||||
|
||||
struct alignas(16) FillEvaluatedPropsUBO {
|
||||
float4 color;
|
||||
float4 outline_color;
|
||||
float opacity;
|
||||
float fade;
|
||||
float from_scale;
|
||||
float to_scale;
|
||||
enum {
|
||||
idGlobalPaintParamsUBO,
|
||||
idGlobalUBOIndex,
|
||||
globalUBOCount,
|
||||
};
|
||||
|
||||
struct alignas(16) FillExtrusionDrawableUBO {
|
||||
/* 0 */ float4x4 matrix;
|
||||
/* 64 */ float2 texsize;
|
||||
/* 72 */ float2 pixel_coord_upper;
|
||||
/* 80 */ float2 pixel_coord_lower;
|
||||
/* 88 */ float height_factor;
|
||||
/* 92 */ float tile_ratio;
|
||||
/* 96 */
|
||||
enum {
|
||||
idDrawableReservedVertexOnlyUBO = globalUBOCount,
|
||||
idDrawableReservedFragmentOnlyUBO,
|
||||
drawableReservedUBOCount
|
||||
};
|
||||
static_assert(sizeof(FillExtrusionDrawableUBO) == 6 * 16, "unexpected padding");
|
||||
|
||||
struct alignas(16) FillExtrusionPropsUBO {
|
||||
/* 0 */ float4 color;
|
||||
/* 16 */ float4 light_color_pad;
|
||||
/* 32 */ float4 light_position_base;
|
||||
/* 48 */ float height;
|
||||
/* 52 */ float light_intensity;
|
||||
/* 56 */ float vertical_gradient;
|
||||
/* 60 */ float opacity;
|
||||
/* 64 */ float fade;
|
||||
/* 68 */ float from_scale;
|
||||
/* 72 */ float to_scale;
|
||||
/* 76 */ float pad2;
|
||||
/* 80 */
|
||||
};
|
||||
static_assert(sizeof(FillExtrusionPropsUBO) == 5 * 16, "unexpected padding");
|
||||
|
||||
struct alignas(16) FillExtrusionTilePropsUBO {
|
||||
/* 0 */ float4 pattern_from;
|
||||
/* 16 */ float4 pattern_to;
|
||||
/* 32 */
|
||||
};
|
||||
static_assert(sizeof(FillExtrusionTilePropsUBO) == 2 * 16, "unexpected padding");
|
||||
|
||||
struct alignas(16) FillExtrusionInterpolateUBO {
|
||||
/* 0 */ float base_t;
|
||||
/* 4 */ float height_t;
|
||||
/* 8 */ float color_t;
|
||||
/* 12 */ float pattern_from_t;
|
||||
/* 16 */ float pattern_to_t;
|
||||
/* 20 */ float pad1, pad2, pad3;
|
||||
/* 32 */
|
||||
};
|
||||
static_assert(sizeof(FillExtrusionInterpolateUBO) == 2 * 16, "unexpected padding");
|
||||
|
||||
struct alignas(16) LineEvaluatedPropsUBO {
|
||||
float4 color;
|
||||
float blur;
|
||||
float opacity;
|
||||
float gapwidth;
|
||||
float offset;
|
||||
float width;
|
||||
float floorwidth;
|
||||
LineExpressionMask expressionMask;
|
||||
float pad1;
|
||||
};
|
||||
|
||||
struct alignas(16) SymbolDrawableUBO {
|
||||
float4x4 matrix;
|
||||
float4x4 label_plane_matrix;
|
||||
float4x4 coord_matrix;
|
||||
|
||||
float2 texsize;
|
||||
float2 texsize_icon;
|
||||
|
||||
float gamma_scale;
|
||||
/*bool*/ int rotate_symbol;
|
||||
float2 pad;
|
||||
};
|
||||
static_assert(sizeof(SymbolDrawableUBO) == 14 * 16, "unexpected padding");
|
||||
|
||||
struct alignas(16) SymbolTilePropsUBO {
|
||||
/*bool*/ int is_text;
|
||||
/*bool*/ int is_halo;
|
||||
/*bool*/ int pitch_with_map;
|
||||
/*bool*/ int is_size_zoom_constant;
|
||||
/*bool*/ int is_size_feature_constant;
|
||||
float size_t;
|
||||
float size;
|
||||
float padding;
|
||||
};
|
||||
static_assert(sizeof(SymbolTilePropsUBO) == 2 * 16, "unexpected padding");
|
||||
|
||||
struct alignas(16) SymbolInterpolateUBO {
|
||||
float fill_color_t;
|
||||
float halo_color_t;
|
||||
float opacity_t;
|
||||
float halo_width_t;
|
||||
float halo_blur_t;
|
||||
float pad1, pad2, pad3;
|
||||
};
|
||||
static_assert(sizeof(SymbolInterpolateUBO) == 32, "unexpected padding");
|
||||
|
||||
struct alignas(16) SymbolEvaluatedPropsUBO {
|
||||
float4 text_fill_color;
|
||||
float4 text_halo_color;
|
||||
float text_opacity;
|
||||
float text_halo_width;
|
||||
float text_halo_blur;
|
||||
float pad1;
|
||||
float4 icon_fill_color;
|
||||
float4 icon_halo_color;
|
||||
float icon_opacity;
|
||||
float icon_halo_width;
|
||||
float icon_halo_blur;
|
||||
float pad2;
|
||||
};
|
||||
static_assert(sizeof(SymbolEvaluatedPropsUBO) == 6 * 16, "unexpected padding");
|
||||
|
||||
// unpack pattern position
|
||||
inline float2 get_pattern_pos(const float2 pixel_coord_upper, const float2 pixel_coord_lower,
|
||||
const float2 pattern_size, const float tile_units_to_pixels, const float2 pos) {
|
||||
const float2 offset = glMod(glMod(glMod(pixel_coord_upper, pattern_size) * 256.0, pattern_size) * 256.0 + pixel_coord_lower, pattern_size);
|
||||
return (tile_units_to_pixels * pos + offset) / pattern_size;
|
||||
}
|
||||
|
||||
)";
|
||||
|
||||
|
||||
@@ -1,43 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/shaders/mtl/common.hpp>
|
||||
#include <mbgl/shaders/mtl/shader_program.hpp>
|
||||
#include <mbgl/shaders/shader_source.hpp>
|
||||
#include <mbgl/shaders/custom_drawable_layer_ubo.hpp>
|
||||
#include <mbgl/shaders/shader_source.hpp>
|
||||
#include <mbgl/shaders/mtl/shader_program.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
#define CUSTOM_SYMBOL_ICON_SHADER_PRELUDE \
|
||||
R"(
|
||||
|
||||
enum {
|
||||
idCustomSymbolDrawableUBO = idDrawableReservedVertexOnlyUBO,
|
||||
customSymbolUBOCount = drawableReservedUBOCount
|
||||
};
|
||||
|
||||
struct alignas(16) CustomSymbolIconDrawableUBO {
|
||||
/* 0 */ float4x4 matrix;
|
||||
/* 64 */ float2 extrude_scale;
|
||||
/* 72 */ float2 anchor;
|
||||
/* 80 */ float angle_degrees;
|
||||
/* 84 */ uint32_t scale_with_map;
|
||||
/* 88 */ uint32_t pitch_with_map;
|
||||
/* 92 */ float camera_to_center_distance;
|
||||
/* 96 */ float aspect_ratio;
|
||||
/* 100 */ float pad1;
|
||||
/* 104 */ float pad2;
|
||||
/* 108 */ float pad3;
|
||||
/* 112 */
|
||||
};
|
||||
static_assert(sizeof(CustomSymbolIconDrawableUBO) == 7 * 16, "wrong size");
|
||||
|
||||
)"
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::CustomSymbolIconShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto name = "CustomSymbolIconShader";
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static const std::array<UniformBlockInfo, 2> uniforms;
|
||||
static const std::array<AttributeInfo, 2> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static const std::array<TextureInfo, 1> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
struct alignas(16) CustomSymbolIconDrawableUBO {
|
||||
float4x4 matrix;
|
||||
};
|
||||
|
||||
struct alignas(16) CustomSymbolIconParametersUBO {
|
||||
float2 extrude_scale;
|
||||
float2 anchor;
|
||||
float angle_degrees;
|
||||
int scale_with_map;
|
||||
int pitch_with_map;
|
||||
float camera_to_center_distance;
|
||||
float aspect_ratio;
|
||||
float pad0, pad1, pad3;
|
||||
};
|
||||
|
||||
static constexpr auto source = CUSTOM_SYMBOL_ICON_SHADER_PRELUDE R"(
|
||||
struct VertexStage {
|
||||
float2 a_pos [[attribute(3)]];
|
||||
float2 a_tex [[attribute(4)]];
|
||||
float2 a_pos [[attribute(customSymbolUBOCount + 0)]];
|
||||
float2 a_tex [[attribute(customSymbolUBOCount + 1)]];
|
||||
};
|
||||
|
||||
struct FragmentStage {
|
||||
@@ -59,29 +68,28 @@ float2 ellipseRotateVec2(float2 v, float angle, float radiusRatio /* A/B */) {
|
||||
}
|
||||
|
||||
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
device const CustomSymbolIconDrawableUBO& drawable [[buffer(1)]],
|
||||
device const CustomSymbolIconParametersUBO& parameters [[buffer(2)]]) {
|
||||
device const CustomSymbolIconDrawableUBO& drawable [[buffer(idCustomSymbolDrawableUBO)]]) {
|
||||
|
||||
const float2 extrude = glMod(float2(vertx.a_pos), 2.0) * 2.0 - 1.0;
|
||||
const float2 anchor = (parameters.anchor - float2(0.5, 0.5)) * 2.0;
|
||||
const float2 anchor = (drawable.anchor - float2(0.5, 0.5)) * 2.0;
|
||||
const float2 center = floor(float2(vertx.a_pos) * 0.5);
|
||||
const float angle = radians(-parameters.angle_degrees);
|
||||
const float angle = radians(-drawable.angle_degrees);
|
||||
float2 corner = extrude - anchor;
|
||||
|
||||
float4 position;
|
||||
if (parameters.pitch_with_map) {
|
||||
if (parameters.scale_with_map) {
|
||||
corner *= parameters.extrude_scale;
|
||||
if (drawable.pitch_with_map) {
|
||||
if (drawable.scale_with_map) {
|
||||
corner *= drawable.extrude_scale;
|
||||
} else {
|
||||
float4 projected_center = drawable.matrix * float4(center, 0, 1);
|
||||
corner *= parameters.extrude_scale * (projected_center.w / parameters.camera_to_center_distance);
|
||||
corner *= drawable.extrude_scale * (projected_center.w / drawable.camera_to_center_distance);
|
||||
}
|
||||
corner = center + rotateVec2(corner, angle);
|
||||
position = drawable.matrix * float4(corner, 0, 1);
|
||||
} else {
|
||||
position = drawable.matrix * float4(center, 0, 1);
|
||||
const float factor = parameters.scale_with_map ? parameters.camera_to_center_distance : position.w;
|
||||
position.xy += ellipseRotateVec2(corner * parameters.extrude_scale * factor, angle, parameters.aspect_ratio);
|
||||
const float factor = drawable.scale_with_map ? drawable.camera_to_center_distance : position.w;
|
||||
position.xy += ellipseRotateVec2(corner * drawable.extrude_scale * factor, angle, drawable.aspect_ratio);
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -2,27 +2,46 @@
|
||||
|
||||
#include <mbgl/shaders/debug_layer_ubo.hpp>
|
||||
#include <mbgl/shaders/shader_source.hpp>
|
||||
#include <mbgl/shaders/mtl/common.hpp>
|
||||
#include <mbgl/shaders/mtl/shader_program.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
#define DEBUG_SHADER_PRELUDE \
|
||||
R"(
|
||||
|
||||
enum {
|
||||
idDebugUBO = drawableReservedUBOCount,
|
||||
debugUBOCount
|
||||
};
|
||||
|
||||
struct alignas(16) DebugUBO {
|
||||
/* 0 */ float4x4 matrix;
|
||||
/* 64 */ float4 color;
|
||||
/* 80 */ float overlay_scale;
|
||||
/* 84 */ float pad1;
|
||||
/* 88 */ float pad2;
|
||||
/* 92 */ float pad3;
|
||||
/* 96 */
|
||||
};
|
||||
static_assert(sizeof(DebugUBO) == 6 * 16, "wrong size");
|
||||
|
||||
)"
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::DebugShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto name = "DebugShader";
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static const std::array<UniformBlockInfo, 1> uniforms;
|
||||
static const std::array<AttributeInfo, 1> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static const std::array<TextureInfo, 1> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
static constexpr auto source = DEBUG_SHADER_PRELUDE R"(
|
||||
|
||||
struct VertexStage {
|
||||
short2 pos [[attribute(2)]];
|
||||
short2 pos [[attribute(debugUBOCount + 0)]];
|
||||
};
|
||||
|
||||
struct FragmentStage {
|
||||
@@ -30,15 +49,8 @@ struct FragmentStage {
|
||||
float2 uv;
|
||||
};
|
||||
|
||||
struct alignas(16) DebugUBO {
|
||||
float4x4 matrix;
|
||||
float4 color;
|
||||
float overlay_scale;
|
||||
float pad1, pad2, pad3;
|
||||
};
|
||||
|
||||
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
device const DebugUBO& debug [[buffer(1)]]) {
|
||||
device const DebugUBO& debug [[buffer(idDebugUBO)]]) {
|
||||
|
||||
const float4 position = debug.matrix * float4(float2(vertx.pos) * debug.overlay_scale, 0, 1);
|
||||
|
||||
@@ -53,7 +65,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
}
|
||||
|
||||
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
|
||||
device const DebugUBO& debug [[buffer(1)]],
|
||||
device const DebugUBO& debug [[buffer(idDebugUBO)]],
|
||||
texture2d<float, access::sample> overlay [[texture(0)]],
|
||||
sampler overlay_sampler [[sampler(0)]]) {
|
||||
|
||||
|
||||
@@ -2,33 +2,165 @@
|
||||
|
||||
#include <mbgl/shaders/fill_layer_ubo.hpp>
|
||||
#include <mbgl/shaders/shader_source.hpp>
|
||||
#include <mbgl/shaders/mtl/common.hpp>
|
||||
#include <mbgl/shaders/mtl/shader_program.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
#define FILL_SHADER_COMMON \
|
||||
R"(
|
||||
|
||||
enum {
|
||||
idFillDrawableUBO = idDrawableReservedVertexOnlyUBO,
|
||||
idFillTilePropsUBO = drawableReservedUBOCount,
|
||||
idFillEvaluatedPropsUBO,
|
||||
fillUBOCount
|
||||
};
|
||||
|
||||
//
|
||||
// Fill
|
||||
|
||||
struct alignas(16) FillDrawableUBO {
|
||||
/* 0 */ float4x4 matrix;
|
||||
|
||||
// Interpolations
|
||||
/* 64 */ float color_t;
|
||||
/* 68 */ float opacity_t;
|
||||
/* 72 */ float pad1;
|
||||
/* 76 */ float pad2;
|
||||
/* 80 */
|
||||
};
|
||||
static_assert(sizeof(FillDrawableUBO) == 5 * 16, "wrong size");
|
||||
|
||||
//
|
||||
// Fill outline
|
||||
|
||||
struct alignas(16) FillOutlineDrawableUBO {
|
||||
/* 0 */ float4x4 matrix;
|
||||
|
||||
// Interpolations
|
||||
/* 64 */ float outline_color_t;
|
||||
/* 68 */ float opacity_t;
|
||||
/* 72 */ float pad1;
|
||||
/* 76 */ float pad2;
|
||||
/* 80 */
|
||||
};
|
||||
static_assert(sizeof(FillOutlineDrawableUBO) == 5 * 16, "wrong size");
|
||||
|
||||
//
|
||||
// Fill pattern
|
||||
|
||||
struct alignas(16) FillPatternDrawableUBO {
|
||||
/* 0 */ float4x4 matrix;
|
||||
/* 64 */ float2 pixel_coord_upper;
|
||||
/* 72 */ float2 pixel_coord_lower;
|
||||
/* 80 */ float tile_ratio;
|
||||
|
||||
// Interpolations
|
||||
/* 84 */ float pattern_from_t;
|
||||
/* 88 */ float pattern_to_t;
|
||||
/* 92 */ float opacity_t;
|
||||
/* 96 */
|
||||
};
|
||||
static_assert(sizeof(FillPatternDrawableUBO) == 6 * 16, "wrong size");
|
||||
|
||||
struct alignas(16) FillPatternTilePropsUBO {
|
||||
/* 0 */ float4 pattern_from;
|
||||
/* 16 */ float4 pattern_to;
|
||||
/* 32 */ float2 texsize;
|
||||
/* 40 */ float pad1;
|
||||
/* 44 */ float pad2;
|
||||
/* 48 */
|
||||
};
|
||||
static_assert(sizeof(FillPatternTilePropsUBO) == 3 * 16, "wrong size");
|
||||
|
||||
//
|
||||
// Fill pattern outline
|
||||
|
||||
struct alignas(16) FillOutlinePatternDrawableUBO {
|
||||
/* 0 */ float4x4 matrix;
|
||||
/* 64 */ float2 pixel_coord_upper;
|
||||
/* 72 */ float2 pixel_coord_lower;
|
||||
/* 80 */ float tile_ratio;
|
||||
|
||||
// Interpolations
|
||||
/* 84 */ float pattern_from_t;
|
||||
/* 88 */ float pattern_to_t;
|
||||
/* 92 */ float opacity_t;
|
||||
/* 96 */
|
||||
};
|
||||
static_assert(sizeof(FillOutlinePatternDrawableUBO) == 6 * 16, "wrong size");
|
||||
|
||||
struct alignas(16) FillOutlinePatternTilePropsUBO {
|
||||
/* 0 */ float4 pattern_from;
|
||||
/* 16 */ float4 pattern_to;
|
||||
/* 32 */ float2 texsize;
|
||||
/* 40 */ float pad1;
|
||||
/* 44 */ float pad2;
|
||||
/* 48 */
|
||||
};
|
||||
static_assert(sizeof(FillOutlinePatternTilePropsUBO) == 3 * 16, "wrong size");
|
||||
|
||||
//
|
||||
// Fill outline triangulated
|
||||
|
||||
struct alignas(16) FillOutlineTriangulatedDrawableUBO {
|
||||
/* 0 */ float4x4 matrix;
|
||||
/* 64 */ float ratio;
|
||||
/* 68 */ float pad1;
|
||||
/* 72 */ float pad2;
|
||||
/* 76 */ float pad3;
|
||||
/* 80 */
|
||||
};
|
||||
static_assert(sizeof(FillOutlineTriangulatedDrawableUBO) == 5 * 16, "wrong size");
|
||||
|
||||
/// Evaluated properties that do not depend on the tile
|
||||
struct alignas(16) FillEvaluatedPropsUBO {
|
||||
/* 0 */ float4 color;
|
||||
/* 16 */ float4 outline_color;
|
||||
/* 32 */ float opacity;
|
||||
/* 36 */ float fade;
|
||||
/* 40 */ float from_scale;
|
||||
/* 44 */ float to_scale;
|
||||
/* 48 */
|
||||
};
|
||||
static_assert(sizeof(FillEvaluatedPropsUBO) == 3 * 16, "wrong size");
|
||||
|
||||
union FillDrawableUnionUBO {
|
||||
FillDrawableUBO fillDrawableUBO;
|
||||
FillOutlineDrawableUBO fillOutlineDrawableUBO;
|
||||
FillPatternDrawableUBO fillPatternDrawableUBO;
|
||||
FillOutlinePatternDrawableUBO fillOutlinePatternDrawableUBO;
|
||||
FillOutlineTriangulatedDrawableUBO fillOutlineTriangulatedDrawableUBO;
|
||||
};
|
||||
|
||||
union FillTilePropsUnionUBO {
|
||||
FillPatternTilePropsUBO fillPatternTilePropsUBO;
|
||||
FillOutlinePatternTilePropsUBO fillOutlinePatternTilePropsUBO;
|
||||
};
|
||||
|
||||
)"
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::FillShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto name = "FillShader";
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static const std::array<UniformBlockInfo, 3> uniforms;
|
||||
static const std::array<AttributeInfo, 3> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static const std::array<TextureInfo, 0> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
static constexpr auto source = FILL_SHADER_COMMON R"(
|
||||
|
||||
struct VertexStage {
|
||||
short2 position [[attribute(5)]];
|
||||
short2 position [[attribute(fillUBOCount + 0)]];
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_color)
|
||||
float4 color [[attribute(6)]];
|
||||
float4 color [[attribute(fillUBOCount + 1)]];
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_opacity)
|
||||
float2 opacity [[attribute(7)]];
|
||||
float2 opacity [[attribute(fillUBOCount + 2)]];
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -43,32 +175,25 @@ struct FragmentStage {
|
||||
#endif
|
||||
};
|
||||
|
||||
struct alignas(16) FillDrawableUBO {
|
||||
float4x4 matrix;
|
||||
};
|
||||
|
||||
struct alignas(16) FillInterpolateUBO {
|
||||
float color_t;
|
||||
float opacity_t;
|
||||
};
|
||||
|
||||
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
device const FillDrawableUBO& drawable [[buffer(1)]],
|
||||
device const FillInterpolateUBO& interp [[buffer(3)]],
|
||||
device const FillEvaluatedPropsUBO& props [[buffer(4)]]) {
|
||||
device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]],
|
||||
device const FillDrawableUnionUBO* drawableVector [[buffer(idFillDrawableUBO)]]) {
|
||||
|
||||
device const FillDrawableUBO& drawable = drawableVector[uboIndex].fillDrawableUBO;
|
||||
|
||||
return {
|
||||
.position = drawable.matrix * float4(float2(vertx.position), 0.0f, 1.0f),
|
||||
#if !defined(HAS_UNIFORM_u_color)
|
||||
.color = half4(unpack_mix_color(vertx.color, interp.color_t)),
|
||||
.color = half4(unpack_mix_color(vertx.color, drawable.color_t)),
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_opacity)
|
||||
.opacity = half(unpack_mix_float(vertx.opacity, interp.opacity_t)),
|
||||
.opacity = half(unpack_mix_float(vertx.opacity, drawable.opacity_t)),
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
||||
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
|
||||
device const FillEvaluatedPropsUBO& props [[buffer(4)]]) {
|
||||
device const FillEvaluatedPropsUBO& props [[buffer(idFillEvaluatedPropsUBO)]]) {
|
||||
#if defined(OVERDRAW_INSPECTOR)
|
||||
return half4(1.0);
|
||||
#endif
|
||||
@@ -96,16 +221,15 @@ struct ShaderSource<BuiltIn::FillOutlineShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static const std::array<UniformBlockInfo, 4> uniforms;
|
||||
static const std::array<AttributeInfo, 3> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static const std::array<TextureInfo, 0> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
static constexpr auto source = FILL_SHADER_COMMON R"(
|
||||
struct VertexStage {
|
||||
short2 position [[attribute(5)]];
|
||||
float4 outline_color [[attribute(6)]];
|
||||
float2 opacity [[attribute(7)]];
|
||||
short2 position [[attribute(fillUBOCount + 0)]];
|
||||
float4 outline_color [[attribute(fillUBOCount + 1)]];
|
||||
float2 opacity [[attribute(fillUBOCount + 2)]];
|
||||
};
|
||||
|
||||
struct FragmentStage {
|
||||
@@ -119,35 +243,28 @@ struct FragmentStage {
|
||||
#endif
|
||||
};
|
||||
|
||||
struct alignas(16) FillOutlineDrawableUBO {
|
||||
float4x4 matrix;
|
||||
};
|
||||
|
||||
struct alignas(16) FillOutlineInterpolateUBO {
|
||||
float outline_color_t;
|
||||
float opacity_t;
|
||||
};
|
||||
|
||||
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
device const GlobalPaintParamsUBO& paintParams [[buffer(0)]],
|
||||
device const FillOutlineDrawableUBO& drawable [[buffer(1)]],
|
||||
device const FillOutlineInterpolateUBO& interp [[buffer(3)]],
|
||||
device const FillEvaluatedPropsUBO& props [[buffer(4)]]) {
|
||||
device const GlobalPaintParamsUBO& paintParams [[buffer(idGlobalPaintParamsUBO)]],
|
||||
device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]],
|
||||
device const FillDrawableUnionUBO* drawableVector [[buffer(idFillDrawableUBO)]]) {
|
||||
|
||||
device const FillOutlineDrawableUBO& drawable = drawableVector[uboIndex].fillOutlineDrawableUBO;
|
||||
|
||||
const float4 position = drawable.matrix * float4(float2(vertx.position), 0.0f, 1.0f);
|
||||
return {
|
||||
.position = position,
|
||||
.pos = (position.xy / position.w + 1.0) / 2.0 * paintParams.world_size,
|
||||
#if !defined(HAS_UNIFORM_u_outline_color)
|
||||
.outline_color = half4(unpack_mix_color(vertx.outline_color, interp.outline_color_t)),
|
||||
.outline_color = half4(unpack_mix_color(vertx.outline_color, drawable.outline_color_t)),
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_opacity)
|
||||
.opacity = half(unpack_mix_float(vertx.opacity, interp.opacity_t)),
|
||||
.opacity = half(unpack_mix_float(vertx.opacity, drawable.opacity_t)),
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
||||
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
|
||||
device const FillEvaluatedPropsUBO& props [[buffer(4)]]) {
|
||||
device const FillEvaluatedPropsUBO& props [[buffer(idFillEvaluatedPropsUBO)]]) {
|
||||
#if defined(OVERDRAW_INSPECTOR)
|
||||
return half4(1.0);
|
||||
#endif
|
||||
@@ -181,23 +298,22 @@ struct ShaderSource<BuiltIn::FillPatternShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static const std::array<UniformBlockInfo, 5> uniforms;
|
||||
static const std::array<AttributeInfo, 4> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static const std::array<TextureInfo, 1> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
static constexpr auto source = FILL_SHADER_COMMON R"(
|
||||
struct VertexStage {
|
||||
short2 position [[attribute(5)]];
|
||||
short2 position [[attribute(fillUBOCount + 0)]];
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_pattern_from)
|
||||
ushort4 pattern_from [[attribute(6)]];
|
||||
ushort4 pattern_from [[attribute(fillUBOCount + 1)]];
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_pattern_to)
|
||||
ushort4 pattern_to [[attribute(7)]];
|
||||
ushort4 pattern_to [[attribute(fillUBOCount + 2)]];
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_opacity)
|
||||
float2 opacity [[attribute(8)]];
|
||||
float2 opacity [[attribute(fillUBOCount + 3)]];
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -217,32 +333,16 @@ struct FragmentStage {
|
||||
#endif
|
||||
};
|
||||
|
||||
struct alignas(16) FillPatternDrawableUBO {
|
||||
float4x4 matrix;
|
||||
float2 pixel_coord_upper;
|
||||
float2 pixel_coord_lower;
|
||||
float2 texsize;
|
||||
float tile_ratio;
|
||||
float pad;
|
||||
};
|
||||
|
||||
struct alignas(16) FillPatternTilePropsUBO {
|
||||
float4 pattern_from;
|
||||
float4 pattern_to;
|
||||
};
|
||||
|
||||
struct alignas(16) FillPatternInterpolateUBO {
|
||||
float pattern_from_t;
|
||||
float pattern_to_t;
|
||||
float opacity_t;
|
||||
};
|
||||
|
||||
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
device const GlobalPaintParamsUBO& paintParams [[buffer(0)]],
|
||||
device const FillPatternDrawableUBO& drawable [[buffer(1)]],
|
||||
device const FillPatternTilePropsUBO& tileProps [[buffer(2)]],
|
||||
device const FillPatternInterpolateUBO& interp [[buffer(3)]],
|
||||
device const FillEvaluatedPropsUBO& props [[buffer(4)]]) {
|
||||
device const GlobalPaintParamsUBO& paintParams [[buffer(idGlobalPaintParamsUBO)]],
|
||||
device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]],
|
||||
device const FillDrawableUnionUBO* drawableVector [[buffer(idFillDrawableUBO)]],
|
||||
device const FillTilePropsUnionUBO* tilePropsVector [[buffer(idFillTilePropsUBO)]],
|
||||
device const FillEvaluatedPropsUBO& props [[buffer(idFillEvaluatedPropsUBO)]]) {
|
||||
|
||||
device const FillPatternDrawableUBO& drawable = drawableVector[uboIndex].fillPatternDrawableUBO;
|
||||
device const FillPatternTilePropsUBO& tileProps = tilePropsVector[uboIndex].fillPatternTilePropsUBO;
|
||||
|
||||
#if defined(HAS_UNIFORM_u_pattern_from)
|
||||
const auto pattern_from = float4(tileProps.pattern_from);
|
||||
#else
|
||||
@@ -280,21 +380,23 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
.pattern_to = half4(pattern_to),
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_opacity)
|
||||
.opacity = half(unpack_mix_float(vertx.opacity, interp.opacity_t)),
|
||||
.opacity = half(unpack_mix_float(vertx.opacity, drawable.opacity_t)),
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
||||
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
|
||||
device const FillPatternDrawableUBO& drawable [[buffer(1)]],
|
||||
device const FillPatternTilePropsUBO& tileProps [[buffer(2)]],
|
||||
device const FillEvaluatedPropsUBO& props [[buffer(4)]],
|
||||
device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]],
|
||||
device const FillTilePropsUnionUBO* tilePropsVector [[buffer(idFillTilePropsUBO)]],
|
||||
device const FillEvaluatedPropsUBO& props [[buffer(idFillEvaluatedPropsUBO)]],
|
||||
texture2d<float, access::sample> image0 [[texture(0)]],
|
||||
sampler image0_sampler [[sampler(0)]]) {
|
||||
#if defined(OVERDRAW_INSPECTOR)
|
||||
return half4(1.0);
|
||||
#endif
|
||||
|
||||
device const FillPatternTilePropsUBO& tileProps = tilePropsVector[uboIndex].fillPatternTilePropsUBO;
|
||||
|
||||
#if defined(HAS_UNIFORM_u_pattern_from)
|
||||
const auto pattern_from = float4(tileProps.pattern_from);
|
||||
#else
|
||||
@@ -319,11 +421,11 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]],
|
||||
const float2 pattern_br_b = pattern_to.zw;
|
||||
|
||||
const float2 imagecoord = glMod(in.v_pos_a, 1.0);
|
||||
const float2 pos = mix(pattern_tl_a / drawable.texsize, pattern_br_a / drawable.texsize, imagecoord);
|
||||
const float2 pos = mix(pattern_tl_a / tileProps.texsize, pattern_br_a / tileProps.texsize, imagecoord);
|
||||
const float4 color1 = image0.sample(image0_sampler, pos);
|
||||
|
||||
const float2 imagecoord_b = glMod(in.v_pos_b, 1.0);
|
||||
const float2 pos2 = mix(pattern_tl_b / drawable.texsize, pattern_br_b / drawable.texsize, imagecoord_b);
|
||||
const float2 pos2 = mix(pattern_tl_b / tileProps.texsize, pattern_br_b / tileProps.texsize, imagecoord_b);
|
||||
const float4 color2 = image0.sample(image0_sampler, pos2);
|
||||
|
||||
return half4(mix(color1, color2, props.fade) * opacity);
|
||||
@@ -337,24 +439,23 @@ struct ShaderSource<BuiltIn::FillOutlinePatternShader, gfx::Backend::Type::Metal
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static const std::array<UniformBlockInfo, 5> uniforms;
|
||||
static const std::array<AttributeInfo, 4> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static const std::array<TextureInfo, 1> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
static constexpr auto source = FILL_SHADER_COMMON R"(
|
||||
|
||||
struct VertexStage {
|
||||
short2 position [[attribute(5)]];
|
||||
short2 position [[attribute(fillUBOCount + 0)]];
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_pattern_from)
|
||||
ushort4 pattern_from [[attribute(6)]];
|
||||
ushort4 pattern_from [[attribute(fillUBOCount + 1)]];
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_pattern_to)
|
||||
ushort4 pattern_to [[attribute(7)]];
|
||||
ushort4 pattern_to [[attribute(fillUBOCount + 2)]];
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_opacity)
|
||||
float2 opacity [[attribute(8)]];
|
||||
float2 opacity [[attribute(fillUBOCount + 3)]];
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -375,32 +476,16 @@ struct FragmentStage {
|
||||
#endif
|
||||
};
|
||||
|
||||
struct alignas(16) FillOutlinePatternDrawableUBO {
|
||||
float4x4 matrix;
|
||||
float2 pixel_coord_upper;
|
||||
float2 pixel_coord_lower;
|
||||
float2 texsize;
|
||||
float tile_ratio;
|
||||
float pad;
|
||||
};
|
||||
|
||||
struct alignas(16) FillOutlinePatternTilePropsUBO {
|
||||
float4 pattern_from;
|
||||
float4 pattern_to;
|
||||
};
|
||||
|
||||
struct alignas(16) FillOutlinePatternInterpolateUBO {
|
||||
float pattern_from_t;
|
||||
float pattern_to_t;
|
||||
float opacity_t;
|
||||
};
|
||||
|
||||
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
device const GlobalPaintParamsUBO& paintParams [[buffer(0)]],
|
||||
device const FillOutlinePatternDrawableUBO& drawable [[buffer(1)]],
|
||||
device const FillOutlinePatternTilePropsUBO& tileProps [[buffer(2)]],
|
||||
device const FillOutlinePatternInterpolateUBO& interp [[buffer(3)]],
|
||||
device const FillEvaluatedPropsUBO& props [[buffer(4)]]) {
|
||||
device const GlobalPaintParamsUBO& paintParams [[buffer(idGlobalPaintParamsUBO)]],
|
||||
device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]],
|
||||
device const FillDrawableUnionUBO* drawableVector [[buffer(idFillDrawableUBO)]],
|
||||
device const FillTilePropsUnionUBO* tilePropsVector [[buffer(idFillTilePropsUBO)]],
|
||||
device const FillEvaluatedPropsUBO& props [[buffer(idFillEvaluatedPropsUBO)]]) {
|
||||
|
||||
device const FillOutlinePatternDrawableUBO& drawable = drawableVector[uboIndex].fillOutlinePatternDrawableUBO;
|
||||
device const FillOutlinePatternTilePropsUBO& tileProps = tilePropsVector[uboIndex].fillOutlinePatternTilePropsUBO;
|
||||
|
||||
#if defined(HAS_UNIFORM_u_pattern_from)
|
||||
const auto pattern_from = tileProps.pattern_from;
|
||||
#else
|
||||
@@ -414,7 +499,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
#endif
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_opacity)
|
||||
const auto opacity = unpack_mix_float(vertx.opacity, interp.opacity_t);
|
||||
const auto opacity = unpack_mix_float(vertx.opacity, drawable.opacity_t);
|
||||
#endif
|
||||
|
||||
const float2 pattern_tl_a = pattern_from.xy;
|
||||
@@ -451,15 +536,17 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
}
|
||||
|
||||
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
|
||||
device const FillOutlinePatternDrawableUBO& drawable [[buffer(1)]],
|
||||
device const FillOutlinePatternTilePropsUBO& tileProps [[buffer(2)]],
|
||||
device const FillEvaluatedPropsUBO& props [[buffer(4)]],
|
||||
device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]],
|
||||
device const FillTilePropsUnionUBO* tilePropsVector [[buffer(idFillTilePropsUBO)]],
|
||||
device const FillEvaluatedPropsUBO& props [[buffer(idFillEvaluatedPropsUBO)]],
|
||||
texture2d<float, access::sample> image0 [[texture(0)]],
|
||||
sampler image0_sampler [[sampler(0)]]) {
|
||||
#if defined(OVERDRAW_INSPECTOR)
|
||||
return half4(1.0);
|
||||
#endif
|
||||
|
||||
device const FillOutlinePatternTilePropsUBO& tileProps = tilePropsVector[uboIndex].fillOutlinePatternTilePropsUBO;
|
||||
|
||||
#if defined(HAS_UNIFORM_u_pattern_from)
|
||||
const auto pattern_from = float4(tileProps.pattern_from);
|
||||
#else
|
||||
@@ -484,11 +571,11 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]],
|
||||
const float2 pattern_br_b = pattern_to.zw;
|
||||
|
||||
const float2 imagecoord = glMod(in.v_pos_a, 1.0);
|
||||
const float2 pos = mix(pattern_tl_a / drawable.texsize, pattern_br_a / drawable.texsize, imagecoord);
|
||||
const float2 pos = mix(pattern_tl_a / tileProps.texsize, pattern_br_a / tileProps.texsize, imagecoord);
|
||||
const float4 color1 = image0.sample(image0_sampler, pos);
|
||||
|
||||
const float2 imagecoord_b = glMod(in.v_pos_b, 1.0);
|
||||
const float2 pos2 = mix(pattern_tl_b / drawable.texsize, pattern_br_b / drawable.texsize, imagecoord_b);
|
||||
const float2 pos2 = mix(pattern_tl_b / tileProps.texsize, pattern_br_b / tileProps.texsize, imagecoord_b);
|
||||
const float4 color2 = image0.sample(image0_sampler, pos2);
|
||||
|
||||
// TODO: Should triangate the lines into triangles to support thick line and edge antialiased.
|
||||
@@ -506,15 +593,14 @@ struct ShaderSource<BuiltIn::FillOutlineTriangulatedShader, gfx::Backend::Type::
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static const std::array<UniformBlockInfo, 3> uniforms;
|
||||
static const std::array<AttributeInfo, 2> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static const std::array<TextureInfo, 0> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
static constexpr auto source = FILL_SHADER_COMMON R"(
|
||||
struct VertexStage {
|
||||
short2 pos_normal [[attribute(5)]];
|
||||
uchar4 data [[attribute(6)]];
|
||||
short2 pos_normal [[attribute(fillUBOCount + 0)]];
|
||||
uchar4 data [[attribute(fillUBOCount + 1)]];
|
||||
};
|
||||
|
||||
struct FragmentStage {
|
||||
@@ -524,16 +610,12 @@ struct FragmentStage {
|
||||
half gamma_scale;
|
||||
};
|
||||
|
||||
struct alignas(16) FillOutlineTriangulatedDrawableUBO {
|
||||
float4x4 matrix;
|
||||
float ratio;
|
||||
float pad1, pad2, pad3;
|
||||
};
|
||||
|
||||
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
device const GlobalPaintParamsUBO& paintParams [[buffer(0)]],
|
||||
device const FillOutlineTriangulatedDrawableUBO& drawable [[buffer(1)]],
|
||||
device const FillEvaluatedPropsUBO& props [[buffer(4)]]) {
|
||||
device const GlobalPaintParamsUBO& paintParams [[buffer(idGlobalPaintParamsUBO)]],
|
||||
device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]],
|
||||
device const FillDrawableUnionUBO* drawableVector [[buffer(idFillDrawableUBO)]]) {
|
||||
|
||||
device const FillOutlineTriangulatedDrawableUBO& drawable = drawableVector[uboIndex].fillOutlineTriangulatedDrawableUBO;
|
||||
|
||||
// the distance over which the line edge fades out.
|
||||
// Retina devices need a smaller distance to avoid aliasing.
|
||||
@@ -571,7 +653,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
}
|
||||
|
||||
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
|
||||
device const FillEvaluatedPropsUBO& props [[buffer(4)]]) {
|
||||
device const FillEvaluatedPropsUBO& props [[buffer(idFillEvaluatedPropsUBO)]]) {
|
||||
|
||||
// Calculate the distance of the pixel from the line in pixels.
|
||||
const float dist = length(in.normal) * in.width2;
|
||||
|
||||
@@ -2,36 +2,91 @@
|
||||
|
||||
#include <mbgl/shaders/fill_extrusion_layer_ubo.hpp>
|
||||
#include <mbgl/shaders/shader_source.hpp>
|
||||
#include <mbgl/shaders/mtl/common.hpp>
|
||||
#include <mbgl/shaders/mtl/shader_program.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
#define FILL_EXTRUSION_SHADER_COMMON \
|
||||
R"(
|
||||
|
||||
enum {
|
||||
idFillExtrusionDrawableUBO = idDrawableReservedVertexOnlyUBO,
|
||||
idFillExtrusionTilePropsUBO = drawableReservedUBOCount,
|
||||
idFillExtrusionPropsUBO,
|
||||
fillExtrusionUBOCount
|
||||
};
|
||||
|
||||
struct alignas(16) FillExtrusionDrawableUBO {
|
||||
/* 0 */ float4x4 matrix;
|
||||
/* 64 */ float2 pixel_coord_upper;
|
||||
/* 72 */ float2 pixel_coord_lower;
|
||||
/* 80 */ float height_factor;
|
||||
/* 84 */ float tile_ratio;
|
||||
|
||||
// Interpolations
|
||||
/* 88 */ float base_t;
|
||||
/* 92 */ float height_t;
|
||||
/* 96 */ float color_t;
|
||||
/* 100 */ float pattern_from_t;
|
||||
/* 104 */ float pattern_to_t;
|
||||
/* 108 */ float pad1;
|
||||
/* 112 */
|
||||
};
|
||||
static_assert(sizeof(FillExtrusionDrawableUBO) == 7 * 16, "wrong size");
|
||||
|
||||
struct alignas(16) FillExtrusionTilePropsUBO {
|
||||
/* 0 */ float4 pattern_from;
|
||||
/* 16 */ float4 pattern_to;
|
||||
/* 32 */ float2 texsize;
|
||||
/* 40 */ float pad1;
|
||||
/* 44 */ float pad2;
|
||||
/* 48 */
|
||||
};
|
||||
static_assert(sizeof(FillExtrusionTilePropsUBO) == 3 * 16, "wrong size");
|
||||
|
||||
/// Evaluated properties that do not depend on the tile
|
||||
struct alignas(16) FillExtrusionPropsUBO {
|
||||
/* 0 */ float4 color;
|
||||
/* 16 */ float4 light_color_pad;
|
||||
/* 32 */ float4 light_position_base;
|
||||
/* 48 */ float height;
|
||||
/* 52 */ float light_intensity;
|
||||
/* 56 */ float vertical_gradient;
|
||||
/* 60 */ float opacity;
|
||||
/* 64 */ float fade;
|
||||
/* 68 */ float from_scale;
|
||||
/* 72 */ float to_scale;
|
||||
/* 76 */ float pad2;
|
||||
/* 80 */
|
||||
};
|
||||
static_assert(sizeof(FillExtrusionPropsUBO) == 5 * 16, "wrong size");
|
||||
|
||||
)"
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::FillExtrusionShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto name = "FillExtrusionShader";
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static const std::array<UniformBlockInfo, 3> uniforms;
|
||||
static const std::array<AttributeInfo, 5> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static const std::array<TextureInfo, 0> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
static constexpr auto source = FILL_EXTRUSION_SHADER_COMMON R"(
|
||||
struct VertexStage {
|
||||
short2 pos [[attribute(5)]];
|
||||
short4 normal_ed [[attribute(6)]];
|
||||
short2 pos [[attribute(fillExtrusionUBOCount + 0)]];
|
||||
short4 normal_ed [[attribute(fillExtrusionUBOCount + 1)]];
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_color)
|
||||
float4 color [[attribute(7)]];
|
||||
float4 color [[attribute(fillExtrusionUBOCount + 2)]];
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_base)
|
||||
float base [[attribute(8)]];
|
||||
float base [[attribute(fillExtrusionUBOCount + 3)]];
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_height)
|
||||
float height [[attribute(9)]];
|
||||
float height [[attribute(fillExtrusionUBOCount + 4)]];
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -46,19 +101,21 @@ struct FragmentOutput {
|
||||
};
|
||||
|
||||
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
device const FillExtrusionDrawableUBO& drawable [[buffer(1)]],
|
||||
device const FillExtrusionInterpolateUBO& interp [[buffer(3)]],
|
||||
device const FillExtrusionPropsUBO& props [[buffer(4)]]) {
|
||||
device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]],
|
||||
device const FillExtrusionDrawableUBO* drawableVector [[buffer(idFillExtrusionDrawableUBO)]],
|
||||
device const FillExtrusionPropsUBO& props [[buffer(idFillExtrusionPropsUBO)]]) {
|
||||
|
||||
device const FillExtrusionDrawableUBO& drawable = drawableVector[uboIndex];
|
||||
|
||||
#if defined(HAS_UNIFORM_u_base)
|
||||
const auto base = props.light_position_base.w;
|
||||
#else
|
||||
const auto base = max(unpack_mix_float(vertx.base, interp.base_t), 0.0);
|
||||
const auto base = max(unpack_mix_float(vertx.base, drawable.base_t), 0.0);
|
||||
#endif
|
||||
#if defined(HAS_UNIFORM_u_height)
|
||||
const auto height = props.height;
|
||||
#else
|
||||
const auto height = max(unpack_mix_float(vertx.height, interp.height_t), 0.0);
|
||||
const auto height = max(unpack_mix_float(vertx.height, drawable.height_t), 0.0);
|
||||
#endif
|
||||
|
||||
const float3 normal = float3(vertx.normal_ed.xyz);
|
||||
@@ -76,7 +133,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
#if defined(HAS_UNIFORM_u_color)
|
||||
auto color = props.color;
|
||||
#else
|
||||
auto color = unpack_mix_color(vertx.color, interp.color_t);
|
||||
auto color = unpack_mix_color(vertx.color, drawable.color_t);
|
||||
#endif
|
||||
|
||||
// Relative luminance (how dark/bright is the surface color?)
|
||||
@@ -126,5 +183,189 @@ fragment FragmentOutput fragmentMain(FragmentStage in [[stage_in]]) {
|
||||
)";
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::FillExtrusionPatternShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto name = "FillExtrusionPatternShader";
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static const std::array<AttributeInfo, 6> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static const std::array<TextureInfo, 1> textures;
|
||||
|
||||
static constexpr auto source = FILL_EXTRUSION_SHADER_COMMON R"(
|
||||
struct VertexStage {
|
||||
short2 pos [[attribute(fillExtrusionUBOCount + 0)]];
|
||||
short4 normal_ed [[attribute(fillExtrusionUBOCount + 1)]];
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_base)
|
||||
float base [[attribute(fillExtrusionUBOCount + 2)]];
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_height)
|
||||
float height [[attribute(fillExtrusionUBOCount + 3)]];
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_pattern_from)
|
||||
ushort4 pattern_from [[attribute(fillExtrusionUBOCount + 4)]];
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_pattern_to)
|
||||
ushort4 pattern_to [[attribute(fillExtrusionUBOCount + 5)]];
|
||||
#endif
|
||||
};
|
||||
|
||||
struct FragmentStage {
|
||||
float4 position [[position, invariant]];
|
||||
float4 lighting;
|
||||
float2 pos_a;
|
||||
float2 pos_b;
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_pattern_from)
|
||||
half4 pattern_from;
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_pattern_to)
|
||||
half4 pattern_to;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct FragmentOutput {
|
||||
half4 color [[color(0)]];
|
||||
//float depth [[depth(less)]]; // Write depth value if it's less than what's already there
|
||||
};
|
||||
|
||||
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
device const GlobalPaintParamsUBO& paintParams [[buffer(idGlobalPaintParamsUBO)]],
|
||||
device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]],
|
||||
device const FillExtrusionDrawableUBO* drawableVector [[buffer(idFillExtrusionDrawableUBO)]],
|
||||
device const FillExtrusionTilePropsUBO* tilePropsVector [[buffer(idFillExtrusionTilePropsUBO)]],
|
||||
device const FillExtrusionPropsUBO& props [[buffer(idFillExtrusionPropsUBO)]]) {
|
||||
|
||||
device const FillExtrusionDrawableUBO& drawable = drawableVector[uboIndex];
|
||||
device const FillExtrusionTilePropsUBO& tileProps = tilePropsVector[uboIndex];
|
||||
|
||||
#if defined(HAS_UNIFORM_u_base)
|
||||
const auto base = props.light_position_base.w;
|
||||
#else
|
||||
const auto base = max(unpack_mix_float(vertx.base, drawable.base_t), 0.0);
|
||||
#endif
|
||||
#if defined(HAS_UNIFORM_u_height)
|
||||
const auto height = props.height;
|
||||
#else
|
||||
const auto height = max(unpack_mix_float(vertx.height, drawable.height_t), 0.0);
|
||||
#endif
|
||||
|
||||
const float3 normal = float3(vertx.normal_ed.xyz);
|
||||
const float edgedistance = vertx.normal_ed.w;
|
||||
const float t = glMod(normal.x, 2.0);
|
||||
const float z = (t != 0.0) ? height : base; // TODO: This would come out wrong on GL for negative values, check it...
|
||||
const float4 position = drawable.matrix * float4(float2(vertx.pos), z, 1);
|
||||
|
||||
#if defined(OVERDRAW_INSPECTOR)
|
||||
return {
|
||||
.position = position,
|
||||
.lighting = float4(1.0),
|
||||
.pattern_from = float4(1.0),
|
||||
.pattern_to = float4(1.0),
|
||||
.pos_a = float2(1.0),
|
||||
.pos_b = float2(1.0),
|
||||
};
|
||||
#endif
|
||||
|
||||
#if defined(HAS_UNIFORM_u_pattern_from)
|
||||
const auto pattern_from = tileProps.pattern_from;
|
||||
#else
|
||||
const auto pattern_from = float4(vertx.pattern_from);
|
||||
#endif
|
||||
#if defined(HAS_UNIFORM_u_pattern_to)
|
||||
const auto pattern_to = tileProps.pattern_to;
|
||||
#else
|
||||
const auto pattern_to = float4(vertx.pattern_to);
|
||||
#endif
|
||||
|
||||
const float2 pattern_tl_a = pattern_from.xy;
|
||||
const float2 pattern_br_a = pattern_from.zw;
|
||||
const float2 pattern_tl_b = pattern_to.xy;
|
||||
const float2 pattern_br_b = pattern_to.zw;
|
||||
|
||||
const float pixelRatio = paintParams.pixel_ratio;
|
||||
const float tileZoomRatio = drawable.tile_ratio;
|
||||
const float fromScale = props.from_scale;
|
||||
const float toScale = props.to_scale;
|
||||
|
||||
const float2 display_size_a = float2((pattern_br_a.x - pattern_tl_a.x) / pixelRatio, (pattern_br_a.y - pattern_tl_a.y) / pixelRatio);
|
||||
const float2 display_size_b = float2((pattern_br_b.x - pattern_tl_b.x) / pixelRatio, (pattern_br_b.y - pattern_tl_b.y) / pixelRatio);
|
||||
|
||||
const float2 pos = normal.x == 1.0 && normal.y == 0.0 && normal.z == 16384.0
|
||||
? float2(vertx.pos) // extrusion top
|
||||
: float2(edgedistance, z * drawable.height_factor); // extrusion side
|
||||
|
||||
float4 lighting = float4(0.0, 0.0, 0.0, 1.0);
|
||||
float directional = clamp(dot(normal / 16383.0, props.light_position_base.xyz), 0.0, 1.0);
|
||||
directional = mix((1.0 - props.light_intensity), max((0.5 + props.light_intensity), 1.0), directional);
|
||||
|
||||
if (normal.y != 0.0) {
|
||||
// This avoids another branching statement, but multiplies by a constant of 0.84 if no vertical gradient,
|
||||
// and otherwise calculates the gradient based on base + height
|
||||
directional *= (
|
||||
(1.0 - props.vertical_gradient) +
|
||||
(props.vertical_gradient * clamp((t + base) * pow(height / 150.0, 0.5), mix(0.7, 0.98, 1.0 - props.light_intensity), 1.0)));
|
||||
}
|
||||
|
||||
lighting.rgb += clamp(directional * props.light_color_pad.rgb, mix(float3(0.0), float3(0.3), 1.0 - props.light_color_pad.rgb), float3(1.0));
|
||||
lighting *= props.opacity;
|
||||
|
||||
return {
|
||||
.position = position,
|
||||
.lighting = lighting,
|
||||
#if !defined(HAS_UNIFORM_u_pattern_from)
|
||||
.pattern_from = half4(pattern_from),
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_pattern_from)
|
||||
.pattern_to = half4(pattern_to),
|
||||
#endif
|
||||
.pos_a = get_pattern_pos(drawable.pixel_coord_upper, drawable.pixel_coord_lower, fromScale * display_size_a, tileZoomRatio, pos),
|
||||
.pos_b = get_pattern_pos(drawable.pixel_coord_upper, drawable.pixel_coord_lower, toScale * display_size_b, tileZoomRatio, pos),
|
||||
};
|
||||
}
|
||||
|
||||
fragment FragmentOutput fragmentMain(FragmentStage in [[stage_in]],
|
||||
device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]],
|
||||
device const FillExtrusionTilePropsUBO* tilePropsVector [[buffer(idFillExtrusionTilePropsUBO)]],
|
||||
device const FillExtrusionPropsUBO& props [[buffer(idFillExtrusionPropsUBO)]],
|
||||
texture2d<float, access::sample> image0 [[texture(0)]],
|
||||
sampler image0_sampler [[sampler(0)]]) {
|
||||
#if defined(OVERDRAW_INSPECTOR)
|
||||
return {half4(1.0)/*, in.position.z*/};
|
||||
#endif
|
||||
|
||||
device const FillExtrusionTilePropsUBO& tileProps = tilePropsVector[uboIndex];
|
||||
|
||||
#if defined(HAS_UNIFORM_u_pattern_from)
|
||||
const auto pattern_from = float4(tileProps.pattern_from);
|
||||
#else
|
||||
const auto pattern_from = float4(in.pattern_from);
|
||||
#endif
|
||||
#if defined(HAS_UNIFORM_u_pattern_to)
|
||||
const auto pattern_to = float4(tileProps.pattern_to);
|
||||
#else
|
||||
const auto pattern_to = float4(in.pattern_to);
|
||||
#endif
|
||||
|
||||
const float2 pattern_tl_a = pattern_from.xy;
|
||||
const float2 pattern_br_a = pattern_from.zw;
|
||||
const float2 pattern_tl_b = pattern_to.xy;
|
||||
const float2 pattern_br_b = pattern_to.zw;
|
||||
|
||||
const float2 imagecoord = glMod(in.pos_a, 1.0);
|
||||
const float2 pos = mix(pattern_tl_a / tileProps.texsize, pattern_br_a / tileProps.texsize, imagecoord);
|
||||
const float4 color1 = image0.sample(image0_sampler, pos);
|
||||
|
||||
const float2 imagecoord_b = glMod(in.pos_b, 1.0);
|
||||
const float2 pos2 = mix(pattern_tl_b / tileProps.texsize, pattern_br_b / tileProps.texsize, imagecoord_b);
|
||||
const float4 color2 = image0.sample(image0_sampler, pos2);
|
||||
|
||||
return {half4(mix(color1, color2, props.fade) * in.lighting)/*, in.position.z*/};
|
||||
}
|
||||
)";
|
||||
};
|
||||
|
||||
} // namespace shaders
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -1,192 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/shaders/fill_extrusion_layer_ubo.hpp>
|
||||
#include <mbgl/shaders/shader_source.hpp>
|
||||
#include <mbgl/shaders/mtl/common.hpp>
|
||||
#include <mbgl/shaders/mtl/shader_program.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::FillExtrusionPatternShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto name = "FillExtrusionPatternShader";
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static const std::array<UniformBlockInfo, 5> uniforms;
|
||||
static const std::array<AttributeInfo, 6> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static const std::array<TextureInfo, 1> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
struct VertexStage {
|
||||
short2 pos [[attribute(5)]];
|
||||
short4 normal_ed [[attribute(6)]];
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_base)
|
||||
float base [[attribute(7)]];
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_height)
|
||||
float height [[attribute(8)]];
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_pattern_from)
|
||||
ushort4 pattern_from [[attribute(9)]];
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_pattern_to)
|
||||
ushort4 pattern_to [[attribute(10)]];
|
||||
#endif
|
||||
};
|
||||
|
||||
struct FragmentStage {
|
||||
float4 position [[position, invariant]];
|
||||
float4 lighting;
|
||||
float2 pos_a;
|
||||
float2 pos_b;
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_pattern_from)
|
||||
half4 pattern_from;
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_pattern_to)
|
||||
half4 pattern_to;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct FragmentOutput {
|
||||
half4 color [[color(0)]];
|
||||
//float depth [[depth(less)]]; // Write depth value if it's less than what's already there
|
||||
};
|
||||
|
||||
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
device const GlobalPaintParamsUBO& paintParams [[buffer(0)]],
|
||||
device const FillExtrusionDrawableUBO& drawable [[buffer(1)]],
|
||||
device const FillExtrusionTilePropsUBO& tileProps [[buffer(2)]],
|
||||
device const FillExtrusionInterpolateUBO& interp [[buffer(3)]],
|
||||
device const FillExtrusionPropsUBO& props [[buffer(4)]]) {
|
||||
|
||||
#if defined(HAS_UNIFORM_u_base)
|
||||
const auto base = props.light_position_base.w;
|
||||
#else
|
||||
const auto base = max(unpack_mix_float(vertx.base, interp.base_t), 0.0);
|
||||
#endif
|
||||
#if defined(HAS_UNIFORM_u_height)
|
||||
const auto height = props.height;
|
||||
#else
|
||||
const auto height = max(unpack_mix_float(vertx.height, interp.height_t), 0.0);
|
||||
#endif
|
||||
|
||||
const float3 normal = float3(vertx.normal_ed.xyz);
|
||||
const float edgedistance = vertx.normal_ed.w;
|
||||
const float t = glMod(normal.x, 2.0);
|
||||
const float z = (t != 0.0) ? height : base; // TODO: This would come out wrong on GL for negative values, check it...
|
||||
const float4 position = drawable.matrix * float4(float2(vertx.pos), z, 1);
|
||||
|
||||
#if defined(OVERDRAW_INSPECTOR)
|
||||
return {
|
||||
.position = position,
|
||||
.lighting = float4(1.0),
|
||||
.pattern_from = float4(1.0),
|
||||
.pattern_to = float4(1.0),
|
||||
.pos_a = float2(1.0),
|
||||
.pos_b = float2(1.0),
|
||||
};
|
||||
#endif
|
||||
|
||||
#if defined(HAS_UNIFORM_u_pattern_from)
|
||||
const auto pattern_from = tileProps.pattern_from;
|
||||
#else
|
||||
const auto pattern_from = float4(vertx.pattern_from);
|
||||
#endif
|
||||
#if defined(HAS_UNIFORM_u_pattern_to)
|
||||
const auto pattern_to = tileProps.pattern_to;
|
||||
#else
|
||||
const auto pattern_to = float4(vertx.pattern_to);
|
||||
#endif
|
||||
|
||||
const float2 pattern_tl_a = pattern_from.xy;
|
||||
const float2 pattern_br_a = pattern_from.zw;
|
||||
const float2 pattern_tl_b = pattern_to.xy;
|
||||
const float2 pattern_br_b = pattern_to.zw;
|
||||
|
||||
const float pixelRatio = paintParams.pixel_ratio;
|
||||
const float tileZoomRatio = drawable.tile_ratio;
|
||||
const float fromScale = props.from_scale;
|
||||
const float toScale = props.to_scale;
|
||||
|
||||
const float2 display_size_a = float2((pattern_br_a.x - pattern_tl_a.x) / pixelRatio, (pattern_br_a.y - pattern_tl_a.y) / pixelRatio);
|
||||
const float2 display_size_b = float2((pattern_br_b.x - pattern_tl_b.x) / pixelRatio, (pattern_br_b.y - pattern_tl_b.y) / pixelRatio);
|
||||
|
||||
const float2 pos = normal.x == 1.0 && normal.y == 0.0 && normal.z == 16384.0
|
||||
? float2(vertx.pos) // extrusion top
|
||||
: float2(edgedistance, z * drawable.height_factor); // extrusion side
|
||||
|
||||
float4 lighting = float4(0.0, 0.0, 0.0, 1.0);
|
||||
float directional = clamp(dot(normal / 16383.0, props.light_position_base.xyz), 0.0, 1.0);
|
||||
directional = mix((1.0 - props.light_intensity), max((0.5 + props.light_intensity), 1.0), directional);
|
||||
|
||||
if (normal.y != 0.0) {
|
||||
// This avoids another branching statement, but multiplies by a constant of 0.84 if no vertical gradient,
|
||||
// and otherwise calculates the gradient based on base + height
|
||||
directional *= (
|
||||
(1.0 - props.vertical_gradient) +
|
||||
(props.vertical_gradient * clamp((t + base) * pow(height / 150.0, 0.5), mix(0.7, 0.98, 1.0 - props.light_intensity), 1.0)));
|
||||
}
|
||||
|
||||
lighting.rgb += clamp(directional * props.light_color_pad.rgb, mix(float3(0.0), float3(0.3), 1.0 - props.light_color_pad.rgb), float3(1.0));
|
||||
lighting *= props.opacity;
|
||||
|
||||
return {
|
||||
.position = position,
|
||||
.lighting = lighting,
|
||||
#if !defined(HAS_UNIFORM_u_pattern_from)
|
||||
.pattern_from = half4(pattern_from),
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_pattern_from)
|
||||
.pattern_to = half4(pattern_to),
|
||||
#endif
|
||||
.pos_a = get_pattern_pos(drawable.pixel_coord_upper, drawable.pixel_coord_lower, fromScale * display_size_a, tileZoomRatio, pos),
|
||||
.pos_b = get_pattern_pos(drawable.pixel_coord_upper, drawable.pixel_coord_lower, toScale * display_size_b, tileZoomRatio, pos),
|
||||
};
|
||||
}
|
||||
|
||||
fragment FragmentOutput fragmentMain(FragmentStage in [[stage_in]],
|
||||
device const FillExtrusionDrawableUBO& drawable [[buffer(1)]],
|
||||
device const FillExtrusionTilePropsUBO& tileProps [[buffer(2)]],
|
||||
device const FillExtrusionPropsUBO& props [[buffer(4)]],
|
||||
texture2d<float, access::sample> image0 [[texture(0)]],
|
||||
sampler image0_sampler [[sampler(0)]]) {
|
||||
#if defined(OVERDRAW_INSPECTOR)
|
||||
return {half4(1.0)/*, in.position.z*/};
|
||||
#endif
|
||||
|
||||
#if defined(HAS_UNIFORM_u_pattern_from)
|
||||
const auto pattern_from = float4(tileProps.pattern_from);
|
||||
#else
|
||||
const auto pattern_from = float4(in.pattern_from);
|
||||
#endif
|
||||
#if defined(HAS_UNIFORM_u_pattern_to)
|
||||
const auto pattern_to = float4(tileProps.pattern_to);
|
||||
#else
|
||||
const auto pattern_to = float4(in.pattern_to);
|
||||
#endif
|
||||
|
||||
const float2 pattern_tl_a = pattern_from.xy;
|
||||
const float2 pattern_br_a = pattern_from.zw;
|
||||
const float2 pattern_tl_b = pattern_to.xy;
|
||||
const float2 pattern_br_b = pattern_to.zw;
|
||||
|
||||
const float2 imagecoord = glMod(in.pos_a, 1.0);
|
||||
const float2 pos = mix(pattern_tl_a / drawable.texsize, pattern_br_a / drawable.texsize, imagecoord);
|
||||
const float4 color1 = image0.sample(image0_sampler, pos);
|
||||
|
||||
const float2 imagecoord_b = glMod(in.pos_b, 1.0);
|
||||
const float2 pos2 = mix(pattern_tl_b / drawable.texsize, pattern_br_b / drawable.texsize, imagecoord_b);
|
||||
const float4 color2 = image0.sample(image0_sampler, pos2);
|
||||
|
||||
return {half4(mix(color1, color2, props.fade) * in.lighting)/*, in.position.z*/};
|
||||
}
|
||||
)";
|
||||
};
|
||||
|
||||
} // namespace shaders
|
||||
} // namespace mbgl
|
||||
@@ -2,33 +2,64 @@
|
||||
|
||||
#include <mbgl/shaders/heatmap_layer_ubo.hpp>
|
||||
#include <mbgl/shaders/shader_source.hpp>
|
||||
#include <mbgl/shaders/mtl/common.hpp>
|
||||
#include <mbgl/shaders/mtl/shader_program.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
#define HEATMAP_SHADER_PRELUDE \
|
||||
R"(
|
||||
|
||||
enum {
|
||||
idHeatmapDrawableUBO = idDrawableReservedVertexOnlyUBO,
|
||||
idHeatmapEvaluatedPropsUBO = drawableReservedUBOCount,
|
||||
heatmapUBOCount
|
||||
};
|
||||
|
||||
struct alignas(16) HeatmapDrawableUBO {
|
||||
/* 0 */ float4x4 matrix;
|
||||
/* 64 */ float extrude_scale;
|
||||
|
||||
// Interpolations
|
||||
/* 68 */ float weight_t;
|
||||
/* 72 */ float radius_t;
|
||||
/* 76 */ float pad1;
|
||||
/* 80 */
|
||||
};
|
||||
static_assert(sizeof(HeatmapDrawableUBO) == 5 * 16, "wrong size");
|
||||
|
||||
/// Evaluated properties that do not depend on the tile
|
||||
struct alignas(16) HeatmapEvaluatedPropsUBO {
|
||||
/* 0 */ float weight;
|
||||
/* 4 */ float radius;
|
||||
/* 8 */ float intensity;
|
||||
/* 12 */ float padding;
|
||||
/* 16 */
|
||||
};
|
||||
static_assert(sizeof(HeatmapEvaluatedPropsUBO) == 16, "wrong size");
|
||||
|
||||
)"
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::HeatmapShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto name = "HeatmapShader";
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static const std::array<UniformBlockInfo, 3> uniforms;
|
||||
static const std::array<AttributeInfo, 3> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static const std::array<TextureInfo, 0> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
static constexpr auto source = HEATMAP_SHADER_PRELUDE R"(
|
||||
|
||||
struct VertexStage {
|
||||
short2 pos [[attribute(4)]];
|
||||
short2 pos [[attribute(heatmapUBOCount + 0)]];
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_weight)
|
||||
float2 weight [[attribute(5)]];
|
||||
float2 weight [[attribute(heatmapUBOCount + 1)]];
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_radius)
|
||||
float2 radius [[attribute(6)]];
|
||||
float2 radius [[attribute(heatmapUBOCount + 2)]];
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -38,26 +69,6 @@ struct FragmentStage {
|
||||
float2 extrude;
|
||||
};
|
||||
|
||||
struct alignas(16) HeatmapDrawableUBO {
|
||||
float4x4 matrix;
|
||||
float extrude_scale;
|
||||
float pad1;
|
||||
float2 pad2;
|
||||
};
|
||||
|
||||
struct alignas(16) HeatmapEvaluatedPropsUBO {
|
||||
float weight;
|
||||
float radius;
|
||||
float intensity;
|
||||
float pad1;
|
||||
};
|
||||
|
||||
struct alignas(16) HeatmapInterpolateUBO {
|
||||
float weight_t;
|
||||
float radius_t;
|
||||
float2 pad1;
|
||||
};
|
||||
|
||||
// Effective "0" in the kernel density texture to adjust the kernel size to;
|
||||
// this empirically chosen number minimizes artifacts on overlapping kernels
|
||||
// for typical heatmap cases (assuming clustered source)
|
||||
@@ -67,19 +78,21 @@ constant const float ZERO = 1.0 / 255.0 / 16.0;
|
||||
#define GAUSS_COEF 0.3989422804014327
|
||||
|
||||
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
device const HeatmapDrawableUBO& drawable [[buffer(1)]],
|
||||
device const HeatmapInterpolateUBO& interp [[buffer(2)]],
|
||||
device const HeatmapEvaluatedPropsUBO& props [[buffer(3)]]) {
|
||||
device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]],
|
||||
device const HeatmapDrawableUBO* drawableVector [[buffer(idHeatmapDrawableUBO)]],
|
||||
device const HeatmapEvaluatedPropsUBO& props [[buffer(idHeatmapEvaluatedPropsUBO)]]) {
|
||||
|
||||
device const HeatmapDrawableUBO& drawable = drawableVector[uboIndex];
|
||||
|
||||
#if defined(HAS_UNIFORM_u_weight)
|
||||
const auto weight = props.weight;
|
||||
#else
|
||||
const auto weight = unpack_mix_float(vertx.weight, interp.weight_t);
|
||||
const auto weight = unpack_mix_float(vertx.weight, drawable.weight_t);
|
||||
#endif
|
||||
#if defined(HAS_UNIFORM_u_radius)
|
||||
const auto radius = props.radius;
|
||||
#else
|
||||
const auto radius = unpack_mix_float(vertx.radius, interp.radius_t);
|
||||
const auto radius = unpack_mix_float(vertx.radius, drawable.radius_t);
|
||||
#endif
|
||||
|
||||
// unencode the extrusion vector that we snuck into the a_pos vector
|
||||
@@ -117,7 +130,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
}
|
||||
|
||||
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
|
||||
device const HeatmapEvaluatedPropsUBO& props [[buffer(3)]]) {
|
||||
device const HeatmapEvaluatedPropsUBO& props [[buffer(idHeatmapEvaluatedPropsUBO)]]) {
|
||||
#if defined(OVERDRAW_INSPECTOR)
|
||||
return half4(1.0);
|
||||
#endif
|
||||
|
||||
@@ -2,27 +2,45 @@
|
||||
|
||||
#include <mbgl/shaders/heatmap_texture_layer_ubo.hpp>
|
||||
#include <mbgl/shaders/shader_source.hpp>
|
||||
#include <mbgl/shaders/mtl/common.hpp>
|
||||
#include <mbgl/shaders/mtl/shader_program.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
#define HEATMAP_TEXTURE_SHADER_PRELUDE \
|
||||
R"(
|
||||
|
||||
enum {
|
||||
idHeatmapTexturePropsUBO = drawableReservedUBOCount,
|
||||
heatmapTextureUBOCount
|
||||
};
|
||||
|
||||
struct alignas(16) HeatmapTexturePropsUBO {
|
||||
/* 0 */ float4x4 matrix;
|
||||
/* 64 */ float opacity;
|
||||
/* 68 */ float pad1;
|
||||
/* 72 */ float pad2;
|
||||
/* 76 */ float pad3;
|
||||
/* 80 */
|
||||
};
|
||||
static_assert(sizeof(HeatmapTexturePropsUBO) == 5 * 16, "wrong size");
|
||||
|
||||
)"
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::HeatmapTextureShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto name = "HeatmapTextureShader";
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static const std::array<UniformBlockInfo, 2> uniforms;
|
||||
static const std::array<AttributeInfo, 1> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static const std::array<TextureInfo, 2> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
static constexpr auto source = HEATMAP_TEXTURE_SHADER_PRELUDE R"(
|
||||
|
||||
struct VertexStage {
|
||||
short2 pos [[attribute(2)]];
|
||||
short2 pos [[attribute(heatmapTextureUBOCount + 0)]];
|
||||
};
|
||||
|
||||
struct FragmentStage {
|
||||
@@ -30,15 +48,9 @@ struct FragmentStage {
|
||||
float2 pos;
|
||||
};
|
||||
|
||||
struct alignas(16) HeatmapTexturePropsUBO {
|
||||
float4x4 matrix;
|
||||
float opacity;
|
||||
float pad1, pad2, pad3;
|
||||
};
|
||||
|
||||
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
device const GlobalPaintParamsUBO& paintParams [[buffer(0)]],
|
||||
device const HeatmapTexturePropsUBO& props [[buffer(1)]]) {
|
||||
device const GlobalPaintParamsUBO& paintParams [[buffer(idGlobalPaintParamsUBO)]],
|
||||
device const HeatmapTexturePropsUBO& props [[buffer(idHeatmapTexturePropsUBO)]]) {
|
||||
|
||||
const float2 pos = float2(vertx.pos);
|
||||
const float4 position = props.matrix * float4(pos * paintParams.world_size, 0, 1);
|
||||
@@ -50,7 +62,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
}
|
||||
|
||||
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
|
||||
device const HeatmapTexturePropsUBO& props [[buffer(1)]],
|
||||
device const HeatmapTexturePropsUBO& props [[buffer(idHeatmapTexturePropsUBO)]],
|
||||
texture2d<float, access::sample> image [[texture(0)]],
|
||||
texture2d<float, access::sample> color_ramp [[texture(1)]],
|
||||
sampler image_sampler [[sampler(0)]],
|
||||
|
||||
@@ -2,28 +2,60 @@
|
||||
|
||||
#include <mbgl/shaders/hillshade_layer_ubo.hpp>
|
||||
#include <mbgl/shaders/shader_source.hpp>
|
||||
#include <mbgl/shaders/mtl/common.hpp>
|
||||
#include <mbgl/shaders/mtl/shader_program.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
#define HILLSHADE_SHADER_PRELUDE \
|
||||
R"(
|
||||
|
||||
enum {
|
||||
idHillshadeDrawableUBO = idDrawableReservedVertexOnlyUBO,
|
||||
idHillshadeTilePropsUBO = idDrawableReservedFragmentOnlyUBO,
|
||||
idHillshadeEvaluatedPropsUBO = drawableReservedUBOCount,
|
||||
hillshadeUBOCount
|
||||
};
|
||||
|
||||
struct alignas(16) HillshadeDrawableUBO {
|
||||
/* 0 */ float4x4 matrix;
|
||||
/* 64 */
|
||||
};
|
||||
static_assert(sizeof(HillshadeDrawableUBO) == 4 * 16, "wrong size");
|
||||
|
||||
struct alignas(16) HillshadeTilePropsUBO {
|
||||
/* 0 */ float2 latrange;
|
||||
/* 8 */ float2 light;
|
||||
/* 16 */
|
||||
};
|
||||
static_assert(sizeof(HillshadeTilePropsUBO) == 16, "wrong size");
|
||||
|
||||
/// Evaluated properties that do not depend on the tile
|
||||
struct alignas(16) HillshadeEvaluatedPropsUBO {
|
||||
/* 0 */ float4 highlight;
|
||||
/* 16 */ float4 shadow;
|
||||
/* 32 */ float4 accent;
|
||||
/* 48 */
|
||||
};
|
||||
static_assert(sizeof(HillshadeEvaluatedPropsUBO) == 3 * 16, "wrong size");
|
||||
|
||||
)"
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::HillshadeShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto name = "HillshadeShader";
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static const std::array<UniformBlockInfo, 2> uniforms;
|
||||
static const std::array<AttributeInfo, 2> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static const std::array<TextureInfo, 1> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
static constexpr auto source = HILLSHADE_SHADER_PRELUDE R"(
|
||||
|
||||
struct VertexStage {
|
||||
short2 pos [[attribute(3)]];
|
||||
short2 texture_pos [[attribute(4)]];
|
||||
short2 pos [[attribute(hillshadeUBOCount + 0)]];
|
||||
short2 texture_pos [[attribute(hillshadeUBOCount + 1)]];
|
||||
};
|
||||
|
||||
struct FragmentStage {
|
||||
@@ -31,21 +63,12 @@ struct FragmentStage {
|
||||
float2 pos;
|
||||
};
|
||||
|
||||
struct alignas(16) HillshadeDrawableUBO {
|
||||
float4x4 matrix;
|
||||
float2 latrange;
|
||||
float2 light;
|
||||
};
|
||||
|
||||
struct alignas(16) HillshadeEvaluatedPropsUBO {
|
||||
float4 highlight;
|
||||
float4 shadow;
|
||||
float4 accent;
|
||||
};
|
||||
|
||||
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
device const HillshadeDrawableUBO& drawable [[buffer(1)]]) {
|
||||
device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]],
|
||||
device const HillshadeDrawableUBO* drawableVector [[buffer(idHillshadeDrawableUBO)]]) {
|
||||
|
||||
device const HillshadeDrawableUBO& drawable = drawableVector[uboIndex];
|
||||
|
||||
const float4 position = drawable.matrix * float4(float2(vertx.pos), 0, 1);
|
||||
float2 pos = float2(vertx.texture_pos) / 8192.0;
|
||||
pos.y = 1.0 - pos.y;
|
||||
@@ -57,30 +80,33 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
}
|
||||
|
||||
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
|
||||
device const HillshadeDrawableUBO& drawable [[buffer(1)]],
|
||||
device const HillshadeEvaluatedPropsUBO& props [[buffer(2)]],
|
||||
device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]],
|
||||
device const HillshadeTilePropsUBO* tilePropsVector [[buffer(idHillshadeTilePropsUBO)]],
|
||||
device const HillshadeEvaluatedPropsUBO& props [[buffer(idHillshadeEvaluatedPropsUBO)]],
|
||||
texture2d<float, access::sample> image [[texture(0)]],
|
||||
sampler image_sampler [[sampler(0)]]) {
|
||||
#if defined(OVERDRAW_INSPECTOR)
|
||||
return half4(1.0);
|
||||
#endif
|
||||
|
||||
device const HillshadeTilePropsUBO& tileProps = tilePropsVector[uboIndex];
|
||||
|
||||
float4 pixel = image.sample(image_sampler, in.pos);
|
||||
|
||||
float2 deriv = ((pixel.rg * 2.0) - 1.0);
|
||||
|
||||
// We divide the slope by a scale factor based on the cosin of the pixel's approximate latitude
|
||||
// to account for mercator projection distortion. see #4807 for details
|
||||
float scaleFactor = cos(radians((drawable.latrange[0] - drawable.latrange[1]) * in.pos.y + drawable.latrange[1]));
|
||||
float scaleFactor = cos(radians((tileProps.latrange[0] - tileProps.latrange[1]) * in.pos.y + tileProps.latrange[1]));
|
||||
// We also multiply the slope by an arbitrary z-factor of 1.25
|
||||
float slope = atan(1.25 * length(deriv) / scaleFactor);
|
||||
float aspect = deriv.x != 0.0 ? atan2(deriv.y, -deriv.x) : M_PI_F / 2.0 * (deriv.y > 0.0 ? 1.0 : -1.0);
|
||||
|
||||
float intensity = drawable.light.x;
|
||||
float intensity = tileProps.light.x;
|
||||
// We add PI to make this property match the global light object, which adds PI/2 to the light's azimuthal
|
||||
// position property to account for 0deg corresponding to north/the top of the viewport in the style spec
|
||||
// and the original shader was written to accept (-illuminationDirection - 90) as the azimuthal.
|
||||
float azimuth = drawable.light.y + M_PI_F;
|
||||
float azimuth = tileProps.light.y + M_PI_F;
|
||||
|
||||
// We scale the slope exponentially based on intensity, using a calculation similar to
|
||||
// the exponential interpolation function in the style spec:
|
||||
|
||||
@@ -2,27 +2,51 @@
|
||||
|
||||
#include <mbgl/shaders/hillshade_prepare_layer_ubo.hpp>
|
||||
#include <mbgl/shaders/shader_source.hpp>
|
||||
#include <mbgl/shaders/mtl/common.hpp>
|
||||
#include <mbgl/shaders/mtl/shader_program.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
#define HILLSHADE_PREPARE_SHADER_PRELUDE \
|
||||
R"(
|
||||
|
||||
enum {
|
||||
idHillshadePrepareDrawableUBO = idDrawableReservedVertexOnlyUBO,
|
||||
idHillshadePrepareTilePropsUBO = drawableReservedUBOCount,
|
||||
hillshadePrepareUBOCount
|
||||
};
|
||||
|
||||
struct alignas(16) HillshadePrepareDrawableUBO {
|
||||
/* 0 */ float4x4 matrix;
|
||||
/* 64 */
|
||||
};
|
||||
static_assert(sizeof(HillshadePrepareDrawableUBO) == 4 * 16, "wrong size");
|
||||
|
||||
struct alignas(16) HillshadePrepareTilePropsUBO {
|
||||
/* 0 */ float4 unpack;
|
||||
/* 16 */ float2 dimension;
|
||||
/* 24 */ float zoom;
|
||||
/* 28 */ float maxzoom;
|
||||
/* 32 */
|
||||
};
|
||||
static_assert(sizeof(HillshadePrepareTilePropsUBO) == 2 * 16, "wrong size");
|
||||
|
||||
)"
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::HillshadePrepareShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto name = "HillshadePrepareShader";
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static const std::array<UniformBlockInfo, 1> uniforms;
|
||||
static const std::array<AttributeInfo, 2> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static const std::array<TextureInfo, 1> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
static constexpr auto source = HILLSHADE_PREPARE_SHADER_PRELUDE R"(
|
||||
struct VertexStage {
|
||||
short2 pos [[attribute(2)]];
|
||||
short2 texture_pos [[attribute(3)]];
|
||||
short2 pos [[attribute(hillshadePrepareUBOCount + 0)]];
|
||||
short2 texture_pos [[attribute(hillshadePrepareUBOCount + 1)]];
|
||||
};
|
||||
|
||||
struct FragmentStage {
|
||||
@@ -30,21 +54,14 @@ struct FragmentStage {
|
||||
float2 pos;
|
||||
};
|
||||
|
||||
struct alignas(16) HillshadePrepareDrawableUBO {
|
||||
float4x4 matrix;
|
||||
float4 unpack;
|
||||
float2 dimension;
|
||||
float zoom;
|
||||
float maxzoom;
|
||||
};
|
||||
|
||||
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
device const HillshadePrepareDrawableUBO& drawable [[buffer(1)]]) {
|
||||
device const HillshadePrepareDrawableUBO& drawable [[buffer(idHillshadePrepareDrawableUBO)]],
|
||||
device const HillshadePrepareTilePropsUBO& tileProps [[buffer(idHillshadePrepareTilePropsUBO)]]) {
|
||||
|
||||
const float4 position = drawable.matrix * float4(float2(vertx.pos), 0, 1);
|
||||
|
||||
float2 epsilon = 1.0 / drawable.dimension;
|
||||
float scale = (drawable.dimension.x - 2.0) / drawable.dimension.x;
|
||||
float2 epsilon = 1.0 / tileProps.dimension;
|
||||
float scale = (tileProps.dimension.x - 2.0) / tileProps.dimension.x;
|
||||
const float2 pos = (float2(vertx.texture_pos) / 8192.0) * scale + epsilon;
|
||||
|
||||
return {
|
||||
@@ -61,14 +78,14 @@ float getElevation(float2 coord, float bias, texture2d<float, access::sample> im
|
||||
}
|
||||
|
||||
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
|
||||
device const HillshadePrepareDrawableUBO& drawable [[buffer(1)]],
|
||||
device const HillshadePrepareTilePropsUBO& tileProps [[buffer(idHillshadePrepareTilePropsUBO)]],
|
||||
texture2d<float, access::sample> image [[texture(0)]],
|
||||
sampler image_sampler [[sampler(0)]]) {
|
||||
#if defined(OVERDRAW_INSPECTOR)
|
||||
return half4(1.0);
|
||||
#endif
|
||||
|
||||
float2 epsilon = 1.0 / drawable.dimension;
|
||||
float2 epsilon = 1.0 / tileProps.dimension;
|
||||
|
||||
// queried pixels:
|
||||
// +-----------+
|
||||
@@ -85,15 +102,15 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]],
|
||||
// | | | |
|
||||
// +-----------+
|
||||
|
||||
float a = getElevation(in.pos + float2(-epsilon.x, -epsilon.y), 0.0, image, image_sampler, drawable.unpack);
|
||||
float b = getElevation(in.pos + float2(0, -epsilon.y), 0.0, image, image_sampler, drawable.unpack);
|
||||
float c = getElevation(in.pos + float2(epsilon.x, -epsilon.y), 0.0, image, image_sampler, drawable.unpack);
|
||||
float d = getElevation(in.pos + float2(-epsilon.x, 0), 0.0, image, image_sampler, drawable.unpack);
|
||||
//float e = getElevation(in.pos, 0.0, image, image_sampler, drawable.unpack);
|
||||
float f = getElevation(in.pos + float2(epsilon.x, 0), 0.0, image, image_sampler, drawable.unpack);
|
||||
float g = getElevation(in.pos + float2(-epsilon.x, epsilon.y), 0.0, image, image_sampler, drawable.unpack);
|
||||
float h = getElevation(in.pos + float2(0, epsilon.y), 0.0, image, image_sampler, drawable.unpack);
|
||||
float i = getElevation(in.pos + float2(epsilon.x, epsilon.y), 0.0, image, image_sampler, drawable.unpack);
|
||||
float a = getElevation(in.pos + float2(-epsilon.x, -epsilon.y), 0.0, image, image_sampler, tileProps.unpack);
|
||||
float b = getElevation(in.pos + float2(0, -epsilon.y), 0.0, image, image_sampler, tileProps.unpack);
|
||||
float c = getElevation(in.pos + float2(epsilon.x, -epsilon.y), 0.0, image, image_sampler, tileProps.unpack);
|
||||
float d = getElevation(in.pos + float2(-epsilon.x, 0), 0.0, image, image_sampler, tileProps.unpack);
|
||||
//float e = getElevation(in.pos, 0.0, image, image_sampler, tileProps.unpack);
|
||||
float f = getElevation(in.pos + float2(epsilon.x, 0), 0.0, image, image_sampler, tileProps.unpack);
|
||||
float g = getElevation(in.pos + float2(-epsilon.x, epsilon.y), 0.0, image, image_sampler, tileProps.unpack);
|
||||
float h = getElevation(in.pos + float2(0, epsilon.y), 0.0, image, image_sampler, tileProps.unpack);
|
||||
float i = getElevation(in.pos + float2(epsilon.x, epsilon.y), 0.0, image, image_sampler, tileProps.unpack);
|
||||
|
||||
// here we divide the x and y slopes by 8 * pixel size
|
||||
// where pixel size (aka meters/pixel) is:
|
||||
@@ -106,12 +123,12 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]],
|
||||
// Here we use a=0.3 which works out to the expression below. see
|
||||
// nickidlugash's awesome breakdown for more info
|
||||
// https://github.com/mapbox/mapbox-gl-js/pull/5286#discussion_r148419556
|
||||
float exaggeration = drawable.zoom < 2.0 ? 0.4 : drawable.zoom < 4.5 ? 0.35 : 0.3;
|
||||
float exaggeration = tileProps.zoom < 2.0 ? 0.4 : tileProps.zoom < 4.5 ? 0.35 : 0.3;
|
||||
|
||||
float2 deriv = float2(
|
||||
(c + f + f + i) - (a + d + d + g),
|
||||
(g + h + h + i) - (a + b + b + c)
|
||||
) / pow(2.0, (drawable.zoom - drawable.maxzoom) * exaggeration + 19.2562 - drawable.zoom);
|
||||
) / pow(2.0, (tileProps.zoom - tileProps.maxzoom) * exaggeration + 19.2562 - tileProps.zoom);
|
||||
|
||||
float4 color = clamp(float4(
|
||||
deriv.x / 2.0 + 0.5,
|
||||
|
||||
@@ -2,24 +2,188 @@
|
||||
|
||||
#include <mbgl/shaders/line_layer_ubo.hpp>
|
||||
#include <mbgl/shaders/shader_source.hpp>
|
||||
#include <mbgl/shaders/mtl/common.hpp>
|
||||
#include <mbgl/shaders/mtl/shader_program.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
#define LINE_SHADER_COMMON \
|
||||
R"(
|
||||
|
||||
enum {
|
||||
idLineDrawableUBO = idDrawableReservedVertexOnlyUBO,
|
||||
idLineTilePropsUBO = idDrawableReservedFragmentOnlyUBO,
|
||||
idLineEvaluatedPropsUBO = drawableReservedUBOCount,
|
||||
idLineExpressionUBO,
|
||||
lineUBOCount
|
||||
};
|
||||
|
||||
//
|
||||
// Line
|
||||
|
||||
struct alignas(16) LineDrawableUBO {
|
||||
/* 0 */ float4x4 matrix;
|
||||
/* 64 */ float ratio;
|
||||
|
||||
// Interpolations
|
||||
/* 68 */ float color_t;
|
||||
/* 72 */ float blur_t;
|
||||
/* 76 */ float opacity_t;
|
||||
/* 80 */ float gapwidth_t;
|
||||
/* 84 */ float offset_t;
|
||||
/* 88 */ float width_t;
|
||||
/* 92 */ float pad1;
|
||||
/* 96 */
|
||||
};
|
||||
static_assert(sizeof(LineDrawableUBO) == 6 * 16, "wrong size");
|
||||
|
||||
//
|
||||
// Line gradient
|
||||
|
||||
struct alignas(16) LineGradientDrawableUBO {
|
||||
/* 0 */ float4x4 matrix;
|
||||
/* 64 */ float ratio;
|
||||
|
||||
// Interpolations
|
||||
/* 68 */ float blur_t;
|
||||
/* 72 */ float opacity_t;
|
||||
/* 76 */ float gapwidth_t;
|
||||
/* 80 */ float offset_t;
|
||||
/* 84 */ float width_t;
|
||||
/* 88 */ float pad1;
|
||||
/* 92 */ float pad2;
|
||||
/* 96 */
|
||||
};
|
||||
static_assert(sizeof(LineGradientDrawableUBO) == 6 * 16, "wrong size");
|
||||
|
||||
//
|
||||
// Line pattern
|
||||
|
||||
struct alignas(16) LinePatternDrawableUBO {
|
||||
/* 0 */ float4x4 matrix;
|
||||
/* 64 */ float ratio;
|
||||
|
||||
// Interpolations
|
||||
/* 68 */ float blur_t;
|
||||
/* 72 */ float opacity_t;
|
||||
/* 76 */ float gapwidth_t;
|
||||
/* 80 */ float offset_t;
|
||||
/* 84 */ float width_t;
|
||||
/* 88 */ float pattern_from_t;
|
||||
/* 92 */ float pattern_to_t;
|
||||
/* 96 */
|
||||
};
|
||||
static_assert(sizeof(LinePatternDrawableUBO) == 6 * 16, "wrong size");
|
||||
|
||||
struct alignas(16) LinePatternTilePropsUBO {
|
||||
/* 0 */ float4 pattern_from;
|
||||
/* 16 */ float4 pattern_to;
|
||||
/* 32 */ float4 scale;
|
||||
/* 48 */ float2 texsize;
|
||||
/* 56 */ float fade;
|
||||
/* 60 */ float pad2;
|
||||
/* 64 */
|
||||
};
|
||||
static_assert(sizeof(LinePatternTilePropsUBO) == 4 * 16, "wrong size");
|
||||
|
||||
//
|
||||
// Line SDF
|
||||
|
||||
struct alignas(16) LineSDFDrawableUBO {
|
||||
/* 0 */ float4x4 matrix;
|
||||
/* 64 */ float2 patternscale_a;
|
||||
/* 72 */ float2 patternscale_b;
|
||||
/* 80 */ float tex_y_a;
|
||||
/* 84 */ float tex_y_b;
|
||||
/* 88 */ float ratio;
|
||||
|
||||
// Interpolations
|
||||
/* 92 */ float color_t;
|
||||
/* 96 */ float blur_t;
|
||||
/* 100 */ float opacity_t;
|
||||
/* 104 */ float gapwidth_t;
|
||||
/* 108 */ float offset_t;
|
||||
/* 112 */ float width_t;
|
||||
/* 116 */ float floorwidth_t;
|
||||
/* 120 */ float pad1;
|
||||
/* 124 */ float pad2;
|
||||
/* 128 */
|
||||
};
|
||||
static_assert(sizeof(LineSDFDrawableUBO) == 8 * 16, "wrong size");
|
||||
|
||||
struct alignas(16) LineSDFTilePropsUBO {
|
||||
/* 0 */ float sdfgamma;
|
||||
/* 4 */ float mix;
|
||||
/* 8 */ float pad1;
|
||||
/* 12 */ float pad2;
|
||||
/* 16 */
|
||||
};
|
||||
static_assert(sizeof(LineSDFTilePropsUBO) == 16, "wrong size");
|
||||
|
||||
/// Expression properties that do not depend on the tile
|
||||
enum class LineExpressionMask : uint32_t {
|
||||
None = 0,
|
||||
Color = 1 << 0,
|
||||
Opacity = 1 << 1,
|
||||
Blur = 1 << 2,
|
||||
Width = 1 << 3,
|
||||
GapWidth = 1 << 4,
|
||||
FloorWidth = 1 << 5,
|
||||
Offset = 1 << 6,
|
||||
};
|
||||
bool operator&(LineExpressionMask a, LineExpressionMask b) { return (uint32_t)a & (uint32_t)b; }
|
||||
|
||||
struct alignas(16) LineExpressionUBO {
|
||||
GPUExpression color;
|
||||
GPUExpression blur;
|
||||
GPUExpression opacity;
|
||||
GPUExpression gapwidth;
|
||||
GPUExpression offset;
|
||||
GPUExpression width;
|
||||
GPUExpression floorwidth;
|
||||
};
|
||||
static_assert(sizeof(LineExpressionUBO) % 16 == 0, "wrong alignment");
|
||||
|
||||
/// Evaluated properties that do not depend on the tile
|
||||
struct alignas(16) LineEvaluatedPropsUBO {
|
||||
/* 0 */ float4 color;
|
||||
/* 16 */ float blur;
|
||||
/* 20 */ float opacity;
|
||||
/* 24 */ float gapwidth;
|
||||
/* 28 */ float offset;
|
||||
/* 32 */ float width;
|
||||
/* 36 */ float floorwidth;
|
||||
/* 40 */ LineExpressionMask expressionMask;
|
||||
/* 44 */ float pad1;
|
||||
/* 48 */
|
||||
};
|
||||
static_assert(sizeof(LineEvaluatedPropsUBO) == 3 * 16, "wrong size");
|
||||
|
||||
union LineDrawableUnionUBO {
|
||||
LineDrawableUBO lineDrawableUBO;
|
||||
LineGradientDrawableUBO lineGradientDrawableUBO;
|
||||
LinePatternDrawableUBO linePatternDrawableUBO;
|
||||
LineSDFDrawableUBO lineSDFDrawableUBO;
|
||||
};
|
||||
|
||||
union LineTilePropsUnionUBO {
|
||||
LinePatternTilePropsUBO linePatternTilePropsUBO;
|
||||
LineSDFTilePropsUBO lineSDFTilePropsUBO;
|
||||
};
|
||||
|
||||
)"
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::LineShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto name = "LineShader";
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static const std::array<UniformBlockInfo, 5> uniforms;
|
||||
static const std::array<AttributeInfo, 8> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static const std::array<TextureInfo, 0> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
static constexpr auto source = LINE_SHADER_COMMON R"(
|
||||
struct VertexStage {
|
||||
short2 pos_normal [[attribute(lineUBOCount + 0)]];
|
||||
uchar4 data [[attribute(lineUBOCount + 1)]];
|
||||
@@ -61,48 +225,34 @@ struct FragmentStage {
|
||||
#endif
|
||||
};
|
||||
|
||||
struct alignas(16) LineDrawableUBO {
|
||||
float4x4 matrix;
|
||||
float ratio;
|
||||
float pad1, pad2, pad3;
|
||||
};
|
||||
|
||||
struct alignas(16) LineInterpolationUBO {
|
||||
float color_t;
|
||||
float blur_t;
|
||||
float opacity_t;
|
||||
float gapwidth_t;
|
||||
float offset_t;
|
||||
float width_t;
|
||||
float pad1, pad2;
|
||||
};
|
||||
|
||||
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
device const GlobalPaintParamsUBO& paintParams [[buffer(idGlobalPaintParamsUBO)]],
|
||||
device const LineDrawableUBO& drawable [[buffer(idLineDrawableUBO)]],
|
||||
device const LineInterpolationUBO& interp [[buffer(idLineInterpolationUBO)]],
|
||||
device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]],
|
||||
device const LineDrawableUnionUBO* drawableVector [[buffer(idLineDrawableUBO)]],
|
||||
device const LineEvaluatedPropsUBO& props [[buffer(idLineEvaluatedPropsUBO)]],
|
||||
device const LineExpressionUBO& expr [[buffer(idLineExpressionUBO)]]) {
|
||||
|
||||
device const LineDrawableUBO& drawable = drawableVector[uboIndex].lineDrawableUBO;
|
||||
|
||||
#if defined(HAS_UNIFORM_u_gapwidth)
|
||||
const auto exprGapWidth = (props.expressionMask & LineExpressionMask::GapWidth);
|
||||
const auto gapwidth = (exprGapWidth ? expr.gapwidth.eval(paintParams.zoom) : props.gapwidth) / 2;
|
||||
const auto gapwidth = (exprGapWidth ? expr.gapwidth.eval(paintParams.map_zoom) : props.gapwidth) / 2;
|
||||
#else
|
||||
const auto gapwidth = unpack_mix_float(vertx.gapwidth, interp.gapwidth_t) / 2;
|
||||
const auto gapwidth = unpack_mix_float(vertx.gapwidth, drawable.gapwidth_t) / 2;
|
||||
#endif
|
||||
|
||||
#if defined(HAS_UNIFORM_u_offset)
|
||||
const auto exprOffset = (props.expressionMask & LineExpressionMask::Offset);
|
||||
const auto offset = (exprOffset ? expr.offset.eval(paintParams.zoom) : props.offset) * -1;
|
||||
const auto offset = (exprOffset ? expr.offset.eval(paintParams.map_zoom) : props.offset) * -1;
|
||||
#else
|
||||
const auto offset = unpack_mix_float(vertx.offset, interp.offset_t) * -1;
|
||||
const auto offset = unpack_mix_float(vertx.offset, drawable.offset_t) * -1;
|
||||
#endif
|
||||
|
||||
#if defined(HAS_UNIFORM_u_width)
|
||||
const auto exprWidth = (props.expressionMask & LineExpressionMask::Width);
|
||||
const auto width = exprWidth ? expr.width.eval(paintParams.zoom) : props.width;
|
||||
const auto width = exprWidth ? expr.width.eval(paintParams.map_zoom) : props.width;
|
||||
#else
|
||||
const auto width = unpack_mix_float(vertx.width, interp.width_t);
|
||||
const auto width = unpack_mix_float(vertx.width, drawable.width_t);
|
||||
#endif
|
||||
|
||||
// the distance over which the line edge fades out.
|
||||
@@ -148,13 +298,13 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
.gamma_scale = half(extrude_length_without_perspective / extrude_length_with_perspective),
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_color)
|
||||
.color = unpack_mix_color(vertx.color, interp.color_t),
|
||||
.color = unpack_mix_color(vertx.color, drawable.color_t),
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_blur)
|
||||
.blur = unpack_mix_float(vertx.blur, interp.blur_t),
|
||||
.blur = unpack_mix_float(vertx.blur, drawable.blur_t),
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_opacity)
|
||||
.opacity = unpack_mix_float(vertx.opacity, interp.opacity_t),
|
||||
.opacity = unpack_mix_float(vertx.opacity, drawable.opacity_t),
|
||||
#endif
|
||||
};
|
||||
}
|
||||
@@ -169,21 +319,21 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]],
|
||||
|
||||
#if defined(HAS_UNIFORM_u_color)
|
||||
const auto exprColor = (props.expressionMask & LineExpressionMask::Color);
|
||||
const auto color = exprColor ? expr.color.evalColor(paintParams.zoom) : props.color;
|
||||
const auto color = exprColor ? expr.color.evalColor(paintParams.map_zoom) : props.color;
|
||||
#else
|
||||
const float4 color = in.color;
|
||||
#endif
|
||||
|
||||
#if defined(HAS_UNIFORM_u_blur)
|
||||
const auto exprBlur = (props.expressionMask & LineExpressionMask::Blur);
|
||||
const float blur = exprBlur ? expr.blur.eval(paintParams.zoom) : props.blur;
|
||||
const float blur = exprBlur ? expr.blur.eval(paintParams.map_zoom) : props.blur;
|
||||
#else
|
||||
const float blur = in.blur;
|
||||
#endif
|
||||
|
||||
#if defined(HAS_UNIFORM_u_opacity)
|
||||
const auto exprOpacity = (props.expressionMask & LineExpressionMask::Opacity);
|
||||
const float opacity = exprOpacity ? expr.opacity.eval(paintParams.zoom) : props.opacity;
|
||||
const float opacity = exprOpacity ? expr.opacity.eval(paintParams.map_zoom) : props.opacity;
|
||||
#else
|
||||
const float opacity = in.opacity;
|
||||
#endif
|
||||
@@ -207,12 +357,11 @@ struct ShaderSource<BuiltIn::LineGradientShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static const std::array<UniformBlockInfo, 4> uniforms;
|
||||
static const std::array<AttributeInfo, 7> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static const std::array<TextureInfo, 1> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
static constexpr auto source = LINE_SHADER_COMMON R"(
|
||||
struct VertexStage {
|
||||
short2 pos_normal [[attribute(lineUBOCount + 0)]];
|
||||
uchar4 data [[attribute(lineUBOCount + 1)]];
|
||||
@@ -248,48 +397,34 @@ struct FragmentStage {
|
||||
#endif
|
||||
};
|
||||
|
||||
struct alignas(16) LineGradientDrawableUBO {
|
||||
float4x4 matrix;
|
||||
float ratio;
|
||||
float pad1, pad2, pad3;
|
||||
};
|
||||
|
||||
struct alignas(16) LineGradientInterpolationUBO {
|
||||
float blur_t;
|
||||
float opacity_t;
|
||||
float gapwidth_t;
|
||||
float offset_t;
|
||||
float width_t;
|
||||
float pad1, pad2, pad3;
|
||||
};
|
||||
|
||||
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
device const GlobalPaintParamsUBO& paintParams [[buffer(idGlobalPaintParamsUBO)]],
|
||||
device const LineGradientDrawableUBO& drawable [[buffer(idLineDrawableUBO)]],
|
||||
device const LineGradientInterpolationUBO& interp [[buffer(idLineInterpolationUBO)]],
|
||||
device const LineEvaluatedPropsUBO& props [[buffer(idLineEvaluatedPropsUBO)]],
|
||||
device const LineExpressionUBO& expr [[buffer(idLineExpressionUBO)]]) {
|
||||
device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]],
|
||||
device const LineDrawableUnionUBO* drawableVector [[buffer(idLineDrawableUBO)]],
|
||||
device const LineEvaluatedPropsUBO& props [[buffer(idLineEvaluatedPropsUBO)]]) {
|
||||
|
||||
device const LineGradientDrawableUBO& drawable = drawableVector[uboIndex].lineGradientDrawableUBO;
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_blur)
|
||||
const auto blur = unpack_mix_float(vertx.blur, interp.blur_t);
|
||||
const auto blur = unpack_mix_float(vertx.blur, drawable.blur_t);
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_opacity)
|
||||
const auto opacity = unpack_mix_float(vertx.opacity, interp.opacity_t);
|
||||
const auto opacity = unpack_mix_float(vertx.opacity, drawable.opacity_t);
|
||||
#endif
|
||||
#if defined(HAS_UNIFORM_u_gapwidth)
|
||||
const auto gapwidth = props.gapwidth / 2;
|
||||
#else
|
||||
const auto gapwidth = unpack_mix_float(vertx.gapwidth, interp.gapwidth_t) / 2;
|
||||
const auto gapwidth = unpack_mix_float(vertx.gapwidth, drawable.gapwidth_t) / 2;
|
||||
#endif
|
||||
#if defined(HAS_UNIFORM_u_offset)
|
||||
const auto offset = props.offset * -1;
|
||||
#else
|
||||
const auto offset = unpack_mix_float(vertx.offset, interp.offset_t) * -1;
|
||||
const auto offset = unpack_mix_float(vertx.offset, drawable.offset_t) * -1;
|
||||
#endif
|
||||
#if defined(HAS_UNIFORM_u_width)
|
||||
const auto width = props.width;
|
||||
#else
|
||||
const auto width = unpack_mix_float(vertx.width, interp.width_t);
|
||||
const auto width = unpack_mix_float(vertx.width, drawable.width_t);
|
||||
#endif
|
||||
|
||||
// the distance over which the line edge fades out.
|
||||
@@ -347,7 +482,6 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
|
||||
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
|
||||
device const LineEvaluatedPropsUBO& props [[buffer(idLineEvaluatedPropsUBO)]],
|
||||
device const LineExpressionUBO& expr [[buffer(idLineExpressionUBO)]],
|
||||
texture2d<float, access::sample> gradientTexture [[texture(0)]]) {
|
||||
#if defined(OVERDRAW_INSPECTOR)
|
||||
return half4(1.0);
|
||||
@@ -388,12 +522,11 @@ struct ShaderSource<BuiltIn::LinePatternShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static const std::array<UniformBlockInfo, 6> uniforms;
|
||||
static const std::array<AttributeInfo, 9> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static const std::array<TextureInfo, 1> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
static constexpr auto source = LINE_SHADER_COMMON R"(
|
||||
struct VertexStage {
|
||||
short2 pos_normal [[attribute(lineUBOCount + 0)]];
|
||||
uchar4 data [[attribute(lineUBOCount + 1)]];
|
||||
@@ -442,57 +575,34 @@ struct FragmentStage {
|
||||
#endif
|
||||
};
|
||||
|
||||
struct alignas(16) LinePatternDrawableUBO {
|
||||
float4x4 matrix;
|
||||
float4 scale;
|
||||
float2 texsize;
|
||||
float ratio;
|
||||
float fade;
|
||||
};
|
||||
|
||||
struct alignas(16) LinePatternInterpolationUBO {
|
||||
float blur_t;
|
||||
float opacity_t;
|
||||
float offset_t;
|
||||
float gapwidth_t;
|
||||
float width_t;
|
||||
float pattern_from_t;
|
||||
float pattern_to_t;
|
||||
float pad1;
|
||||
};
|
||||
|
||||
struct alignas(16) LinePatternTilePropertiesUBO {
|
||||
float4 pattern_from;
|
||||
float4 pattern_to;
|
||||
};
|
||||
|
||||
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
device const GlobalPaintParamsUBO& paintParams [[buffer(idGlobalPaintParamsUBO)]],
|
||||
device const LinePatternDrawableUBO& drawable [[buffer(idLineDrawableUBO)]],
|
||||
device const LinePatternInterpolationUBO& interp [[buffer(idLineInterpolationUBO)]],
|
||||
device const LinePatternTilePropertiesUBO& tileProps [[buffer(idLineTilePropertiesUBO)]],
|
||||
device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]],
|
||||
device const LineDrawableUnionUBO* drawableVector [[buffer(idLineDrawableUBO)]],
|
||||
device const LineEvaluatedPropsUBO& props [[buffer(idLineEvaluatedPropsUBO)]],
|
||||
device const LineExpressionUBO& expr [[buffer(idLineExpressionUBO)]]) {
|
||||
|
||||
device const LinePatternDrawableUBO& drawable = drawableVector[uboIndex].linePatternDrawableUBO;
|
||||
|
||||
#if defined(HAS_UNIFORM_u_gapwidth)
|
||||
const auto exprGapWidth = (props.expressionMask & LineExpressionMask::GapWidth);
|
||||
const auto gapwidth = (exprGapWidth ? expr.gapwidth.eval(paintParams.zoom) : props.gapwidth) / 2;
|
||||
const auto gapwidth = (exprGapWidth ? expr.gapwidth.eval(paintParams.map_zoom) : props.gapwidth) / 2;
|
||||
#else
|
||||
const auto gapwidth = unpack_mix_float(vertx.gapwidth, interp.gapwidth_t) / 2;
|
||||
const auto gapwidth = unpack_mix_float(vertx.gapwidth, drawable.gapwidth_t) / 2;
|
||||
#endif
|
||||
|
||||
#if defined(HAS_UNIFORM_u_offset)
|
||||
const auto exprOffset = (props.expressionMask & LineExpressionMask::Offset);
|
||||
const auto offset = (exprOffset ? expr.offset.eval(paintParams.zoom) : props.offset) * -1;
|
||||
const auto offset = (exprOffset ? expr.offset.eval(paintParams.map_zoom) : props.offset) * -1;
|
||||
#else
|
||||
const auto offset = unpack_mix_float(vertx.offset, interp.offset_t) * -1;
|
||||
const auto offset = unpack_mix_float(vertx.offset, drawable.offset_t) * -1;
|
||||
#endif
|
||||
|
||||
#if defined(HAS_UNIFORM_u_width)
|
||||
const auto exprWidth = (props.expressionMask & LineExpressionMask::Width);
|
||||
const auto width = exprWidth ? expr.width.eval(paintParams.zoom) : props.width;
|
||||
const auto width = exprWidth ? expr.width.eval(paintParams.map_zoom) : props.width;
|
||||
#else
|
||||
const auto width = unpack_mix_float(vertx.width, interp.width_t);
|
||||
const auto width = unpack_mix_float(vertx.width, drawable.width_t);
|
||||
#endif
|
||||
|
||||
// the distance over which the line edge fades out.
|
||||
@@ -541,10 +651,10 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
.linesofar = linesofar,
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_blur)
|
||||
.blur = half(unpack_mix_float(vertx.blur, interp.blur_t)),
|
||||
.blur = half(unpack_mix_float(vertx.blur, drawable.blur_t)),
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_opacity)
|
||||
.opacity = half(unpack_mix_float(vertx.opacity, interp.opacity_t)),
|
||||
.opacity = half(unpack_mix_float(vertx.opacity, drawable.opacity_t)),
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_pattern_from)
|
||||
.pattern_from = half4(vertx.pattern_from),
|
||||
@@ -557,26 +667,29 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
|
||||
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
|
||||
device const GlobalPaintParamsUBO& paintParams [[buffer(idGlobalPaintParamsUBO)]],
|
||||
device const LinePatternDrawableUBO& drawable [[buffer(idLineDrawableUBO)]],
|
||||
device const LinePatternTilePropertiesUBO& tileProps [[buffer(idLineTilePropertiesUBO)]],
|
||||
device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]],
|
||||
device const LineTilePropsUnionUBO* tilePropsVector [[buffer(idLineTilePropsUBO)]],
|
||||
device const LineEvaluatedPropsUBO& props [[buffer(idLineEvaluatedPropsUBO)]],
|
||||
device const LineExpressionUBO& expr [[buffer(idLineExpressionUBO)]],
|
||||
texture2d<float, access::sample> image0 [[texture(0)]],
|
||||
sampler image0_sampler [[sampler(0)]]) {
|
||||
|
||||
#if defined(OVERDRAW_INSPECTOR)
|
||||
return half4(1.0);
|
||||
#endif
|
||||
|
||||
device const LinePatternTilePropsUBO& tileProps = tilePropsVector[uboIndex].linePatternTilePropsUBO;
|
||||
|
||||
#if defined(HAS_UNIFORM_u_blur)
|
||||
const auto exprBlur = (props.expressionMask & LineExpressionMask::Blur);
|
||||
const float blur = exprBlur ? expr.blur.eval(paintParams.zoom) : props.blur;
|
||||
const float blur = exprBlur ? expr.blur.eval(paintParams.map_zoom) : props.blur;
|
||||
#else
|
||||
const float blur = in.blur;
|
||||
#endif
|
||||
|
||||
#if defined(HAS_UNIFORM_u_opacity)
|
||||
const auto exprOpacity = (props.expressionMask & LineExpressionMask::Opacity);
|
||||
const float opacity = exprOpacity ? expr.opacity.eval(paintParams.zoom) : props.opacity;
|
||||
const float opacity = exprOpacity ? expr.opacity.eval(paintParams.map_zoom) : props.opacity;
|
||||
#else
|
||||
const float opacity = in.opacity;
|
||||
#endif
|
||||
@@ -598,10 +711,10 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]],
|
||||
const float2 pattern_tl_b = pattern_to.xy;
|
||||
const float2 pattern_br_b = pattern_to.zw;
|
||||
|
||||
const float pixelRatio = drawable.scale.x;
|
||||
const float tileZoomRatio = drawable.scale.y;
|
||||
const float fromScale = drawable.scale.z;
|
||||
const float toScale = drawable.scale.w;
|
||||
const float pixelRatio = tileProps.scale.x;
|
||||
const float tileZoomRatio = tileProps.scale.y;
|
||||
const float fromScale = tileProps.scale.z;
|
||||
const float toScale = tileProps.scale.w;
|
||||
|
||||
const float2 display_size_a = float2((pattern_br_a.x - pattern_tl_a.x) / pixelRatio, (pattern_br_a.y - pattern_tl_a.y) / pixelRatio);
|
||||
const float2 display_size_b = float2((pattern_br_b.x - pattern_tl_b.x) / pixelRatio, (pattern_br_b.y - pattern_tl_b.y) / pixelRatio);
|
||||
@@ -628,10 +741,10 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]],
|
||||
// the texture coordinate
|
||||
const float y_a = 0.5 + (in.normal.y * clamp(in.width2.x, 0.0, (pattern_size_a.y + 2.0) / 2.0) / pattern_size_a.y);
|
||||
const float y_b = 0.5 + (in.normal.y * clamp(in.width2.x, 0.0, (pattern_size_b.y + 2.0) / 2.0) / pattern_size_b.y);
|
||||
const float2 pos_a = mix(pattern_tl_a / drawable.texsize, pattern_br_a / drawable.texsize, float2(x_a, y_a));
|
||||
const float2 pos_b = mix(pattern_tl_b / drawable.texsize, pattern_br_b / drawable.texsize, float2(x_b, y_b));
|
||||
const float2 pos_a = mix(pattern_tl_a / tileProps.texsize, pattern_br_a / tileProps.texsize, float2(x_a, y_a));
|
||||
const float2 pos_b = mix(pattern_tl_b / tileProps.texsize, pattern_br_b / tileProps.texsize, float2(x_b, y_b));
|
||||
|
||||
const float4 color = mix(image0.sample(image0_sampler, pos_a), image0.sample(image0_sampler, pos_b), drawable.fade);
|
||||
const float4 color = mix(image0.sample(image0_sampler, pos_a), image0.sample(image0_sampler, pos_b), tileProps.fade);
|
||||
|
||||
return half4(color * alpha * opacity);
|
||||
}
|
||||
@@ -644,12 +757,11 @@ struct ShaderSource<BuiltIn::LineSDFShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static const std::array<UniformBlockInfo, 5> uniforms;
|
||||
static const std::array<AttributeInfo, 9> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static const std::array<TextureInfo, 1> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
static constexpr auto source = LINE_SHADER_COMMON R"(
|
||||
struct VertexStage {
|
||||
short2 pos_normal [[attribute(lineUBOCount + 0)]];
|
||||
uchar4 data [[attribute(lineUBOCount + 1)]];
|
||||
@@ -699,62 +811,41 @@ struct FragmentStage {
|
||||
#endif
|
||||
};
|
||||
|
||||
struct alignas(16) LineSDFDrawableUBO {
|
||||
float4x4 matrix;
|
||||
float2 patternscale_a;
|
||||
float2 patternscale_b;
|
||||
float ratio;
|
||||
float tex_y_a;
|
||||
float tex_y_b;
|
||||
float sdfgamma;
|
||||
float mix;
|
||||
float pad1, pad2, pad3;
|
||||
};
|
||||
|
||||
struct alignas(16) LineSDFInterpolationUBO {
|
||||
float color_t;
|
||||
float blur_t;
|
||||
float opacity_t;
|
||||
float gapwidth_t;
|
||||
float offset_t;
|
||||
float width_t;
|
||||
float floorwidth_t;
|
||||
float pad1;
|
||||
};
|
||||
|
||||
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
device const GlobalPaintParamsUBO& paintParams [[buffer(idGlobalPaintParamsUBO)]],
|
||||
device const LineSDFDrawableUBO& drawable [[buffer(idLineDrawableUBO)]],
|
||||
device const LineSDFInterpolationUBO& interp [[buffer(idLineInterpolationUBO)]],
|
||||
device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]],
|
||||
device const LineDrawableUnionUBO* drawableVector [[buffer(idLineDrawableUBO)]],
|
||||
device const LineEvaluatedPropsUBO& props [[buffer(idLineEvaluatedPropsUBO)]],
|
||||
device const LineExpressionUBO& expr [[buffer(idLineExpressionUBO)]]) {
|
||||
|
||||
device const LineSDFDrawableUBO& drawable = drawableVector[uboIndex].lineSDFDrawableUBO;
|
||||
|
||||
#if defined(HAS_UNIFORM_u_gapwidth)
|
||||
const auto exprGapWidth = (props.expressionMask & LineExpressionMask::GapWidth);
|
||||
const auto gapwidth = (exprGapWidth ? expr.gapwidth.eval(paintParams.zoom) : props.gapwidth) / 2.0;
|
||||
const auto gapwidth = (exprGapWidth ? expr.gapwidth.eval(paintParams.map_zoom) : props.gapwidth) / 2.0;
|
||||
#else
|
||||
const auto gapwidth = unpack_mix_float(vertx.gapwidth, interp.gapwidth_t) / 2.0;
|
||||
const auto gapwidth = unpack_mix_float(vertx.gapwidth, drawable.gapwidth_t) / 2.0;
|
||||
#endif
|
||||
|
||||
#if defined(HAS_UNIFORM_u_offset)
|
||||
const auto exprOffset = (props.expressionMask & LineExpressionMask::Offset);
|
||||
const auto offset = (exprOffset ? expr.offset.eval(paintParams.zoom) : props.offset) * -1.0;
|
||||
const auto offset = (exprOffset ? expr.offset.eval(paintParams.map_zoom) : props.offset) * -1.0;
|
||||
#else
|
||||
const auto offset = unpack_mix_float(vertx.offset, interp.offset_t) * -1.0;
|
||||
const auto offset = unpack_mix_float(vertx.offset, drawable.offset_t) * -1.0;
|
||||
#endif
|
||||
|
||||
#if defined(HAS_UNIFORM_u_width)
|
||||
const auto exprWidth = (props.expressionMask & LineExpressionMask::Width);
|
||||
const auto width = exprWidth ? expr.width.eval(paintParams.zoom) : props.width;
|
||||
const auto width = exprWidth ? expr.width.eval(paintParams.map_zoom) : props.width;
|
||||
#else
|
||||
const auto width = unpack_mix_float(vertx.width, interp.width_t);
|
||||
const auto width = unpack_mix_float(vertx.width, drawable.width_t);
|
||||
#endif
|
||||
|
||||
#if defined(HAS_UNIFORM_u_floorwidth)
|
||||
const auto exprFloorWidth = (props.expressionMask & LineExpressionMask::FloorWidth);
|
||||
const auto floorwidth = exprFloorWidth ? expr.floorwidth.eval(paintParams.zoom) : props.floorwidth;
|
||||
const auto floorwidth = exprFloorWidth ? expr.floorwidth.eval(paintParams.map_zoom) : props.floorwidth;
|
||||
#else
|
||||
const auto floorwidth = unpack_mix_float(vertx.floorwidth, interp.floorwidth_t);
|
||||
const auto floorwidth = unpack_mix_float(vertx.floorwidth, drawable.floorwidth_t);
|
||||
#endif
|
||||
|
||||
// the distance over which the line edge fades out.
|
||||
@@ -804,13 +895,13 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
.tex_b = float2(linesofar * drawable.patternscale_b.x / floorwidth, v_normal.y * drawable.patternscale_b.y + drawable.tex_y_b),
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_color)
|
||||
.color = unpack_mix_color(vertx.color, interp.color_t),
|
||||
.color = unpack_mix_color(vertx.color, drawable.color_t),
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_blur)
|
||||
.blur = unpack_mix_float(vertx.blur, interp.blur_t),
|
||||
.blur = unpack_mix_float(vertx.blur, drawable.blur_t),
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_opacity)
|
||||
.opacity = unpack_mix_float(vertx.opacity, interp.opacity_t),
|
||||
.opacity = unpack_mix_float(vertx.opacity, drawable.opacity_t),
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_floorwidth)
|
||||
.floorwidth = floorwidth,
|
||||
@@ -820,39 +911,43 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
|
||||
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
|
||||
device const GlobalPaintParamsUBO& paintParams [[buffer(idGlobalPaintParamsUBO)]],
|
||||
device const LineSDFDrawableUBO& drawable [[buffer(idLineDrawableUBO)]],
|
||||
device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]],
|
||||
device const LineTilePropsUnionUBO* tilePropsVector [[buffer(idLineTilePropsUBO)]],
|
||||
device const LineEvaluatedPropsUBO& props [[buffer(idLineEvaluatedPropsUBO)]],
|
||||
device const LineExpressionUBO& expr [[buffer(idLineExpressionUBO)]],
|
||||
texture2d<float, access::sample> image0 [[texture(0)]],
|
||||
sampler image0_sampler [[sampler(0)]]) {
|
||||
|
||||
#if defined(OVERDRAW_INSPECTOR)
|
||||
return half4(1.0);
|
||||
#endif
|
||||
|
||||
device const LineSDFTilePropsUBO& tileProps = tilePropsVector[uboIndex].lineSDFTilePropsUBO;
|
||||
|
||||
#if defined(HAS_UNIFORM_u_color)
|
||||
const auto exprColor = (props.expressionMask & LineExpressionMask::Color);
|
||||
const auto color = exprColor ? expr.color.evalColor(paintParams.zoom) : props.color;
|
||||
const auto color = exprColor ? expr.color.evalColor(paintParams.map_zoom) : props.color;
|
||||
#else
|
||||
const float4 color = in.color;
|
||||
#endif
|
||||
|
||||
#if defined(HAS_UNIFORM_u_blur)
|
||||
const auto exprBlur = (props.expressionMask & LineExpressionMask::Blur);
|
||||
const float blur = exprBlur ? expr.blur.eval(paintParams.zoom) : props.blur;
|
||||
const float blur = exprBlur ? expr.blur.eval(paintParams.map_zoom) : props.blur;
|
||||
#else
|
||||
const float blur = in.blur;
|
||||
#endif
|
||||
|
||||
#if defined(HAS_UNIFORM_u_opacity)
|
||||
const auto exprOpacity = (props.expressionMask & LineExpressionMask::Opacity);
|
||||
const float opacity = exprOpacity ? expr.opacity.eval(paintParams.zoom) : props.opacity;
|
||||
const float opacity = exprOpacity ? expr.opacity.eval(paintParams.map_zoom) : props.opacity;
|
||||
#else
|
||||
const float opacity = in.opacity;
|
||||
#endif
|
||||
|
||||
#if defined(HAS_UNIFORM_u_floorwidth)
|
||||
const auto exprFloorWidth = (props.expressionMask & LineExpressionMask::FloorWidth);
|
||||
const auto floorwidth = exprFloorWidth ? expr.floorwidth.eval(paintParams.zoom) : props.floorwidth;
|
||||
const auto floorwidth = exprFloorWidth ? expr.floorwidth.eval(paintParams.map_zoom) : props.floorwidth;
|
||||
#else
|
||||
const auto floorwidth = in.floorwidth;
|
||||
#endif
|
||||
@@ -866,9 +961,9 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]],
|
||||
|
||||
const float sdfdist_a = image0.sample(image0_sampler, in.tex_a).a;
|
||||
const float sdfdist_b = image0.sample(image0_sampler, in.tex_b).a;
|
||||
const float sdfdist = mix(sdfdist_a, sdfdist_b, drawable.mix);
|
||||
const float sdfdist = mix(sdfdist_a, sdfdist_b, tileProps.mix);
|
||||
const float alpha = clamp(min(dist - (in.width2.y - blur2), in.width2.x - dist) / blur2, 0.0, 1.0) *
|
||||
smoothstep(0.5 - drawable.sdfgamma / floorwidth, 0.5 + drawable.sdfgamma / floorwidth, sdfdist);
|
||||
smoothstep(0.5 - tileProps.sdfgamma / floorwidth, 0.5 + tileProps.sdfgamma / floorwidth, sdfdist);
|
||||
|
||||
return half4(color * (alpha * opacity));
|
||||
}
|
||||
|
||||
@@ -2,28 +2,61 @@
|
||||
|
||||
#include <mbgl/shaders/raster_layer_ubo.hpp>
|
||||
#include <mbgl/shaders/shader_source.hpp>
|
||||
#include <mbgl/shaders/mtl/common.hpp>
|
||||
#include <mbgl/shaders/mtl/shader_program.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
#define RASTER_SHADER_PRELUDE \
|
||||
R"(
|
||||
|
||||
enum {
|
||||
idRasterDrawableUBO = idDrawableReservedVertexOnlyUBO,
|
||||
idRasterEvaluatedPropsUBO = drawableReservedUBOCount,
|
||||
rasterUBOCount
|
||||
};
|
||||
|
||||
struct alignas(16) RasterDrawableUBO {
|
||||
/* 0 */ float4x4 matrix;
|
||||
/* 64 */
|
||||
};
|
||||
static_assert(sizeof(RasterDrawableUBO) == 4 * 16, "wrong size");
|
||||
|
||||
/// Evaluated properties that do not depend on the tile
|
||||
struct alignas(16) RasterEvaluatedPropsUBO {
|
||||
/* 0 */ float4 spin_weights;
|
||||
/* 16 */ float2 tl_parent;
|
||||
/* 24 */ float scale_parent;
|
||||
/* 28 */ float buffer_scale;
|
||||
/* 32 */ float fade_t;
|
||||
/* 36 */ float opacity;
|
||||
/* 40 */ float brightness_low;
|
||||
/* 44 */ float brightness_high;
|
||||
/* 48 */ float saturation_factor;
|
||||
/* 52 */ float contrast_factor;
|
||||
/* 56 */ float pad1;
|
||||
/* 60 */ float pad2;
|
||||
/* 64 */
|
||||
};
|
||||
static_assert(sizeof(RasterEvaluatedPropsUBO) == 4 * 16, "wrong size");
|
||||
|
||||
)"
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::RasterShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto name = "RasterShader";
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static const std::array<UniformBlockInfo, 2> uniforms;
|
||||
static const std::array<AttributeInfo, 2> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static const std::array<TextureInfo, 2> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
static constexpr auto source = RASTER_SHADER_PRELUDE R"(
|
||||
|
||||
struct VertexStage {
|
||||
short2 pos [[attribute(3)]];
|
||||
short2 texture_pos [[attribute(4)]];
|
||||
short2 pos [[attribute(rasterUBOCount + 0)]];
|
||||
short2 texture_pos [[attribute(rasterUBOCount + 1)]];
|
||||
};
|
||||
|
||||
struct FragmentStage {
|
||||
@@ -32,27 +65,12 @@ struct FragmentStage {
|
||||
float2 pos1;
|
||||
};
|
||||
|
||||
struct alignas(16) RasterDrawableUBO {
|
||||
float4x4 matrix;
|
||||
};
|
||||
|
||||
struct alignas(16) RasterEvaluatedPropsUBO {
|
||||
float4 spin_weights;
|
||||
float2 tl_parent;
|
||||
float scale_parent;
|
||||
float buffer_scale;
|
||||
float fade_t;
|
||||
float opacity;
|
||||
float brightness_low;
|
||||
float brightness_high;
|
||||
float saturation_factor;
|
||||
float contrast_factor;
|
||||
float pad1, pad2;
|
||||
};
|
||||
|
||||
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
device const RasterDrawableUBO& drawable [[buffer(1)]],
|
||||
device const RasterEvaluatedPropsUBO& props [[buffer(2)]]) {
|
||||
device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]],
|
||||
device const RasterDrawableUBO* drawableVector [[buffer(idRasterDrawableUBO)]],
|
||||
device const RasterEvaluatedPropsUBO& props [[buffer(idRasterEvaluatedPropsUBO)]]) {
|
||||
|
||||
device const RasterDrawableUBO& drawable = drawableVector[uboIndex];
|
||||
|
||||
const float4 position = drawable.matrix * float4(float2(vertx.pos), 0, 1);
|
||||
|
||||
@@ -72,7 +90,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
}
|
||||
|
||||
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
|
||||
device const RasterEvaluatedPropsUBO& props [[buffer(2)]],
|
||||
device const RasterEvaluatedPropsUBO& props [[buffer(idRasterEvaluatedPropsUBO)]],
|
||||
texture2d<float, access::sample> image0 [[texture(0)]],
|
||||
texture2d<float, access::sample> image1 [[texture(1)]],
|
||||
sampler image0_sampler [[sampler(0)]],
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <mbgl/gfx/shader_group.hpp>
|
||||
#include <mbgl/programs/program_parameters.hpp>
|
||||
#include <mbgl/shaders/mtl/background.hpp>
|
||||
#include <mbgl/shaders/mtl/common.hpp>
|
||||
#include <mbgl/shaders/mtl/shader_program.hpp>
|
||||
#include <mbgl/shaders/shader_source.hpp>
|
||||
#include <mbgl/util/hash.hpp>
|
||||
@@ -81,9 +81,6 @@ public:
|
||||
for (const auto& attrib : ShaderClass::instanceAttributes) {
|
||||
shader->initInstanceAttribute(attrib);
|
||||
}
|
||||
for (const auto& uniform : ShaderClass::uniforms) {
|
||||
shader->initUniformBlock(uniform);
|
||||
}
|
||||
for (const auto& texture : ShaderClass::textures) {
|
||||
shader->initTexture(texture);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
#include <mbgl/shaders/shader_program_base.hpp>
|
||||
#include <mbgl/mtl/mtl_fwd.hpp>
|
||||
#include <mbgl/mtl/uniform_block.hpp>
|
||||
#include <mbgl/mtl/vertex_attribute.hpp>
|
||||
|
||||
#include <Foundation/NSSharedPtr.hpp>
|
||||
@@ -71,12 +70,8 @@ public:
|
||||
|
||||
const gfx::VertexAttributeArray& getInstanceAttributes() const override { return instanceAttributes; }
|
||||
|
||||
const gfx::UniformBlockArray& getUniformBlocks() const override { return uniformBlocks; }
|
||||
gfx::UniformBlockArray& mutableUniformBlocks() override { return uniformBlocks; }
|
||||
|
||||
void initAttribute(const shaders::AttributeInfo&);
|
||||
void initInstanceAttribute(const shaders::AttributeInfo&);
|
||||
void initUniformBlock(const shaders::UniformBlockInfo&);
|
||||
void initTexture(const shaders::TextureInfo&);
|
||||
|
||||
protected:
|
||||
@@ -84,7 +79,6 @@ protected:
|
||||
RendererBackend& backend;
|
||||
MTLFunctionPtr vertexFunction;
|
||||
MTLFunctionPtr fragmentFunction;
|
||||
UniformBlockArray uniformBlocks;
|
||||
VertexAttributeArray vertexAttributes;
|
||||
VertexAttributeArray instanceAttributes;
|
||||
std::array<std::optional<size_t>, shaders::maxTextureCountPerShader> textureBindings;
|
||||
|
||||
644
include/mbgl/shaders/mtl/symbol.hpp
Normal file
644
include/mbgl/shaders/mtl/symbol.hpp
Normal file
@@ -0,0 +1,644 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/shaders/symbol_layer_ubo.hpp>
|
||||
#include <mbgl/shaders/shader_source.hpp>
|
||||
#include <mbgl/shaders/mtl/shader_program.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
#define SYMBOL_SHADER_COMMON \
|
||||
R"(
|
||||
|
||||
enum {
|
||||
idSymbolDrawableUBO = idDrawableReservedVertexOnlyUBO,
|
||||
idSymbolTilePropsUBO = idDrawableReservedFragmentOnlyUBO,
|
||||
idSymbolEvaluatedPropsUBO = drawableReservedUBOCount,
|
||||
symbolUBOCount
|
||||
};
|
||||
|
||||
struct alignas(16) SymbolDrawableUBO {
|
||||
/* 0 */ float4x4 matrix;
|
||||
/* 64 */ float4x4 label_plane_matrix;
|
||||
/* 128 */ float4x4 coord_matrix;
|
||||
|
||||
/* 192 */ float2 texsize;
|
||||
/* 200 */ float2 texsize_icon;
|
||||
|
||||
/* 208 */ /*bool*/ int is_text_prop;
|
||||
/* 212 */ /*bool*/ int rotate_symbol;
|
||||
/* 216 */ /*bool*/ int pitch_with_map;
|
||||
/* 220 */ /*bool*/ int is_size_zoom_constant;
|
||||
/* 224 */ /*bool*/ int is_size_feature_constant;
|
||||
|
||||
/* 228 */ float size_t;
|
||||
/* 232 */ float size;
|
||||
|
||||
// Interpolations
|
||||
/* 236 */ float fill_color_t;
|
||||
/* 240 */ float halo_color_t;
|
||||
/* 244 */ float opacity_t;
|
||||
/* 248 */ float halo_width_t;
|
||||
/* 252 */ float halo_blur_t;
|
||||
/* 256 */
|
||||
};
|
||||
static_assert(sizeof(SymbolDrawableUBO) == 16 * 16, "wrong size");
|
||||
|
||||
struct alignas(16) SymbolTilePropsUBO {
|
||||
/* 0 */ /*bool*/ int is_text;
|
||||
/* 4 */ /*bool*/ int is_halo;
|
||||
/* 8 */ float gamma_scale;
|
||||
/* 12 */ float pad1;
|
||||
/* 16 */
|
||||
};
|
||||
static_assert(sizeof(SymbolTilePropsUBO) == 16, "wrong size");
|
||||
|
||||
/// Evaluated properties that do not depend on the tile
|
||||
struct alignas(16) SymbolEvaluatedPropsUBO {
|
||||
/* 0 */ float4 text_fill_color;
|
||||
/* 16 */ float4 text_halo_color;
|
||||
/* 32 */ float text_opacity;
|
||||
/* 36 */ float text_halo_width;
|
||||
/* 40 */ float text_halo_blur;
|
||||
/* 44 */ float pad1;
|
||||
/* 48 */ float4 icon_fill_color;
|
||||
/* 64 */ float4 icon_halo_color;
|
||||
/* 80 */ float icon_opacity;
|
||||
/* 84 */ float icon_halo_width;
|
||||
/* 88 */ float icon_halo_blur;
|
||||
/* 92 */ float pad2;
|
||||
/* 96 */
|
||||
};
|
||||
static_assert(sizeof(SymbolEvaluatedPropsUBO) == 6 * 16, "wrong size");
|
||||
|
||||
)"
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::SymbolIconShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto name = "SymbolIconShader";
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static const std::array<AttributeInfo, 6> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static const std::array<TextureInfo, 1> textures;
|
||||
|
||||
static constexpr auto source = SYMBOL_SHADER_COMMON R"(
|
||||
struct VertexStage {
|
||||
float4 pos_offset [[attribute(symbolUBOCount + 0)]];
|
||||
float4 data [[attribute(symbolUBOCount + 1)]];
|
||||
float4 pixeloffset [[attribute(symbolUBOCount + 2)]];
|
||||
float3 projected_pos [[attribute(symbolUBOCount + 3)]];
|
||||
float fade_opacity [[attribute(symbolUBOCount + 4)]];
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_opacity)
|
||||
float opacity [[attribute(symbolUBOCount + 5)]];
|
||||
#endif
|
||||
};
|
||||
|
||||
struct FragmentStage {
|
||||
float4 position [[position, invariant]];
|
||||
half2 tex;
|
||||
|
||||
#if defined(HAS_UNIFORM_u_opacity)
|
||||
// We only need to pass `fade_opacity` separately if opacity is a
|
||||
// uniform, otherwise it's multiplied into fragment opacity, below.
|
||||
half fade_opacity;
|
||||
#else
|
||||
half opacity;
|
||||
#endif
|
||||
};
|
||||
|
||||
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
device const GlobalPaintParamsUBO& paintParams [[buffer(idGlobalPaintParamsUBO)]],
|
||||
device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]],
|
||||
device const SymbolDrawableUBO* drawableVector [[buffer(idSymbolDrawableUBO)]]) {
|
||||
|
||||
device const SymbolDrawableUBO& drawable = drawableVector[uboIndex];
|
||||
|
||||
const float2 a_pos = vertx.pos_offset.xy;
|
||||
const float2 a_offset = vertx.pos_offset.zw;
|
||||
|
||||
const float2 a_tex = vertx.data.xy;
|
||||
const float2 a_size = vertx.data.zw;
|
||||
|
||||
const float a_size_min = floor(a_size[0] * 0.5);
|
||||
const float2 a_pxoffset = vertx.pixeloffset.xy;
|
||||
const float2 a_minFontScale = vertx.pixeloffset.zw / 256.0;
|
||||
|
||||
const float segment_angle = -vertx.projected_pos[2];
|
||||
|
||||
float size;
|
||||
if (!drawable.is_size_zoom_constant && !drawable.is_size_feature_constant) {
|
||||
size = mix(a_size_min, a_size[1], drawable.size_t) / 128.0;
|
||||
} else if (drawable.is_size_zoom_constant && !drawable.is_size_feature_constant) {
|
||||
size = a_size_min / 128.0;
|
||||
} else {
|
||||
size = drawable.size;
|
||||
}
|
||||
|
||||
const float4 projectedPoint = drawable.matrix * float4(a_pos, 0, 1);
|
||||
const float camera_to_anchor_distance = projectedPoint.w;
|
||||
// See comments in symbol_sdf.vertex
|
||||
const float distance_ratio = drawable.pitch_with_map ?
|
||||
camera_to_anchor_distance / paintParams.camera_to_center_distance :
|
||||
paintParams.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
|
||||
4.0);
|
||||
|
||||
size *= perspective_ratio;
|
||||
|
||||
const float fontScale = drawable.is_text_prop ? size / 24.0 : size;
|
||||
|
||||
float symbol_rotation = 0.0;
|
||||
if (drawable.rotate_symbol) {
|
||||
// See comments in symbol_sdf.vertex
|
||||
const float4 offsetProjectedPoint = drawable.matrix * float4(a_pos + float2(1, 0), 0, 1);
|
||||
|
||||
const float2 a = projectedPoint.xy / projectedPoint.w;
|
||||
const float2 b = offsetProjectedPoint.xy / offsetProjectedPoint.w;
|
||||
symbol_rotation = atan2((b.y - a.y) / paintParams.aspect_ratio, b.x - a.x);
|
||||
}
|
||||
|
||||
const float angle_sin = sin(segment_angle + symbol_rotation);
|
||||
const float angle_cos = cos(segment_angle + symbol_rotation);
|
||||
const float2x2 rotation_matrix = float2x2(angle_cos, -1.0 * angle_sin, angle_sin, angle_cos);
|
||||
|
||||
const float4 projected_pos = drawable.label_plane_matrix * float4(vertx.projected_pos.xy, 0.0, 1.0);
|
||||
const float2 pos0 = projected_pos.xy / projected_pos.w;
|
||||
const float2 posOffset = a_offset * max(a_minFontScale, fontScale) / 32.0 + a_pxoffset / 16.0;
|
||||
const float4 position = drawable.coord_matrix * float4(pos0 + rotation_matrix * posOffset, 0.0, 1.0);
|
||||
|
||||
const float2 raw_fade_opacity = unpack_opacity(vertx.fade_opacity);
|
||||
const float fade_change = raw_fade_opacity[1] > 0.5 ? paintParams.symbol_fade_change : -paintParams.symbol_fade_change;
|
||||
const float fade_opacity = max(0.0, min(1.0, raw_fade_opacity[0] + fade_change));
|
||||
|
||||
return {
|
||||
.position = position,
|
||||
.tex = half2(a_tex / drawable.texsize),
|
||||
#if defined(HAS_UNIFORM_u_opacity)
|
||||
.fade_opacity = half(fade_opacity),
|
||||
#else
|
||||
.opacity = half(unpack_mix_float(vertx.opacity, drawable.opacity_t) * fade_opacity),
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
||||
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
|
||||
device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]],
|
||||
device const SymbolTilePropsUBO* tilePropsVector [[buffer(idSymbolTilePropsUBO)]],
|
||||
device const SymbolEvaluatedPropsUBO& props [[buffer(idSymbolEvaluatedPropsUBO)]],
|
||||
texture2d<float, access::sample> image [[texture(0)]],
|
||||
sampler image_sampler [[sampler(0)]]) {
|
||||
#if defined(OVERDRAW_INSPECTOR)
|
||||
return half4(1.0);
|
||||
#endif
|
||||
|
||||
device const SymbolTilePropsUBO& tileProps = tilePropsVector[uboIndex];
|
||||
|
||||
#if defined(HAS_UNIFORM_u_opacity)
|
||||
const float opacity = (tileProps.is_text ? props.text_opacity : props.icon_opacity) * in.fade_opacity;
|
||||
#else
|
||||
const float opacity = in.opacity; // fade_opacity is baked in for this case
|
||||
#endif
|
||||
|
||||
return half4(image.sample(image_sampler, float2(in.tex)) * opacity);
|
||||
}
|
||||
)";
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::SymbolSDFIconShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto name = "SymbolSDFIconShader";
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static const std::array<AttributeInfo, 10> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static const std::array<TextureInfo, 1> textures;
|
||||
|
||||
static constexpr auto source = SYMBOL_SHADER_COMMON R"(
|
||||
struct VertexStage {
|
||||
float4 pos_offset [[attribute(symbolUBOCount + 0)]];
|
||||
float4 data [[attribute(symbolUBOCount + 1)]];
|
||||
float4 pixeloffset [[attribute(symbolUBOCount + 2)]];
|
||||
float3 projected_pos [[attribute(symbolUBOCount + 3)]];
|
||||
float fade_opacity [[attribute(symbolUBOCount + 4)]];
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_fill_color)
|
||||
float4 fill_color [[attribute(symbolUBOCount + 5)]];
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_halo_color)
|
||||
float4 halo_color [[attribute(symbolUBOCount + 6)]];
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_opacity)
|
||||
float opacity [[attribute(symbolUBOCount + 7)]];
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_halo_width)
|
||||
float halo_width [[attribute(symbolUBOCount + 8)]];
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_halo_blur)
|
||||
float halo_blur [[attribute(symbolUBOCount + 9)]];
|
||||
#endif
|
||||
};
|
||||
|
||||
struct FragmentStage {
|
||||
float4 position [[position, invariant]];
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_fill_color)
|
||||
half4 fill_color;
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_halo_color)
|
||||
half4 halo_color;
|
||||
#endif
|
||||
|
||||
half2 tex;
|
||||
half gamma_scale;
|
||||
half fontScale;
|
||||
half fade_opacity;
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_opacity)
|
||||
half opacity;
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_halo_width)
|
||||
half halo_width;
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_halo_blur)
|
||||
half halo_blur;
|
||||
#endif
|
||||
};
|
||||
|
||||
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
device const GlobalPaintParamsUBO& paintParams [[buffer(idGlobalPaintParamsUBO)]],
|
||||
device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]],
|
||||
device const SymbolDrawableUBO* drawableVector [[buffer(idSymbolDrawableUBO)]]) {
|
||||
|
||||
device const SymbolDrawableUBO& drawable = drawableVector[uboIndex];
|
||||
|
||||
const float2 a_pos = vertx.pos_offset.xy;
|
||||
const float2 a_offset = vertx.pos_offset.zw;
|
||||
|
||||
const float2 a_tex = vertx.data.xy;
|
||||
const float2 a_size = vertx.data.zw;
|
||||
|
||||
const float a_size_min = floor(a_size[0] * 0.5);
|
||||
const float2 a_pxoffset = vertx.pixeloffset.xy;
|
||||
|
||||
const float segment_angle = -vertx.projected_pos[2];
|
||||
|
||||
float size;
|
||||
if (!drawable.is_size_zoom_constant && !drawable.is_size_feature_constant) {
|
||||
size = mix(a_size_min, a_size[1], drawable.size_t) / 128.0;
|
||||
} else if (drawable.is_size_zoom_constant && !drawable.is_size_feature_constant) {
|
||||
size = a_size_min / 128.0;
|
||||
} else {
|
||||
size = drawable.size;
|
||||
}
|
||||
|
||||
const float4 projectedPoint = drawable.matrix * float4(a_pos, 0, 1);
|
||||
const float camera_to_anchor_distance = projectedPoint.w;
|
||||
// If the label is pitched with the map, layout is done in pitched space,
|
||||
// which makes labels in the distance smaller relative to viewport space.
|
||||
// We counteract part of that effect by multiplying by the perspective ratio.
|
||||
// If the label isn't pitched with the map, we do layout in viewport space,
|
||||
// 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 = drawable.pitch_with_map ?
|
||||
camera_to_anchor_distance / paintParams.camera_to_center_distance :
|
||||
paintParams.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
|
||||
4.0);
|
||||
|
||||
size *= perspective_ratio;
|
||||
|
||||
const float fontScale = drawable.is_text_prop ? size / 24.0 : size;
|
||||
|
||||
float symbol_rotation = 0.0;
|
||||
if (drawable.rotate_symbol) {
|
||||
// Point labels with 'rotation-alignment: map' are horizontal with respect to tile units
|
||||
// To figure out that angle in projected space, we draw a short horizontal line in tile
|
||||
// space, project it, and measure its angle in projected space.
|
||||
const float4 offsetProjectedPoint = drawable.matrix * float4(a_pos + float2(1, 0), 0, 1);
|
||||
|
||||
const float2 a = projectedPoint.xy / projectedPoint.w;
|
||||
const float2 b = offsetProjectedPoint.xy / offsetProjectedPoint.w;
|
||||
|
||||
symbol_rotation = atan2((b.y - a.y) / paintParams.aspect_ratio, b.x - a.x);
|
||||
}
|
||||
|
||||
const float angle_sin = sin(segment_angle + symbol_rotation);
|
||||
const float angle_cos = cos(segment_angle + symbol_rotation);
|
||||
const auto rotation_matrix = float2x2(angle_cos, -1.0 * angle_sin, angle_sin, angle_cos);
|
||||
const float4 projected_pos = drawable.label_plane_matrix * float4(vertx.projected_pos.xy, 0.0, 1.0);
|
||||
const float2 pos_rot = a_offset / 32.0 * fontScale + a_pxoffset;
|
||||
const float2 pos0 = projected_pos.xy / projected_pos.w + rotation_matrix * pos_rot;
|
||||
const float4 position = drawable.coord_matrix * float4(pos0, 0.0, 1.0);
|
||||
const float2 fade_opacity = unpack_opacity(vertx.fade_opacity);
|
||||
const float fade_change = (fade_opacity[1] > 0.5) ? paintParams.symbol_fade_change : -paintParams.symbol_fade_change;
|
||||
|
||||
return {
|
||||
.position = position,
|
||||
#if !defined(HAS_UNIFORM_u_fill_color)
|
||||
.fill_color = half4(unpack_mix_color(vertx.fill_color, drawable.fill_color_t)),
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_halo_color)
|
||||
.halo_color = half4(unpack_mix_color(vertx.halo_color, drawable.halo_color_t)),
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_halo_width)
|
||||
.halo_width = half(unpack_mix_float(vertx.halo_width, drawable.halo_width_t)),
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_halo_blur)
|
||||
.halo_blur = half(unpack_mix_float(vertx.halo_blur, drawable.halo_blur_t)),
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_opacity)
|
||||
.opacity = half(unpack_mix_float(vertx.opacity, drawable.opacity_t)),
|
||||
#endif
|
||||
.tex = half2(a_tex / drawable.texsize),
|
||||
.gamma_scale = half(position.w),
|
||||
.fontScale = half(fontScale),
|
||||
.fade_opacity = half(max(0.0, min(1.0, fade_opacity[0] + fade_change))),
|
||||
};
|
||||
}
|
||||
|
||||
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
|
||||
device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]],
|
||||
device const SymbolTilePropsUBO* tilePropsVector [[buffer(idSymbolTilePropsUBO)]],
|
||||
device const SymbolEvaluatedPropsUBO& props [[buffer(idSymbolEvaluatedPropsUBO)]],
|
||||
texture2d<float, access::sample> image [[texture(0)]],
|
||||
sampler image_sampler [[sampler(0)]]) {
|
||||
#if defined(OVERDRAW_INSPECTOR)
|
||||
return half4(1.0);
|
||||
#endif
|
||||
|
||||
device const SymbolTilePropsUBO& tileProps = tilePropsVector[uboIndex];
|
||||
|
||||
#if defined(HAS_UNIFORM_u_fill_color)
|
||||
const half4 fill_color = half4(tileProps.is_text ? props.text_fill_color : props.icon_fill_color);
|
||||
#else
|
||||
const half4 fill_color = in.fill_color;
|
||||
#endif
|
||||
#if defined(HAS_UNIFORM_u_halo_color)
|
||||
const half4 halo_color = half4(tileProps.is_text ? props.text_halo_color : props.icon_halo_color);
|
||||
#else
|
||||
const half4 halo_color = in.halo_color;
|
||||
#endif
|
||||
#if defined(HAS_UNIFORM_u_opacity)
|
||||
const float opacity = tileProps.is_text ? props.text_opacity : props.icon_opacity;
|
||||
#else
|
||||
const float opacity = in.opacity;
|
||||
#endif
|
||||
#if defined(HAS_UNIFORM_u_halo_width)
|
||||
const float halo_width = tileProps.is_text ? props.text_halo_width : props.icon_halo_width;
|
||||
#else
|
||||
const float halo_width = in.halo_width;
|
||||
#endif
|
||||
#if defined(HAS_UNIFORM_u_halo_blur)
|
||||
const float halo_blur = tileProps.is_text ? props.text_halo_blur : props.icon_halo_blur;
|
||||
#else
|
||||
const float halo_blur = in.halo_blur;
|
||||
#endif
|
||||
|
||||
const float EDGE_GAMMA = 0.105 / DEVICE_PIXEL_RATIO;
|
||||
const float fontGamma = in.fontScale * tileProps.gamma_scale;
|
||||
const half4 color = tileProps.is_halo ? halo_color : fill_color;
|
||||
const float gamma = ((tileProps.is_halo ? (halo_blur * 1.19 / SDF_PX) : 0) + EDGE_GAMMA) / fontGamma;
|
||||
const float buff = tileProps.is_halo ? (6.0 - halo_width / in.fontScale) / SDF_PX : (256.0 - 64.0) / 256.0;
|
||||
const float dist = image.sample(image_sampler, float2(in.tex)).a;
|
||||
const float gamma_scaled = gamma * in.gamma_scale;
|
||||
const float alpha = smoothstep(buff - gamma_scaled, buff + gamma_scaled, dist);
|
||||
|
||||
return half4(color * (alpha * opacity * in.fade_opacity));
|
||||
}
|
||||
)";
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::SymbolTextAndIconShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto name = "SymbolTextAndIconShader";
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static const std::array<AttributeInfo, 9> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static const std::array<TextureInfo, 2> textures;
|
||||
|
||||
static constexpr auto source = SYMBOL_SHADER_COMMON R"(
|
||||
#define SDF 1.0
|
||||
#define ICON 0.0
|
||||
|
||||
struct VertexStage {
|
||||
float4 pos_offset [[attribute(symbolUBOCount + 0)]];
|
||||
float4 data [[attribute(symbolUBOCount + 1)]];
|
||||
float3 projected_pos [[attribute(symbolUBOCount + 2)]];
|
||||
float fade_opacity [[attribute(symbolUBOCount + 3)]];
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_fill_color)
|
||||
float4 fill_color [[attribute(symbolUBOCount + 4)]];
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_halo_color)
|
||||
float4 halo_color [[attribute(symbolUBOCount + 5)]];
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_opacity)
|
||||
float opacity [[attribute(symbolUBOCount + 6)]];
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_halo_width)
|
||||
float halo_width [[attribute(symbolUBOCount + 7)]];
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_halo_blur)
|
||||
float halo_blur [[attribute(symbolUBOCount + 8)]];
|
||||
#endif
|
||||
};
|
||||
|
||||
struct FragmentStage {
|
||||
float4 position [[position, invariant]];
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_fill_color)
|
||||
half4 fill_color;
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_halo_color)
|
||||
half4 halo_color;
|
||||
#endif
|
||||
|
||||
half2 tex;
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_opacity)
|
||||
half opacity;
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_halo_width)
|
||||
half halo_width;
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_halo_blur)
|
||||
half halo_blur;
|
||||
#endif
|
||||
|
||||
half gamma_scale;
|
||||
half fontScale;
|
||||
half fade_opacity;
|
||||
bool is_icon;
|
||||
};
|
||||
|
||||
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
device const GlobalPaintParamsUBO& paintParams [[buffer(idGlobalPaintParamsUBO)]],
|
||||
device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]],
|
||||
device const SymbolDrawableUBO* drawableVector [[buffer(idSymbolDrawableUBO)]]) {
|
||||
|
||||
device const SymbolDrawableUBO& drawable = drawableVector[uboIndex];
|
||||
|
||||
const float2 a_pos = vertx.pos_offset.xy;
|
||||
const float2 a_offset = vertx.pos_offset.zw;
|
||||
|
||||
const float2 a_tex = vertx.data.xy;
|
||||
const float2 a_size = vertx.data.zw;
|
||||
|
||||
const float a_size_min = floor(a_size[0] * 0.5);
|
||||
const float is_sdf = a_size[0] - 2.0 * a_size_min;
|
||||
|
||||
const float segment_angle = -vertx.projected_pos[2];
|
||||
|
||||
float size;
|
||||
if (!drawable.is_size_zoom_constant && !drawable.is_size_feature_constant) {
|
||||
size = mix(a_size_min, a_size[1], drawable.size_t) / 128.0;
|
||||
} else if (drawable.is_size_zoom_constant && !drawable.is_size_feature_constant) {
|
||||
size = a_size_min / 128.0;
|
||||
} else {
|
||||
size = drawable.size;
|
||||
}
|
||||
|
||||
const float4 projectedPoint = drawable.matrix * float4(a_pos, 0, 1);
|
||||
const float camera_to_anchor_distance = projectedPoint.w;
|
||||
// If the label is pitched with the map, layout is done in pitched space,
|
||||
// which makes labels in the distance smaller relative to viewport space.
|
||||
// We counteract part of that effect by multiplying by the perspective ratio.
|
||||
// If the label isn't pitched with the map, we do layout in viewport space,
|
||||
// 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 = drawable.pitch_with_map ?
|
||||
camera_to_anchor_distance / paintParams.camera_to_center_distance :
|
||||
paintParams.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
|
||||
4.0);
|
||||
|
||||
size *= perspective_ratio;
|
||||
|
||||
const float fontScale = size / 24.0;
|
||||
|
||||
float symbol_rotation = 0.0;
|
||||
if (drawable.rotate_symbol) {
|
||||
// Point labels with 'rotation-alignment: map' are horizontal with respect to tile units
|
||||
// To figure out that angle in projected space, we draw a short horizontal line in tile
|
||||
// space, project it, and measure its angle in projected space.
|
||||
const float4 offsetProjectedPoint = drawable.matrix * float4(a_pos + float2(1, 0), 0, 1);
|
||||
|
||||
const float2 a = projectedPoint.xy / projectedPoint.w;
|
||||
const float2 b = offsetProjectedPoint.xy / offsetProjectedPoint.w;
|
||||
|
||||
symbol_rotation = atan2((b.y - a.y) / paintParams.aspect_ratio, b.x - a.x);
|
||||
}
|
||||
|
||||
const float angle_sin = sin(segment_angle + symbol_rotation);
|
||||
const float angle_cos = cos(segment_angle + symbol_rotation);
|
||||
const float2x2 rotation_matrix = float2x2(angle_cos, -1.0 * angle_sin, angle_sin, angle_cos);
|
||||
|
||||
const float4 projected_pos = drawable.label_plane_matrix * float4(vertx.projected_pos.xy, 0.0, 1.0);
|
||||
const float2 pos_rot = a_offset / 32.0 * fontScale;
|
||||
const float2 pos0 = projected_pos.xy / projected_pos.w + rotation_matrix * pos_rot;
|
||||
const float4 position = drawable.coord_matrix * float4(pos0, 0.0, 1.0);
|
||||
const float gamma_scale = position.w;
|
||||
|
||||
const float2 fade_opacity = unpack_opacity(vertx.fade_opacity);
|
||||
const float fade_change = (fade_opacity[1] > 0.5) ? paintParams.symbol_fade_change : -paintParams.symbol_fade_change;
|
||||
const bool is_icon = (is_sdf == ICON);
|
||||
|
||||
return {
|
||||
.position = position,
|
||||
.tex = half2(a_tex / (is_icon ? drawable.texsize_icon : drawable.texsize)),
|
||||
.gamma_scale = half(gamma_scale),
|
||||
.fontScale = half(fontScale),
|
||||
.fade_opacity = half(max(0.0, min(1.0, fade_opacity[0] + fade_change))),
|
||||
.is_icon = is_icon,
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_fill_color)
|
||||
.fill_color = half(unpack_mix_color(vertx.fill_color, drawable.fill_color_t));
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_halo_color)
|
||||
.halo_color = half(unpack_mix_color(vertx.halo_color, drawable.halo_color_t));
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_opacity)
|
||||
.opacity = half(unpack_mix_float(vertx.opacity, drawable.opacity_t));
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_halo_width)
|
||||
.halo_width = half(unpack_mix_float(vertx.halo_width, drawable.halo_width_t));
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_halo_blur)
|
||||
.halo_blur = half(unpack_mix_float(vertx.halo_blur, drawable.halo_blur_t));
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
||||
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
|
||||
device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]],
|
||||
device const SymbolTilePropsUBO* tilePropsVector [[buffer(idSymbolTilePropsUBO)]],
|
||||
device const SymbolEvaluatedPropsUBO& props [[buffer(idSymbolEvaluatedPropsUBO)]],
|
||||
texture2d<float, access::sample> glyph_image [[texture(0)]],
|
||||
texture2d<float, access::sample> icon_image [[texture(1)]],
|
||||
sampler glyph_sampler [[sampler(0)]],
|
||||
sampler icon_sampler [[sampler(1)]]) {
|
||||
#if defined(OVERDRAW_INSPECTOR)
|
||||
return half4(1.0);
|
||||
#endif
|
||||
|
||||
device const SymbolTilePropsUBO& tileProps = tilePropsVector[uboIndex];
|
||||
|
||||
#if defined(HAS_UNIFORM_u_fill_color)
|
||||
const half4 fill_color = half4(tileProps.is_text ? props.text_fill_color : props.icon_fill_color);
|
||||
#else
|
||||
const half4 fill_color = in.fill_color;
|
||||
#endif
|
||||
#if defined(HAS_UNIFORM_u_halo_color)
|
||||
const half4 halo_color = half4(tileProps.is_text ? props.text_halo_color : props.icon_halo_color);
|
||||
#else
|
||||
const half4 halo_color = in.halo_color;
|
||||
#endif
|
||||
#if defined(HAS_UNIFORM_u_opacity)
|
||||
const half opacity = half(tileProps.is_text ? props.text_opacity : props.icon_opacity);
|
||||
#else
|
||||
const half opacity = in.opacity;
|
||||
#endif
|
||||
#if defined(HAS_UNIFORM_u_halo_width)
|
||||
const half halo_width = half(tileProps.is_text ? props.text_halo_width : props.icon_halo_width);
|
||||
#else
|
||||
const half halo_width = in.halo_width;
|
||||
#endif
|
||||
#if defined(HAS_UNIFORM_u_halo_blur)
|
||||
const half halo_blur = half(tileProps.is_text ? props.text_halo_blur : props.icon_halo_blur);
|
||||
#else
|
||||
const half halo_blur = in.halo_blur;
|
||||
#endif
|
||||
|
||||
if (in.is_icon) {
|
||||
const float alpha = opacity * in.fade_opacity;
|
||||
return half4(icon_image.sample(icon_sampler, float2(in.tex)) * alpha);
|
||||
}
|
||||
|
||||
const float EDGE_GAMMA = 0.105 / DEVICE_PIXEL_RATIO;
|
||||
const half4 color = tileProps.is_halo ? halo_color : fill_color;
|
||||
const float fontGamma = in.fontScale * tileProps.gamma_scale;
|
||||
const float gamma = ((tileProps.is_halo ? (halo_blur * 1.19 / SDF_PX) : 0) + EDGE_GAMMA) / fontGamma;
|
||||
const float buff = tileProps.is_halo ? (6.0 - halo_width / in.fontScale) / SDF_PX : (256.0 - 64.0) / 256.0;
|
||||
const float dist = glyph_image.sample(glyph_sampler, float2(in.tex)).a;
|
||||
const float gamma_scaled = gamma * in.gamma_scale;
|
||||
const float alpha = smoothstep(buff - gamma_scaled, buff + gamma_scaled, dist);
|
||||
|
||||
return half4(color * (alpha * opacity * in.fade_opacity));
|
||||
}
|
||||
)";
|
||||
};
|
||||
|
||||
} // namespace shaders
|
||||
} // namespace mbgl
|
||||
@@ -1,145 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/shaders/mtl/common.hpp>
|
||||
#include <mbgl/shaders/mtl/shader_program.hpp>
|
||||
#include <mbgl/shaders/shader_source.hpp>
|
||||
#include <mbgl/shaders/symbol_layer_ubo.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::SymbolIconShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto name = "SymbolIconShader";
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static const std::array<UniformBlockInfo, 5> uniforms;
|
||||
static const std::array<AttributeInfo, 6> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static const std::array<TextureInfo, 1> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
struct VertexStage {
|
||||
float4 pos_offset [[attribute(5)]];
|
||||
float4 data [[attribute(6)]];
|
||||
float4 pixeloffset [[attribute(7)]];
|
||||
float3 projected_pos [[attribute(8)]];
|
||||
float fade_opacity [[attribute(9)]];
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_opacity)
|
||||
float opacity [[attribute(10)]];
|
||||
#endif
|
||||
};
|
||||
|
||||
struct FragmentStage {
|
||||
float4 position [[position, invariant]];
|
||||
half2 tex;
|
||||
|
||||
#if defined(HAS_UNIFORM_u_opacity)
|
||||
// We only need to pass `fade_opacity` separately if opacity is a
|
||||
// uniform, otherwise it's multiplied into fragment opacity, below.
|
||||
half fade_opacity;
|
||||
#else
|
||||
half opacity;
|
||||
#endif
|
||||
};
|
||||
|
||||
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
device const GlobalPaintParamsUBO& paintParams [[buffer(0)]],
|
||||
device const SymbolDrawableUBO& drawable [[buffer(1)]],
|
||||
device const SymbolTilePropsUBO& tileprops [[buffer(2)]],
|
||||
device const SymbolInterpolateUBO& interp [[buffer(3)]]) {
|
||||
|
||||
const float2 a_pos = vertx.pos_offset.xy;
|
||||
const float2 a_offset = vertx.pos_offset.zw;
|
||||
|
||||
const float2 a_tex = vertx.data.xy;
|
||||
const float2 a_size = vertx.data.zw;
|
||||
|
||||
const float a_size_min = floor(a_size[0] * 0.5);
|
||||
const float2 a_pxoffset = vertx.pixeloffset.xy;
|
||||
const float2 a_minFontScale = vertx.pixeloffset.zw / 256.0;
|
||||
|
||||
const float segment_angle = -vertx.projected_pos[2];
|
||||
|
||||
float size;
|
||||
if (!tileprops.is_size_zoom_constant && !tileprops.is_size_feature_constant) {
|
||||
size = mix(a_size_min, a_size[1], tileprops.size_t) / 128.0;
|
||||
} else if (tileprops.is_size_zoom_constant && !tileprops.is_size_feature_constant) {
|
||||
size = a_size_min / 128.0;
|
||||
} else {
|
||||
size = tileprops.size;
|
||||
}
|
||||
|
||||
const float4 projectedPoint = drawable.matrix * float4(a_pos, 0, 1);
|
||||
const float camera_to_anchor_distance = projectedPoint.w;
|
||||
// See comments in symbol_sdf.vertex
|
||||
const float distance_ratio = tileprops.pitch_with_map ?
|
||||
camera_to_anchor_distance / paintParams.camera_to_center_distance :
|
||||
paintParams.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
|
||||
4.0);
|
||||
|
||||
size *= perspective_ratio;
|
||||
|
||||
const float fontScale = tileprops.is_text ? size / 24.0 : size;
|
||||
|
||||
float symbol_rotation = 0.0;
|
||||
if (drawable.rotate_symbol) {
|
||||
// See comments in symbol_sdf.vertex
|
||||
const float4 offsetProjectedPoint = drawable.matrix * float4(a_pos + float2(1, 0), 0, 1);
|
||||
|
||||
const float2 a = projectedPoint.xy / projectedPoint.w;
|
||||
const float2 b = offsetProjectedPoint.xy / offsetProjectedPoint.w;
|
||||
symbol_rotation = atan2((b.y - a.y) / paintParams.aspect_ratio, b.x - a.x);
|
||||
}
|
||||
|
||||
const float angle_sin = sin(segment_angle + symbol_rotation);
|
||||
const float angle_cos = cos(segment_angle + symbol_rotation);
|
||||
const float2x2 rotation_matrix = float2x2(angle_cos, -1.0 * angle_sin, angle_sin, angle_cos);
|
||||
|
||||
const float4 projected_pos = drawable.label_plane_matrix * float4(vertx.projected_pos.xy, 0.0, 1.0);
|
||||
const float2 pos0 = projected_pos.xy / projected_pos.w;
|
||||
const float2 posOffset = a_offset * max(a_minFontScale, fontScale) / 32.0 + a_pxoffset / 16.0;
|
||||
const float4 position = drawable.coord_matrix * float4(pos0 + rotation_matrix * posOffset, 0.0, 1.0);
|
||||
|
||||
const float2 raw_fade_opacity = unpack_opacity(vertx.fade_opacity);
|
||||
const float fade_change = raw_fade_opacity[1] > 0.5 ? paintParams.symbol_fade_change : -paintParams.symbol_fade_change;
|
||||
const float fade_opacity = max(0.0, min(1.0, raw_fade_opacity[0] + fade_change));
|
||||
|
||||
return {
|
||||
.position = position,
|
||||
.tex = half2(a_tex / drawable.texsize),
|
||||
#if defined(HAS_UNIFORM_u_opacity)
|
||||
.fade_opacity = half(fade_opacity),
|
||||
#else
|
||||
.opacity = half(unpack_mix_float(vertx.opacity, interp.opacity_t) * fade_opacity),
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
||||
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
|
||||
device const SymbolTilePropsUBO& tileprops [[buffer(2)]],
|
||||
device const SymbolEvaluatedPropsUBO& props [[buffer(4)]],
|
||||
texture2d<float, access::sample> image [[texture(0)]],
|
||||
sampler image_sampler [[sampler(0)]]) {
|
||||
#if defined(OVERDRAW_INSPECTOR)
|
||||
return half4(1.0);
|
||||
#endif
|
||||
|
||||
#if defined(HAS_UNIFORM_u_opacity)
|
||||
const float opacity = (tileprops.is_text ? props.text_opacity : props.icon_opacity) * in.fade_opacity;
|
||||
#else
|
||||
const float opacity = in.opacity; // fade_opacity is baked in for this case
|
||||
#endif
|
||||
|
||||
return half4(image.sample(image_sampler, float2(in.tex)) * opacity);
|
||||
}
|
||||
)";
|
||||
};
|
||||
|
||||
} // namespace shaders
|
||||
} // namespace mbgl
|
||||
@@ -1,217 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/shaders/mtl/common.hpp>
|
||||
#include <mbgl/shaders/mtl/shader_program.hpp>
|
||||
#include <mbgl/shaders/shader_source.hpp>
|
||||
#include <mbgl/shaders/symbol_layer_ubo.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::SymbolSDFIconShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto name = "SymbolSDFIconShader";
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static const std::array<UniformBlockInfo, 5> uniforms;
|
||||
static const std::array<AttributeInfo, 10> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static const std::array<TextureInfo, 1> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
struct VertexStage {
|
||||
float4 pos_offset [[attribute(5)]];
|
||||
float4 data [[attribute(6)]];
|
||||
float4 pixeloffset [[attribute(7)]];
|
||||
float3 projected_pos [[attribute(8)]];
|
||||
float fade_opacity [[attribute(9)]];
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_fill_color)
|
||||
float4 fill_color [[attribute(10)]];
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_halo_color)
|
||||
float4 halo_color [[attribute(11)]];
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_opacity)
|
||||
float opacity [[attribute(12)]];
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_halo_width)
|
||||
float halo_width [[attribute(13)]];
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_halo_blur)
|
||||
float halo_blur [[attribute(14)]];
|
||||
#endif
|
||||
};
|
||||
|
||||
struct FragmentStage {
|
||||
float4 position [[position, invariant]];
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_fill_color)
|
||||
half4 fill_color;
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_halo_color)
|
||||
half4 halo_color;
|
||||
#endif
|
||||
|
||||
half2 tex;
|
||||
half gamma_scale;
|
||||
half fontScale;
|
||||
half fade_opacity;
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_opacity)
|
||||
half opacity;
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_halo_width)
|
||||
half halo_width;
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_halo_blur)
|
||||
half halo_blur;
|
||||
#endif
|
||||
};
|
||||
|
||||
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
device const GlobalPaintParamsUBO& paintParams [[buffer(0)]],
|
||||
device const SymbolDrawableUBO& drawable [[buffer(1)]],
|
||||
device const SymbolTilePropsUBO& tileprops [[buffer(2)]],
|
||||
device const SymbolInterpolateUBO& interp [[buffer(3)]]) {
|
||||
|
||||
const float2 a_pos = vertx.pos_offset.xy;
|
||||
const float2 a_offset = vertx.pos_offset.zw;
|
||||
|
||||
const float2 a_tex = vertx.data.xy;
|
||||
const float2 a_size = vertx.data.zw;
|
||||
|
||||
const float a_size_min = floor(a_size[0] * 0.5);
|
||||
const float2 a_pxoffset = vertx.pixeloffset.xy;
|
||||
|
||||
const float segment_angle = -vertx.projected_pos[2];
|
||||
|
||||
float size;
|
||||
if (!tileprops.is_size_zoom_constant && !tileprops.is_size_feature_constant) {
|
||||
size = mix(a_size_min, a_size[1], tileprops.size_t) / 128.0;
|
||||
} else if (tileprops.is_size_zoom_constant && !tileprops.is_size_feature_constant) {
|
||||
size = a_size_min / 128.0;
|
||||
} else {
|
||||
size = tileprops.size;
|
||||
}
|
||||
|
||||
const float4 projectedPoint = drawable.matrix * float4(a_pos, 0, 1);
|
||||
const float camera_to_anchor_distance = projectedPoint.w;
|
||||
// If the label is pitched with the map, layout is done in pitched space,
|
||||
// which makes labels in the distance smaller relative to viewport space.
|
||||
// We counteract part of that effect by multiplying by the perspective ratio.
|
||||
// If the label isn't pitched with the map, we do layout in viewport space,
|
||||
// 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 = tileprops.pitch_with_map ?
|
||||
camera_to_anchor_distance / paintParams.camera_to_center_distance :
|
||||
paintParams.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
|
||||
4.0);
|
||||
|
||||
size *= perspective_ratio;
|
||||
|
||||
const float fontScale = tileprops.is_text ? size / 24.0 : size;
|
||||
|
||||
float symbol_rotation = 0.0;
|
||||
if (drawable.rotate_symbol) {
|
||||
// Point labels with 'rotation-alignment: map' are horizontal with respect to tile units
|
||||
// To figure out that angle in projected space, we draw a short horizontal line in tile
|
||||
// space, project it, and measure its angle in projected space.
|
||||
const float4 offsetProjectedPoint = drawable.matrix * float4(a_pos + float2(1, 0), 0, 1);
|
||||
|
||||
const float2 a = projectedPoint.xy / projectedPoint.w;
|
||||
const float2 b = offsetProjectedPoint.xy / offsetProjectedPoint.w;
|
||||
|
||||
symbol_rotation = atan2((b.y - a.y) / paintParams.aspect_ratio, b.x - a.x);
|
||||
}
|
||||
|
||||
const float angle_sin = sin(segment_angle + symbol_rotation);
|
||||
const float angle_cos = cos(segment_angle + symbol_rotation);
|
||||
const auto rotation_matrix = float2x2(angle_cos, -1.0 * angle_sin, angle_sin, angle_cos);
|
||||
const float4 projected_pos = drawable.label_plane_matrix * float4(vertx.projected_pos.xy, 0.0, 1.0);
|
||||
const float2 pos_rot = a_offset / 32.0 * fontScale + a_pxoffset;
|
||||
const float2 pos0 = projected_pos.xy / projected_pos.w + rotation_matrix * pos_rot;
|
||||
const float4 position = drawable.coord_matrix * float4(pos0, 0.0, 1.0);
|
||||
const float2 fade_opacity = unpack_opacity(vertx.fade_opacity);
|
||||
const float fade_change = (fade_opacity[1] > 0.5) ? paintParams.symbol_fade_change : -paintParams.symbol_fade_change;
|
||||
|
||||
return {
|
||||
.position = position,
|
||||
#if !defined(HAS_UNIFORM_u_fill_color)
|
||||
.fill_color = half4(unpack_mix_color(vertx.fill_color, interp.fill_color_t)),
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_halo_color)
|
||||
.halo_color = half4(unpack_mix_color(vertx.halo_color, interp.halo_color_t)),
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_halo_width)
|
||||
.halo_width = half(unpack_mix_float(vertx.halo_width, interp.halo_width_t)),
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_halo_blur)
|
||||
.halo_blur = half(unpack_mix_float(vertx.halo_blur, interp.halo_blur_t)),
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_opacity)
|
||||
.opacity = half(unpack_mix_float(vertx.opacity, interp.opacity_t)),
|
||||
#endif
|
||||
.tex = half2(a_tex / drawable.texsize),
|
||||
.gamma_scale = half(position.w),
|
||||
.fontScale = half(fontScale),
|
||||
.fade_opacity = half(max(0.0, min(1.0, fade_opacity[0] + fade_change))),
|
||||
};
|
||||
}
|
||||
|
||||
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
|
||||
device const SymbolDrawableUBO& drawable [[buffer(1)]],
|
||||
device const SymbolTilePropsUBO& tileprops [[buffer(2)]],
|
||||
device const SymbolEvaluatedPropsUBO& props [[buffer(4)]],
|
||||
texture2d<float, access::sample> image [[texture(0)]],
|
||||
sampler image_sampler [[sampler(0)]]) {
|
||||
#if defined(OVERDRAW_INSPECTOR)
|
||||
return half4(1.0);
|
||||
#endif
|
||||
|
||||
#if defined(HAS_UNIFORM_u_fill_color)
|
||||
const half4 fill_color = half4(tileprops.is_text ? props.text_fill_color : props.icon_fill_color);
|
||||
#else
|
||||
const half4 fill_color = in.fill_color;
|
||||
#endif
|
||||
#if defined(HAS_UNIFORM_u_halo_color)
|
||||
const half4 halo_color = half4(tileprops.is_text ? props.text_halo_color : props.icon_halo_color);
|
||||
#else
|
||||
const half4 halo_color = in.halo_color;
|
||||
#endif
|
||||
#if defined(HAS_UNIFORM_u_opacity)
|
||||
const float opacity = tileprops.is_text ? props.text_opacity : props.icon_opacity;
|
||||
#else
|
||||
const float opacity = in.opacity;
|
||||
#endif
|
||||
#if defined(HAS_UNIFORM_u_halo_width)
|
||||
const float halo_width = tileprops.is_text ? props.text_halo_width : props.icon_halo_width;
|
||||
#else
|
||||
const float halo_width = in.halo_width;
|
||||
#endif
|
||||
#if defined(HAS_UNIFORM_u_halo_blur)
|
||||
const float halo_blur = tileprops.is_text ? props.text_halo_blur : props.icon_halo_blur;
|
||||
#else
|
||||
const float halo_blur = in.halo_blur;
|
||||
#endif
|
||||
|
||||
const float EDGE_GAMMA = 0.105 / DEVICE_PIXEL_RATIO;
|
||||
const float fontGamma = in.fontScale * drawable.gamma_scale;
|
||||
const half4 color = tileprops.is_halo ? halo_color : fill_color;
|
||||
const float gamma = ((tileprops.is_halo ? (halo_blur * 1.19 / SDF_PX) : 0) + EDGE_GAMMA) / fontGamma;
|
||||
const float buff = tileprops.is_halo ? (6.0 - halo_width / in.fontScale) / SDF_PX : (256.0 - 64.0) / 256.0;
|
||||
const float dist = image.sample(image_sampler, float2(in.tex)).a;
|
||||
const float gamma_scaled = gamma * in.gamma_scale;
|
||||
const float alpha = smoothstep(buff - gamma_scaled, buff + gamma_scaled, dist);
|
||||
|
||||
return half4(color * (alpha * opacity * in.fade_opacity));
|
||||
}
|
||||
)";
|
||||
};
|
||||
|
||||
} // namespace shaders
|
||||
} // namespace mbgl
|
||||
@@ -1,234 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/shaders/mtl/common.hpp>
|
||||
#include <mbgl/shaders/mtl/shader_program.hpp>
|
||||
#include <mbgl/shaders/shader_source.hpp>
|
||||
#include <mbgl/shaders/symbol_layer_ubo.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::SymbolTextAndIconShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto name = "SymbolTextAndIconShader";
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static const std::array<UniformBlockInfo, 5> uniforms;
|
||||
static const std::array<AttributeInfo, 9> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static const std::array<TextureInfo, 2> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
#define SDF 1.0
|
||||
#define ICON 0.0
|
||||
|
||||
struct VertexStage {
|
||||
float4 pos_offset [[attribute(5)]];
|
||||
float4 data [[attribute(6)]];
|
||||
float3 projected_pos [[attribute(7)]];
|
||||
float fade_opacity [[attribute(8)]];
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_fill_color)
|
||||
float4 fill_color [[attribute(9)]];
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_halo_color)
|
||||
float4 halo_color [[attribute(10)]];
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_opacity)
|
||||
float opacity [[attribute(11)]];
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_halo_width)
|
||||
float halo_width [[attribute(12)]];
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_halo_blur)
|
||||
float halo_blur [[attribute(13)]];
|
||||
#endif
|
||||
};
|
||||
|
||||
struct FragmentStage {
|
||||
float4 position [[position, invariant]];
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_fill_color)
|
||||
half4 fill_color;
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_halo_color)
|
||||
half4 halo_color;
|
||||
#endif
|
||||
|
||||
half2 tex;
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_opacity)
|
||||
half opacity;
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_halo_width)
|
||||
half halo_width;
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_halo_blur)
|
||||
half halo_blur;
|
||||
#endif
|
||||
|
||||
half gamma_scale;
|
||||
half fontScale;
|
||||
half fade_opacity;
|
||||
bool is_icon;
|
||||
};
|
||||
|
||||
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
||||
device const GlobalPaintParamsUBO& paintParams [[buffer(0)]],
|
||||
device const SymbolDrawableUBO& drawable [[buffer(1)]],
|
||||
device const SymbolTilePropsUBO& tileprops [[buffer(2)]],
|
||||
device const SymbolInterpolateUBO& interp [[buffer(3)]]) {
|
||||
|
||||
const float2 a_pos = vertx.pos_offset.xy;
|
||||
const float2 a_offset = vertx.pos_offset.zw;
|
||||
|
||||
const float2 a_tex = vertx.data.xy;
|
||||
const float2 a_size = vertx.data.zw;
|
||||
|
||||
const float a_size_min = floor(a_size[0] * 0.5);
|
||||
const float is_sdf = a_size[0] - 2.0 * a_size_min;
|
||||
|
||||
const float segment_angle = -vertx.projected_pos[2];
|
||||
|
||||
float size;
|
||||
if (!tileprops.is_size_zoom_constant && !tileprops.is_size_feature_constant) {
|
||||
size = mix(a_size_min, a_size[1], tileprops.size_t) / 128.0;
|
||||
} else if (tileprops.is_size_zoom_constant && !tileprops.is_size_feature_constant) {
|
||||
size = a_size_min / 128.0;
|
||||
} else {
|
||||
size = tileprops.size;
|
||||
}
|
||||
|
||||
const float4 projectedPoint = drawable.matrix * float4(a_pos, 0, 1);
|
||||
const float camera_to_anchor_distance = projectedPoint.w;
|
||||
// If the label is pitched with the map, layout is done in pitched space,
|
||||
// which makes labels in the distance smaller relative to viewport space.
|
||||
// We counteract part of that effect by multiplying by the perspective ratio.
|
||||
// If the label isn't pitched with the map, we do layout in viewport space,
|
||||
// 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 = tileprops.pitch_with_map ?
|
||||
camera_to_anchor_distance / paintParams.camera_to_center_distance :
|
||||
paintParams.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
|
||||
4.0);
|
||||
|
||||
size *= perspective_ratio;
|
||||
|
||||
const float fontScale = size / 24.0;
|
||||
|
||||
float symbol_rotation = 0.0;
|
||||
if (drawable.rotate_symbol) {
|
||||
// Point labels with 'rotation-alignment: map' are horizontal with respect to tile units
|
||||
// To figure out that angle in projected space, we draw a short horizontal line in tile
|
||||
// space, project it, and measure its angle in projected space.
|
||||
const float4 offsetProjectedPoint = drawable.matrix * float4(a_pos + float2(1, 0), 0, 1);
|
||||
|
||||
const float2 a = projectedPoint.xy / projectedPoint.w;
|
||||
const float2 b = offsetProjectedPoint.xy / offsetProjectedPoint.w;
|
||||
|
||||
symbol_rotation = atan2((b.y - a.y) / paintParams.aspect_ratio, b.x - a.x);
|
||||
}
|
||||
|
||||
const float angle_sin = sin(segment_angle + symbol_rotation);
|
||||
const float angle_cos = cos(segment_angle + symbol_rotation);
|
||||
const float2x2 rotation_matrix = float2x2(angle_cos, -1.0 * angle_sin, angle_sin, angle_cos);
|
||||
|
||||
const float4 projected_pos = drawable.label_plane_matrix * float4(vertx.projected_pos.xy, 0.0, 1.0);
|
||||
const float2 pos_rot = a_offset / 32.0 * fontScale;
|
||||
const float2 pos0 = projected_pos.xy / projected_pos.w + rotation_matrix * pos_rot;
|
||||
const float4 position = drawable.coord_matrix * float4(pos0, 0.0, 1.0);
|
||||
const float gamma_scale = position.w;
|
||||
|
||||
const float2 fade_opacity = unpack_opacity(vertx.fade_opacity);
|
||||
const float fade_change = (fade_opacity[1] > 0.5) ? paintParams.symbol_fade_change : -paintParams.symbol_fade_change;
|
||||
const bool is_icon = (is_sdf == ICON);
|
||||
|
||||
return {
|
||||
.position = position,
|
||||
.tex = half2(a_tex / (is_icon ? drawable.texsize_icon : drawable.texsize)),
|
||||
.gamma_scale = half(gamma_scale),
|
||||
.fontScale = half(fontScale),
|
||||
.fade_opacity = half(max(0.0, min(1.0, fade_opacity[0] + fade_change))),
|
||||
.is_icon = is_icon,
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_fill_color)
|
||||
.fill_color = half(unpack_mix_color(vertx.fill_color, interp.fill_color_t));
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_halo_color)
|
||||
.halo_color = half(unpack_mix_color(vertx.halo_color, interp.halo_color_t));
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_opacity)
|
||||
.opacity = half(unpack_mix_float(vertx.opacity, interp.opacity_t));
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_halo_width)
|
||||
.halo_width = half(unpack_mix_float(vertx.halo_width, interp.halo_width_t));
|
||||
#endif
|
||||
#if !defined(HAS_UNIFORM_u_halo_blur)
|
||||
.halo_blur = half(unpack_mix_float(vertx.halo_blur, interp.halo_blur_t));
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
||||
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
|
||||
device const SymbolDrawableUBO& drawable [[buffer(1)]],
|
||||
device const SymbolTilePropsUBO& tileprops [[buffer(2)]],
|
||||
device const SymbolEvaluatedPropsUBO& props [[buffer(4)]],
|
||||
texture2d<float, access::sample> glyph_image [[texture(0)]],
|
||||
texture2d<float, access::sample> icon_image [[texture(1)]],
|
||||
sampler glyph_sampler [[sampler(0)]],
|
||||
sampler icon_sampler [[sampler(1)]]) {
|
||||
#if defined(OVERDRAW_INSPECTOR)
|
||||
return half4(1.0);
|
||||
#endif
|
||||
|
||||
#if defined(HAS_UNIFORM_u_fill_color)
|
||||
const half4 fill_color = half4(tileprops.is_text ? props.text_fill_color : props.icon_fill_color);
|
||||
#else
|
||||
const half4 fill_color = in.fill_color;
|
||||
#endif
|
||||
#if defined(HAS_UNIFORM_u_halo_color)
|
||||
const half4 halo_color = half4(tileprops.is_text ? props.text_halo_color : props.icon_halo_color);
|
||||
#else
|
||||
const half4 halo_color = in.halo_color;
|
||||
#endif
|
||||
#if defined(HAS_UNIFORM_u_opacity)
|
||||
const half opacity = half(tileprops.is_text ? props.text_opacity : props.icon_opacity);
|
||||
#else
|
||||
const half opacity = in.opacity;
|
||||
#endif
|
||||
#if defined(HAS_UNIFORM_u_halo_width)
|
||||
const half halo_width = half(tileprops.is_text ? props.text_halo_width : props.icon_halo_width);
|
||||
#else
|
||||
const half halo_width = in.halo_width;
|
||||
#endif
|
||||
#if defined(HAS_UNIFORM_u_halo_blur)
|
||||
const half halo_blur = half(tileprops.is_text ? props.text_halo_blur : props.icon_halo_blur);
|
||||
#else
|
||||
const half halo_blur = in.halo_blur;
|
||||
#endif
|
||||
|
||||
if (in.is_icon) {
|
||||
const float alpha = opacity * in.fade_opacity;
|
||||
return half4(icon_image.sample(icon_sampler, float2(in.tex)) * alpha);
|
||||
}
|
||||
|
||||
const float EDGE_GAMMA = 0.105 / DEVICE_PIXEL_RATIO;
|
||||
const half4 color = tileprops.is_halo ? halo_color : fill_color;
|
||||
const float fontGamma = in.fontScale * drawable.gamma_scale;
|
||||
const float gamma = ((tileprops.is_halo ? (halo_blur * 1.19 / SDF_PX) : 0) + EDGE_GAMMA) / fontGamma;
|
||||
const float buff = tileprops.is_halo ? (6.0 - halo_width / in.fontScale) / SDF_PX : (256.0 - 64.0) / 256.0;
|
||||
const float dist = glyph_image.sample(glyph_sampler, float2(in.tex)).a;
|
||||
const float gamma_scaled = gamma * in.gamma_scale;
|
||||
const float alpha = smoothstep(buff - gamma_scaled, buff + gamma_scaled, dist);
|
||||
|
||||
return half4(color * (alpha * opacity * in.fade_opacity));
|
||||
}
|
||||
)";
|
||||
};
|
||||
|
||||
} // namespace shaders
|
||||
} // namespace mbgl
|
||||
@@ -1,36 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/shaders/shader_source.hpp>
|
||||
#include <mbgl/shaders/mtl/common.hpp>
|
||||
#include <mbgl/shaders/mtl/shader_program.hpp>
|
||||
#include <mbgl/shaders/widevector_ubo.hpp>
|
||||
#include <mbgl/shaders/shader_defines.hpp>
|
||||
#include <mbgl/shaders/shader_source.hpp>
|
||||
#include <mbgl/shaders/mtl/shader_program.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
#define WIDEVECTOR_SHADER_PRELUDE \
|
||||
R"(
|
||||
|
||||
enum {
|
||||
idWideVectorUniformsUBO = idDrawableReservedVertexOnlyUBO,
|
||||
idWideVectorUniformWideVecUBO = drawableReservedUBOCount,
|
||||
wideVectorUBOCount
|
||||
};
|
||||
|
||||
)"
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::WideVectorShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto name = "WideVectorShader";
|
||||
static constexpr auto vertexMainFunction = "vertexTri_wideVecPerf";
|
||||
static constexpr auto fragmentMainFunction = "fragmentTri_wideVecPerf";
|
||||
|
||||
static constexpr std::array<UniformBlockInfo, 2> uniforms{
|
||||
UniformBlockInfo{true, false, sizeof(WideVectorUniformsUBO), idWideVectorUniformsUBO},
|
||||
UniformBlockInfo{true, false, sizeof(WideVectorUniformWideVecUBO), idWideVectorUniformWideVecUBO},
|
||||
};
|
||||
static constexpr std::array<AttributeInfo, 3> attributes{
|
||||
AttributeInfo{wideVectorDrawableUBOCount + 0, gfx::AttributeDataType::Float3, idWideVectorScreenPos},
|
||||
AttributeInfo{wideVectorDrawableUBOCount + 1, gfx::AttributeDataType::Float4, idWideVectorColor},
|
||||
AttributeInfo{wideVectorDrawableUBOCount + 2, gfx::AttributeDataType::Int, idWideVectorIndex}};
|
||||
static constexpr std::array<AttributeInfo, 4> instanceAttributes{
|
||||
AttributeInfo{wideVectorDrawableUBOCount + 3, gfx::AttributeDataType::Float3, idWideVectorInstanceCenter},
|
||||
AttributeInfo{wideVectorDrawableUBOCount + 3, gfx::AttributeDataType::Float4, idWideVectorInstanceColor},
|
||||
AttributeInfo{wideVectorDrawableUBOCount + 3, gfx::AttributeDataType::Int, idWideVectorInstancePrevious},
|
||||
AttributeInfo{wideVectorDrawableUBOCount + 3, gfx::AttributeDataType::Int, idWideVectorInstanceNext}};
|
||||
static constexpr std::array<TextureInfo, 0> textures{};
|
||||
static const std::array<AttributeInfo, 3> attributes;
|
||||
static const std::array<AttributeInfo, 4> instanceAttributes;
|
||||
static const std::array<TextureInfo, 0> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
static constexpr auto source = WIDEVECTOR_SHADER_PRELUDE R"(
|
||||
#include <metal_stdlib>
|
||||
|
||||
namespace WhirlyKitShader
|
||||
@@ -113,9 +111,9 @@ typedef struct
|
||||
struct VertexTriWideVecB
|
||||
{
|
||||
// x, y offset around the center
|
||||
float3 screenPos [[attribute(3)]];
|
||||
float4 color [[attribute(4)]];
|
||||
int index [[attribute(5)]];
|
||||
float3 screenPos [[attribute(wideVectorUBOCount + 0)]];
|
||||
float4 color [[attribute(wideVectorUBOCount + 1)]];
|
||||
int index [[attribute(wideVectorUBOCount + 2)]];
|
||||
};
|
||||
|
||||
// Wide vector vertex passed to fragment shader (new version)
|
||||
@@ -222,10 +220,10 @@ constant constexpr float4 discardPt(0,0,-1e6,NAN);
|
||||
// Performance version of wide vector shader
|
||||
vertex ProjVertexTriWideVecPerf vertexTri_wideVecPerf(
|
||||
thread const VertexTriWideVecB vert [[ stage_in ]],
|
||||
constant Uniforms &uniforms [[ buffer(1) ]],
|
||||
constant UniformWideVec &wideVec [[ buffer(2) ]],
|
||||
constant Uniforms &uniforms [[ buffer(idWideVectorUniformsUBO) ]],
|
||||
constant UniformWideVec &wideVec [[ buffer(idWideVectorUniformWideVecUBO) ]],
|
||||
uint instanceID [[ instance_id ]],
|
||||
constant VertexTriWideVecInstance *wideVecInsts [[ buffer(6) ]])
|
||||
constant VertexTriWideVecInstance *wideVecInsts [[ buffer(wideVectorUBOCount + 3) ]])
|
||||
{
|
||||
ProjVertexTriWideVecPerf outVert = {
|
||||
.position = discardPt,
|
||||
@@ -564,7 +562,7 @@ vertex ProjVertexTriWideVecPerf vertexTri_wideVecPerf(
|
||||
// Fragment shader that takes the back of the globe into account
|
||||
fragment float4 fragmentTri_wideVecPerf(
|
||||
ProjVertexTriWideVecPerf vert [[stage_in]],
|
||||
constant Uniforms &uniforms [[ buffer(1) ]])
|
||||
constant Uniforms &uniforms [[ buffer(idWideVectorUniformsUBO) ]])
|
||||
{
|
||||
float patternAlpha = 1.0;
|
||||
|
||||
|
||||
@@ -6,24 +6,28 @@ namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
struct alignas(16) RasterDrawableUBO {
|
||||
std::array<float, 4 * 4> matrix;
|
||||
/* 0 */ std::array<float, 4 * 4> matrix;
|
||||
/* 64 */
|
||||
};
|
||||
static_assert(sizeof(RasterDrawableUBO) == 64);
|
||||
static_assert(sizeof(RasterDrawableUBO) == 4 * 16);
|
||||
|
||||
/// Evaluated properties that do not depend on the tile
|
||||
struct alignas(16) RasterEvaluatedPropsUBO {
|
||||
std::array<float, 4> spin_weights;
|
||||
std::array<float, 2> tl_parent;
|
||||
float scale_parent;
|
||||
float buffer_scale;
|
||||
float fade_t;
|
||||
float opacity;
|
||||
float brightness_low;
|
||||
float brightness_high;
|
||||
float saturation_factor;
|
||||
float contrast_factor;
|
||||
float pad1, pad2;
|
||||
/* 0 */ std::array<float, 4> spin_weights;
|
||||
/* 16 */ std::array<float, 2> tl_parent;
|
||||
/* 24 */ float scale_parent;
|
||||
/* 28 */ float buffer_scale;
|
||||
/* 32 */ float fade_t;
|
||||
/* 36 */ float opacity;
|
||||
/* 40 */ float brightness_low;
|
||||
/* 44 */ float brightness_high;
|
||||
/* 48 */ float saturation_factor;
|
||||
/* 52 */ float contrast_factor;
|
||||
/* 56 */ float pad1;
|
||||
/* 60 */ float pad2;
|
||||
/* 64 */
|
||||
};
|
||||
static_assert(sizeof(RasterEvaluatedPropsUBO) == 64);
|
||||
static_assert(sizeof(RasterEvaluatedPropsUBO) == 4 * 16);
|
||||
|
||||
} // namespace shaders
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -10,109 +10,112 @@ namespace shaders {
|
||||
// drawable UBOs
|
||||
|
||||
enum {
|
||||
idClippingMaskUBO = globalUBOCount,
|
||||
clippingMaskUBOCount
|
||||
idBackgroundDrawableUBO = idDrawableReservedVertexOnlyUBO,
|
||||
backgroundDrawableUBOCount = drawableReservedUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idCommonUBO = globalUBOCount,
|
||||
commonDrawableUBOCount
|
||||
idCircleDrawableUBO = idDrawableReservedVertexOnlyUBO,
|
||||
circleDrawableUBOCount = drawableReservedUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idCircleDrawableUBO = globalUBOCount,
|
||||
idCircleInterpolateUBO,
|
||||
circleDrawableUBOCount
|
||||
idClippingMaskUBO = idDrawableReservedVertexOnlyUBO,
|
||||
clippingMaskDrawableUBOCount = drawableReservedUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idBackgroundDrawableUBO = globalUBOCount,
|
||||
backgroundDrawableUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idCustomSymbolDrawableUBO = globalUBOCount,
|
||||
idCustomSymbolParametersUBO,
|
||||
customSymbolDrawableUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idCollisionUBO = globalUBOCount,
|
||||
idCollisionDrawableUBO = idDrawableReservedVertexOnlyUBO,
|
||||
idCollisionTilePropsUBO = drawableReservedUBOCount,
|
||||
collisionDrawableUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idDebugUBO = globalUBOCount,
|
||||
idCustomSymbolDrawableUBO = idDrawableReservedVertexOnlyUBO,
|
||||
customSymbolDrawableUBOCount = drawableReservedUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idDebugUBO = drawableReservedUBOCount,
|
||||
debugDrawableUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idFillDrawableUBO = globalUBOCount,
|
||||
idFillTilePropsUBO,
|
||||
idFillInterpolateUBO,
|
||||
idFillDrawableUBO = idDrawableReservedVertexOnlyUBO,
|
||||
idFillTilePropsUBO = drawableReservedUBOCount,
|
||||
fillDrawableUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idFillExtrusionDrawableUBO = globalUBOCount,
|
||||
idFillExtrusionTilePropsUBO,
|
||||
idFillExtrusionInterpolateUBO,
|
||||
idFillExtrusionDrawableUBO = idDrawableReservedVertexOnlyUBO,
|
||||
idFillExtrusionTilePropsUBO = drawableReservedUBOCount,
|
||||
fillExtrusionDrawableUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idHeatmapDrawableUBO = globalUBOCount,
|
||||
idHeatmapInterpolateUBO,
|
||||
heatmapDrawableUBOCount
|
||||
idHeatmapDrawableUBO = idDrawableReservedVertexOnlyUBO,
|
||||
heatmapDrawableUBOCount = drawableReservedUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idHillshadeDrawableUBO = globalUBOCount,
|
||||
hillshadeDrawableUBOCount
|
||||
heatmapTextureDrawableUBOCount = drawableReservedUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idHillshadePrepareDrawableUBO = globalUBOCount,
|
||||
idHillshadeDrawableUBO = idDrawableReservedVertexOnlyUBO,
|
||||
idHillshadeTilePropsUBO = idDrawableReservedFragmentOnlyUBO,
|
||||
hillshadeDrawableUBOCount = drawableReservedUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idHillshadePrepareDrawableUBO = idDrawableReservedVertexOnlyUBO,
|
||||
idHillshadePrepareTilePropsUBO = drawableReservedUBOCount,
|
||||
hillshadePrepareDrawableUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idLineDrawableUBO = globalUBOCount,
|
||||
idLineInterpolationUBO,
|
||||
idLineTilePropertiesUBO,
|
||||
lineDrawableUBOCount
|
||||
idLineDrawableUBO = idDrawableReservedVertexOnlyUBO,
|
||||
idLineTilePropsUBO = idDrawableReservedFragmentOnlyUBO,
|
||||
lineDrawableUBOCount = drawableReservedUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idRasterDrawableUBO = globalUBOCount,
|
||||
rasterDrawableUBOCount
|
||||
idLocationIndicatorDrawableUBO = drawableReservedUBOCount,
|
||||
locationIndicatorDrawableUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idSymbolDrawableUBO = globalUBOCount,
|
||||
idSymbolTilePropsUBO,
|
||||
idSymbolInterpolateUBO,
|
||||
symbolDrawableUBOCount
|
||||
idRasterDrawableUBO = idDrawableReservedVertexOnlyUBO,
|
||||
rasterDrawableUBOCount = drawableReservedUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idWideVectorUniformsUBO = globalUBOCount,
|
||||
idWideVectorUniformWideVecUBO,
|
||||
idSymbolDrawableUBO = idDrawableReservedVertexOnlyUBO,
|
||||
idSymbolTilePropsUBO = idDrawableReservedFragmentOnlyUBO,
|
||||
symbolDrawableUBOCount = drawableReservedUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idWideVectorUniformsUBO = idDrawableReservedVertexOnlyUBO,
|
||||
idWideVectorUniformWideVecUBO = drawableReservedUBOCount,
|
||||
wideVectorDrawableUBOCount
|
||||
};
|
||||
|
||||
static constexpr auto layerUBOStartId = std::max({static_cast<size_t>(circleDrawableUBOCount),
|
||||
static_cast<size_t>(backgroundDrawableUBOCount),
|
||||
static_cast<size_t>(customSymbolDrawableUBOCount),
|
||||
static constexpr auto layerSSBOStartId = globalUBOCount;
|
||||
static constexpr auto layerUBOStartId = std::max({static_cast<size_t>(backgroundDrawableUBOCount),
|
||||
static_cast<size_t>(circleDrawableUBOCount),
|
||||
static_cast<size_t>(clippingMaskDrawableUBOCount),
|
||||
static_cast<size_t>(collisionDrawableUBOCount),
|
||||
static_cast<size_t>(commonDrawableUBOCount),
|
||||
static_cast<size_t>(customSymbolDrawableUBOCount),
|
||||
static_cast<size_t>(debugDrawableUBOCount),
|
||||
static_cast<size_t>(fillDrawableUBOCount),
|
||||
static_cast<size_t>(fillExtrusionDrawableUBOCount),
|
||||
static_cast<size_t>(heatmapDrawableUBOCount),
|
||||
static_cast<size_t>(heatmapTextureDrawableUBOCount),
|
||||
static_cast<size_t>(hillshadeDrawableUBOCount),
|
||||
static_cast<size_t>(hillshadePrepareDrawableUBOCount),
|
||||
static_cast<size_t>(lineDrawableUBOCount),
|
||||
static_cast<size_t>(locationIndicatorDrawableUBOCount),
|
||||
static_cast<size_t>(rasterDrawableUBOCount),
|
||||
static_cast<size_t>(symbolDrawableUBOCount),
|
||||
static_cast<size_t>(wideVectorDrawableUBOCount)});
|
||||
@@ -127,14 +130,30 @@ static constexpr auto maxUBOCountPerDrawable = layerUBOStartId - globalUBOCount;
|
||||
#define getLayerStartValue(packedValue) packedValue
|
||||
#endif
|
||||
|
||||
enum {
|
||||
idBackgroundPropsUBO = getLayerStartValue(backgroundDrawableUBOCount),
|
||||
backgroundUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idCircleEvaluatedPropsUBO = getLayerStartValue(circleDrawableUBOCount),
|
||||
circleUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
idBackgroundLayerUBO = getLayerStartValue(backgroundDrawableUBOCount),
|
||||
backgroundUBOCount
|
||||
clippingMaskUBOCount = getLayerStartValue(clippingMaskDrawableUBOCount)
|
||||
};
|
||||
|
||||
enum {
|
||||
collisionUBOCount = getLayerStartValue(collisionDrawableUBOCount)
|
||||
};
|
||||
|
||||
enum {
|
||||
customSymbolUBOCount = getLayerStartValue(customSymbolDrawableUBOCount)
|
||||
};
|
||||
|
||||
enum {
|
||||
debugUBOCount = getLayerStartValue(debugDrawableUBOCount)
|
||||
};
|
||||
|
||||
enum {
|
||||
@@ -153,7 +172,7 @@ enum {
|
||||
};
|
||||
|
||||
enum {
|
||||
idHeatmapTexturePropsUBO = getLayerStartValue(globalUBOCount),
|
||||
idHeatmapTexturePropsUBO = getLayerStartValue(heatmapTextureDrawableUBOCount),
|
||||
heatmapTextureUBOCount
|
||||
};
|
||||
|
||||
@@ -162,12 +181,20 @@ enum {
|
||||
hillshadeUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
hillshadePrepareUBOCount = getLayerStartValue(hillshadePrepareDrawableUBOCount)
|
||||
};
|
||||
|
||||
enum {
|
||||
idLineEvaluatedPropsUBO = getLayerStartValue(lineDrawableUBOCount),
|
||||
idLineExpressionUBO,
|
||||
lineUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
locationIndicatorUBOCount = getLayerStartValue(locationIndicatorDrawableUBOCount)
|
||||
};
|
||||
|
||||
enum {
|
||||
idRasterEvaluatedPropsUBO = getLayerStartValue(rasterDrawableUBOCount),
|
||||
rasterUBOCount
|
||||
@@ -178,19 +205,31 @@ enum {
|
||||
symbolUBOCount
|
||||
};
|
||||
|
||||
enum {
|
||||
wideVectorUBOCount = getLayerStartValue(wideVectorDrawableUBOCount)
|
||||
};
|
||||
|
||||
#undef getLayerStartValue
|
||||
|
||||
static constexpr auto maxUBOCountPerShader = std::max({static_cast<size_t>(circleUBOCount),
|
||||
static constexpr auto maxUBOCountPerShader = std::max({static_cast<size_t>(backgroundUBOCount),
|
||||
static_cast<size_t>(circleUBOCount),
|
||||
static_cast<size_t>(clippingMaskUBOCount),
|
||||
static_cast<size_t>(collisionUBOCount),
|
||||
static_cast<size_t>(customSymbolUBOCount),
|
||||
static_cast<size_t>(debugUBOCount),
|
||||
static_cast<size_t>(fillUBOCount),
|
||||
static_cast<size_t>(fillExtrusionUBOCount),
|
||||
static_cast<size_t>(heatmapUBOCount),
|
||||
static_cast<size_t>(heatmapTextureUBOCount),
|
||||
static_cast<size_t>(hillshadeUBOCount),
|
||||
static_cast<size_t>(hillshadePrepareUBOCount),
|
||||
static_cast<size_t>(lineUBOCount),
|
||||
static_cast<size_t>(locationIndicatorUBOCount),
|
||||
static_cast<size_t>(rasterUBOCount),
|
||||
static_cast<size_t>(symbolUBOCount)});
|
||||
static_cast<size_t>(symbolUBOCount),
|
||||
static_cast<size_t>(wideVectorUBOCount)});
|
||||
|
||||
static constexpr auto maxSSBOCountPerLayer = maxUBOCountPerDrawable;
|
||||
static constexpr auto maxUBOCountPerLayer = maxUBOCountPerShader - layerUBOStartId;
|
||||
|
||||
// Texture defines
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <mbgl/shaders/gl/drawable_circle.hpp>
|
||||
#include <mbgl/shaders/gl/drawable_collision_box.hpp>
|
||||
#include <mbgl/shaders/gl/drawable_collision_circle.hpp>
|
||||
#include <mbgl/shaders/gl/drawable_custom_symbol_icon.hpp>
|
||||
#include <mbgl/shaders/gl/drawable_debug.hpp>
|
||||
#include <mbgl/shaders/gl/drawable_fill.hpp>
|
||||
#include <mbgl/shaders/gl/drawable_fill_outline.hpp>
|
||||
@@ -23,12 +24,13 @@
|
||||
#include <mbgl/shaders/gl/drawable_line.hpp>
|
||||
#include <mbgl/shaders/gl/drawable_line_gradient.hpp>
|
||||
#include <mbgl/shaders/gl/drawable_line_pattern.hpp>
|
||||
#include <mbgl/shaders/gl/drawable_location_indicator.hpp>
|
||||
#include <mbgl/shaders/gl/drawable_location_indicator_textured.hpp>
|
||||
#include <mbgl/shaders/gl/drawable_line_sdf.hpp>
|
||||
#include <mbgl/shaders/gl/drawable_raster.hpp>
|
||||
#include <mbgl/shaders/gl/drawable_symbol_icon.hpp>
|
||||
#include <mbgl/shaders/gl/drawable_symbol_sdf.hpp>
|
||||
#include <mbgl/shaders/gl/drawable_symbol_text_and_icon.hpp>
|
||||
#include <mbgl/shaders/gl/drawable_custom_symbol_icon.hpp>
|
||||
#include <mbgl/shaders/gl/drawable_wide_vector.hpp>
|
||||
#include <mbgl/shaders/gl/prelude.hpp>
|
||||
#include <mbgl/shaders/gl/background.hpp>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/gfx/shader.hpp>
|
||||
#include <mbgl/gfx/uniform_block.hpp>
|
||||
#include <mbgl/gfx/vertex_attribute.hpp>
|
||||
#include <mbgl/util/identity.hpp>
|
||||
|
||||
@@ -34,18 +33,12 @@ public:
|
||||
/// @param name uniform name
|
||||
virtual std::optional<size_t> getSamplerLocation(const size_t) const = 0;
|
||||
|
||||
/// Get the available uniform blocks attached to this shader
|
||||
virtual const gfx::UniformBlockArray& getUniformBlocks() const = 0;
|
||||
|
||||
/// Get the available vertex attributes and their default values
|
||||
virtual const gfx::VertexAttributeArray& getVertexAttributes() const = 0;
|
||||
|
||||
/// Get the available instance attributes and their default values
|
||||
virtual const gfx::VertexAttributeArray& getInstanceAttributes() const = 0;
|
||||
|
||||
protected:
|
||||
virtual gfx::UniformBlockArray& mutableUniformBlocks() = 0;
|
||||
|
||||
protected:
|
||||
util::SimpleIdentity shaderProgramID;
|
||||
};
|
||||
|
||||
@@ -14,8 +14,7 @@ enum class BuiltIn {
|
||||
CircleShader,
|
||||
CollisionBoxShader,
|
||||
CollisionCircleShader,
|
||||
CommonShader,
|
||||
CommonTexturedShader,
|
||||
CustomSymbolIconShader,
|
||||
DebugShader,
|
||||
FillShader,
|
||||
FillOutlineShader,
|
||||
@@ -31,12 +30,13 @@ enum class BuiltIn {
|
||||
LineShader,
|
||||
LineGradientShader,
|
||||
LinePatternShader,
|
||||
LocationIndicatorShader,
|
||||
LocationIndicatorTexturedShader,
|
||||
LineSDFShader,
|
||||
RasterShader,
|
||||
SymbolIconShader,
|
||||
SymbolSDFIconShader,
|
||||
SymbolTextAndIconShader,
|
||||
CustomSymbolIconShader,
|
||||
WideVectorShader,
|
||||
Prelude,
|
||||
BackgroundProgram,
|
||||
|
||||
@@ -13,39 +13,33 @@ struct alignas(16) SymbolDrawableUBO {
|
||||
/* 192 */ std::array<float, 2> texsize;
|
||||
/* 200 */ std::array<float, 2> texsize_icon;
|
||||
|
||||
/* 208 */ float gamma_scale;
|
||||
/* 208 */ /*bool*/ int is_text_prop;
|
||||
/* 212 */ /*bool*/ int rotate_symbol;
|
||||
/* 216 */ /*bool*/ int pitch_with_map;
|
||||
/* 220 */ /*bool*/ int is_size_zoom_constant;
|
||||
/* 224 */ /*bool*/ int is_size_feature_constant;
|
||||
|
||||
/* 216 */ std::array<float, 2> pad;
|
||||
/* 224 */
|
||||
/* 228 */ float size_t;
|
||||
/* 232 */ float size;
|
||||
|
||||
// Interpolations
|
||||
/* 236 */ float fill_color_t;
|
||||
/* 240 */ float halo_color_t;
|
||||
/* 244 */ float opacity_t;
|
||||
/* 248 */ float halo_width_t;
|
||||
/* 252 */ float halo_blur_t;
|
||||
/* 256 */
|
||||
};
|
||||
static_assert(sizeof(SymbolDrawableUBO) == 14 * 16);
|
||||
static_assert(sizeof(SymbolDrawableUBO) == 16 * 16);
|
||||
|
||||
/// Evaluated properties that depend on the tile
|
||||
struct alignas(16) SymbolTilePropsUBO {
|
||||
/* 0 */ /*bool*/ int is_text;
|
||||
/* 4 */ /*bool*/ int is_halo;
|
||||
/* 8 */ /*bool*/ int pitch_with_map;
|
||||
/* 12 */ /*bool*/ int is_size_zoom_constant;
|
||||
/* 16 */ /*bool*/ int is_size_feature_constant;
|
||||
/* 20 */ float size_t;
|
||||
/* 24 */ float size;
|
||||
/* 28 */ float padding;
|
||||
/* 32 */
|
||||
/* 8 */ float gamma_scale;
|
||||
/* 12 */ float pad1;
|
||||
/* 16 */
|
||||
};
|
||||
static_assert(sizeof(SymbolTilePropsUBO) == 2 * 16);
|
||||
|
||||
/// Attribute interpolations
|
||||
struct alignas(16) SymbolInterpolateUBO {
|
||||
/* 0 */ float fill_color_t;
|
||||
/* 4 */ float halo_color_t;
|
||||
/* 8 */ float opacity_t;
|
||||
/* 12 */ float halo_width_t;
|
||||
/* 16 */ float halo_blur_t;
|
||||
/* 20 */ float pad1, pad2, pad3;
|
||||
/* 32 */
|
||||
};
|
||||
static_assert(sizeof(SymbolInterpolateUBO) == 32);
|
||||
static_assert(sizeof(SymbolTilePropsUBO) == 16);
|
||||
|
||||
/// Evaluated properties that do not depend on the tile
|
||||
struct alignas(16) SymbolEvaluatedPropsUBO {
|
||||
|
||||
@@ -6,37 +6,58 @@
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
#define BACKGROUND_SHADER_COMMON \
|
||||
R"(
|
||||
|
||||
#define idBackgroundDrawableUBO idDrawableReservedVertexOnlyUBO
|
||||
#define idBackgroundPropsUBO layerUBOStartId
|
||||
|
||||
)"
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::BackgroundShader, gfx::Backend::Type::Vulkan> {
|
||||
static constexpr const char* name = "BackgroundShader";
|
||||
|
||||
static const std::array<UniformBlockInfo, 2> uniforms;
|
||||
static const std::array<AttributeInfo, 1> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static constexpr std::array<TextureInfo, 0> textures{};
|
||||
static const std::array<TextureInfo, 0> textures;
|
||||
|
||||
static constexpr auto vertex = R"(
|
||||
static constexpr auto vertex = BACKGROUND_SHADER_COMMON R"(
|
||||
|
||||
layout(location = 0) in ivec2 in_position;
|
||||
|
||||
layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform BackgroundDrawableUBO {
|
||||
layout(push_constant) uniform Constants {
|
||||
int ubo_index;
|
||||
} constant;
|
||||
|
||||
struct BackgroundDrawableUBO {
|
||||
mat4 matrix;
|
||||
} drawable;
|
||||
vec4 pad1;
|
||||
vec4 pad2;
|
||||
};
|
||||
|
||||
layout(std140, set = LAYER_SET_INDEX, binding = idBackgroundDrawableUBO) readonly buffer BackgroundDrawableUBOVector {
|
||||
BackgroundDrawableUBO drawable_ubo[];
|
||||
} drawableVector;
|
||||
|
||||
void main() {
|
||||
const BackgroundDrawableUBO drawable = drawableVector.drawable_ubo[constant.ubo_index];
|
||||
|
||||
gl_Position = drawable.matrix * vec4(in_position, 0.0, 1.0);
|
||||
applySurfaceTransform();
|
||||
}
|
||||
)";
|
||||
|
||||
static constexpr auto fragment = R"(
|
||||
static constexpr auto fragment = BACKGROUND_SHADER_COMMON R"(
|
||||
layout(location = 0) out vec4 out_color;
|
||||
|
||||
layout(set = LAYER_SET_INDEX, binding = 0) uniform BackgroundLayerUBO {
|
||||
layout(set = LAYER_SET_INDEX, binding = idBackgroundPropsUBO) uniform BackgroundPropsUBO {
|
||||
vec4 color;
|
||||
float opacity;
|
||||
float pad1, pad2, pad3;
|
||||
} layer;
|
||||
float pad1;
|
||||
float pad2;
|
||||
float pad3;
|
||||
} props;
|
||||
|
||||
void main() {
|
||||
|
||||
@@ -45,7 +66,7 @@ void main() {
|
||||
return;
|
||||
#endif
|
||||
|
||||
out_color = layer.color * layer.opacity;
|
||||
out_color = props.color * props.opacity;
|
||||
}
|
||||
)";
|
||||
};
|
||||
@@ -54,24 +75,32 @@ template <>
|
||||
struct ShaderSource<BuiltIn::BackgroundPatternShader, gfx::Backend::Type::Vulkan> {
|
||||
static constexpr const char* name = "BackgroundPatternShader";
|
||||
|
||||
static const std::array<UniformBlockInfo, 3> uniforms;
|
||||
static const std::array<AttributeInfo, 1> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static const std::array<TextureInfo, 1> textures;
|
||||
|
||||
static constexpr auto vertex = R"(
|
||||
|
||||
static constexpr auto vertex = BACKGROUND_SHADER_COMMON R"(
|
||||
layout(location = 0) in ivec2 in_position;
|
||||
|
||||
layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform BackgroundPatternDrawableUBO {
|
||||
layout(push_constant) uniform Constants {
|
||||
int ubo_index;
|
||||
} constant;
|
||||
|
||||
struct BackgroundPatternDrawableUBO {
|
||||
mat4 matrix;
|
||||
vec2 pixel_coord_upper;
|
||||
vec2 pixel_coord_lower;
|
||||
float tile_units_to_pixels;
|
||||
float pad1, pad2, pad3;
|
||||
} drawable;
|
||||
float pad1;
|
||||
float pad2;
|
||||
float pad3;
|
||||
};
|
||||
|
||||
layout(set = LAYER_SET_INDEX, binding = 0) uniform BackgroundPatternLayerUBO {
|
||||
layout(std140, set = LAYER_SET_INDEX, binding = idBackgroundDrawableUBO) readonly buffer BackgroundPatternDrawableUBOVector {
|
||||
BackgroundPatternDrawableUBO drawable_ubo[];
|
||||
} drawableVector;
|
||||
|
||||
layout(set = LAYER_SET_INDEX, binding = idBackgroundPropsUBO) uniform BackgroundPatternPropsUBO {
|
||||
vec2 pattern_tl_a;
|
||||
vec2 pattern_br_a;
|
||||
vec2 pattern_tl_b;
|
||||
@@ -82,21 +111,22 @@ layout(set = LAYER_SET_INDEX, binding = 0) uniform BackgroundPatternLayerUBO {
|
||||
float scale_b;
|
||||
float mix;
|
||||
float opacity;
|
||||
} layer;
|
||||
} props;
|
||||
|
||||
layout(location = 0) out vec2 frag_pos_a;
|
||||
layout(location = 1) out vec2 frag_pos_b;
|
||||
|
||||
void main() {
|
||||
const BackgroundPatternDrawableUBO drawable = drawableVector.drawable_ubo[constant.ubo_index];
|
||||
|
||||
frag_pos_a = get_pattern_pos(drawable.pixel_coord_upper,
|
||||
drawable.pixel_coord_lower,
|
||||
layer.scale_a * layer.pattern_size_a,
|
||||
props.scale_a * props.pattern_size_a,
|
||||
drawable.tile_units_to_pixels,
|
||||
in_position);
|
||||
frag_pos_b = get_pattern_pos(drawable.pixel_coord_upper,
|
||||
drawable.pixel_coord_lower,
|
||||
layer.scale_b * layer.pattern_size_b,
|
||||
props.scale_b * props.pattern_size_b,
|
||||
drawable.tile_units_to_pixels,
|
||||
in_position);
|
||||
|
||||
@@ -105,13 +135,13 @@ void main() {
|
||||
}
|
||||
)";
|
||||
|
||||
static constexpr auto fragment = R"(
|
||||
static constexpr auto fragment = BACKGROUND_SHADER_COMMON R"(
|
||||
layout(location = 0) in vec2 frag_pos_a;
|
||||
layout(location = 1) in vec2 frag_pos_b;
|
||||
|
||||
layout(location = 0) out vec4 out_color;
|
||||
|
||||
layout(set = LAYER_SET_INDEX, binding = 0) uniform BackgroundPatternLayerUBO {
|
||||
layout(set = LAYER_SET_INDEX, binding = idBackgroundPropsUBO) uniform BackgroundPatternLayerUBO {
|
||||
vec2 pattern_tl_a;
|
||||
vec2 pattern_br_a;
|
||||
vec2 pattern_tl_b;
|
||||
@@ -122,7 +152,7 @@ layout(set = LAYER_SET_INDEX, binding = 0) uniform BackgroundPatternLayerUBO {
|
||||
float scale_b;
|
||||
float mix;
|
||||
float opacity;
|
||||
} layer;
|
||||
} props;
|
||||
|
||||
layout(set = DRAWABLE_IMAGE_SET_INDEX, binding = 0) uniform sampler2D image_sampler;
|
||||
|
||||
@@ -133,17 +163,17 @@ void main() {
|
||||
return;
|
||||
#endif
|
||||
|
||||
const vec2 texsize = global.pattern_atlas_texsize;
|
||||
const vec2 texsize = paintParams.pattern_atlas_texsize;
|
||||
|
||||
const vec2 imagecoord = mod(frag_pos_a, 1.0);
|
||||
const vec2 pos = mix(layer.pattern_tl_a / texsize, layer.pattern_br_a / texsize, imagecoord);
|
||||
const vec2 pos = mix(props.pattern_tl_a / texsize, props.pattern_br_a / texsize, imagecoord);
|
||||
const vec4 color1 = texture(image_sampler, pos);
|
||||
|
||||
const vec2 imagecoord_b = mod(frag_pos_b, 1.0);
|
||||
const vec2 pos2 = mix(layer.pattern_tl_b / texsize, layer.pattern_br_b / texsize, imagecoord_b);
|
||||
const vec2 pos2 = mix(props.pattern_tl_b / texsize, props.pattern_br_b / texsize, imagecoord_b);
|
||||
const vec4 color2 = texture(image_sampler, pos2);
|
||||
|
||||
out_color = mix(color1, color2, layer.mix) * layer.opacity;
|
||||
out_color = mix(color1, color2, props.mix) * props.opacity;
|
||||
}
|
||||
)";
|
||||
};
|
||||
|
||||
@@ -6,16 +6,23 @@
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
#define CIRCLE_SHADER_PRELUDE \
|
||||
R"(
|
||||
|
||||
#define idCircleDrawableUBO idDrawableReservedVertexOnlyUBO
|
||||
#define idCircleEvaluatedPropsUBO layerUBOStartId
|
||||
|
||||
)"
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::CircleShader, gfx::Backend::Type::Vulkan> {
|
||||
static constexpr const char* name = "CircleShader";
|
||||
|
||||
static const std::array<UniformBlockInfo, 4> uniforms;
|
||||
static const std::array<AttributeInfo, 8> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static constexpr std::array<TextureInfo, 0> textures{};
|
||||
static const std::array<TextureInfo, 0> textures;
|
||||
|
||||
static constexpr auto vertex = R"(
|
||||
static constexpr auto vertex = CIRCLE_SHADER_PRELUDE R"(
|
||||
|
||||
layout(location = 0) in ivec2 in_position;
|
||||
|
||||
@@ -47,13 +54,14 @@ layout(location = 6) in vec2 in_stroke_width;
|
||||
layout(location = 7) in vec2 in_stroke_opacity;
|
||||
#endif
|
||||
|
||||
layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform CircleDrawableUBO {
|
||||
layout(push_constant) uniform Constants {
|
||||
int ubo_index;
|
||||
} constant;
|
||||
|
||||
struct CircleDrawableUBO {
|
||||
mat4 matrix;
|
||||
vec2 extrude_scale;
|
||||
vec2 padding;
|
||||
} drawable;
|
||||
|
||||
layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform CircleInterpolateUBO {
|
||||
// Interpolations
|
||||
float color_t;
|
||||
float radius_t;
|
||||
float blur_t;
|
||||
@@ -61,10 +69,16 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform CircleInterpolateUBO {
|
||||
float stroke_color_t;
|
||||
float stroke_width_t;
|
||||
float stroke_opacity_t;
|
||||
float pad1_;
|
||||
} interp;
|
||||
float pad1;
|
||||
float pad2;
|
||||
float pad3;
|
||||
};
|
||||
|
||||
layout(set = LAYER_SET_INDEX, binding = 0) uniform CircleEvaluatedPropsUBO {
|
||||
layout(std140, set = LAYER_SET_INDEX, binding = idCircleDrawableUBO) readonly buffer CircleDrawableUBOVector {
|
||||
CircleDrawableUBO drawable_ubo[];
|
||||
} drawableVector;
|
||||
|
||||
layout(set = LAYER_SET_INDEX, binding = idCircleEvaluatedPropsUBO) uniform CircleEvaluatedPropsUBO {
|
||||
vec4 color;
|
||||
vec4 stroke_color;
|
||||
float radius;
|
||||
@@ -74,7 +88,7 @@ layout(set = LAYER_SET_INDEX, binding = 0) uniform CircleEvaluatedPropsUBO {
|
||||
float stroke_opacity;
|
||||
bool scale_with_map;
|
||||
bool pitch_with_map;
|
||||
float padding;
|
||||
float pad1;
|
||||
} props;
|
||||
|
||||
layout(location = 0) out vec2 frag_extrude;
|
||||
@@ -109,17 +123,18 @@ layout(location = 8) out lowp float frag_stroke_opacity;
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
const CircleDrawableUBO drawable = drawableVector.drawable_ubo[constant.ubo_index];
|
||||
|
||||
#if defined(HAS_UNIFORM_u_radius)
|
||||
const float radius = props.radius;
|
||||
#else
|
||||
const float radius = unpack_mix_float(in_radius, interp.radius_t);
|
||||
const float radius = unpack_mix_float(in_radius, drawable.radius_t);
|
||||
#endif
|
||||
|
||||
#if defined(HAS_UNIFORM_u_stroke_width)
|
||||
const float stroke_width = props.stroke_width;
|
||||
#else
|
||||
const float stroke_width = unpack_mix_float(in_stroke_width, interp.stroke_width_t);
|
||||
const float stroke_width = unpack_mix_float(in_stroke_width, drawable.stroke_width_t);
|
||||
#endif
|
||||
|
||||
// unencode the extrusion vector that we snuck into the a_pos vector
|
||||
@@ -139,14 +154,14 @@ void main() {
|
||||
// whole circle based on the pitch scaling effect at its central point
|
||||
const vec4 projected_center = drawable.matrix * vec4(circle_center, 0, 1);
|
||||
corner_position += scaled_extrude * (radius + stroke_width) *
|
||||
(projected_center.w / global.camera_to_center_distance);
|
||||
(projected_center.w / paintParams.camera_to_center_distance);
|
||||
}
|
||||
|
||||
gl_Position = drawable.matrix * vec4(corner_position, 0, 1);
|
||||
} else {
|
||||
gl_Position = drawable.matrix * vec4(circle_center, 0, 1);
|
||||
|
||||
const float factor = props.scale_with_map ? global.camera_to_center_distance : gl_Position.w;
|
||||
const float factor = props.scale_with_map ? paintParams.camera_to_center_distance : gl_Position.w;
|
||||
gl_Position.xy += scaled_extrude * (radius + stroke_width) * factor;
|
||||
}
|
||||
|
||||
@@ -160,7 +175,7 @@ void main() {
|
||||
frag_extrude = extrude;
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_color)
|
||||
frag_color = unpack_mix_color(in_color, interp.color_t);
|
||||
frag_color = unpack_mix_color(in_color, drawable.color_t);
|
||||
#endif
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_radius)
|
||||
@@ -168,15 +183,15 @@ void main() {
|
||||
#endif
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_blur)
|
||||
frag_blur = unpack_mix_float(in_blur, interp.blur_t);
|
||||
frag_blur = unpack_mix_float(in_blur, drawable.blur_t);
|
||||
#endif
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_opacity)
|
||||
frag_opacity = unpack_mix_float(in_opacity, interp.opacity_t);
|
||||
frag_opacity = unpack_mix_float(in_opacity, drawable.opacity_t);
|
||||
#endif
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_stroke_color)
|
||||
frag_stroke_color = unpack_mix_color(in_stroke_color, interp.stroke_color_t);
|
||||
frag_stroke_color = unpack_mix_color(in_stroke_color, drawable.stroke_color_t);
|
||||
#endif
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_stroke_width)
|
||||
@@ -184,12 +199,12 @@ void main() {
|
||||
#endif
|
||||
|
||||
#if !defined(HAS_UNIFORM_u_stroke_opacity)
|
||||
frag_stroke_opacity = unpack_mix_float(in_stroke_opacity, interp.stroke_opacity_t);
|
||||
frag_stroke_opacity = unpack_mix_float(in_stroke_opacity, drawable.stroke_opacity_t);
|
||||
#endif
|
||||
}
|
||||
)";
|
||||
|
||||
static constexpr auto fragment = R"(
|
||||
static constexpr auto fragment = CIRCLE_SHADER_PRELUDE R"(
|
||||
|
||||
layout(location = 0) in vec2 frag_extrude;
|
||||
layout(location = 1) in float frag_antialiasblur;
|
||||
@@ -224,7 +239,7 @@ layout(location = 8) in lowp float frag_stroke_opacity;
|
||||
|
||||
layout(location = 0) out vec4 out_color;
|
||||
|
||||
layout(set = LAYER_SET_INDEX, binding = 0) uniform CircleEvaluatedPropsUBO {
|
||||
layout(set = LAYER_SET_INDEX, binding = idCircleEvaluatedPropsUBO) uniform CircleEvaluatedPropsUBO {
|
||||
vec4 color;
|
||||
vec4 stroke_color;
|
||||
float radius;
|
||||
@@ -234,7 +249,7 @@ layout(set = LAYER_SET_INDEX, binding = 0) uniform CircleEvaluatedPropsUBO {
|
||||
float stroke_opacity;
|
||||
bool scale_with_map;
|
||||
bool pitch_with_map;
|
||||
float padding;
|
||||
float pad1;
|
||||
} props;
|
||||
|
||||
void main() {
|
||||
|
||||
@@ -16,10 +16,9 @@ template <>
|
||||
struct ShaderSource<BuiltIn::ClippingMaskProgram, gfx::Backend::Type::Vulkan> {
|
||||
static constexpr const char* name = "ClippingMaskProgram";
|
||||
|
||||
static constexpr std::array<UniformBlockInfo, 0> uniforms{};
|
||||
static const std::array<AttributeInfo, 1> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static constexpr std::array<TextureInfo, 0> textures{};
|
||||
static const std::array<TextureInfo, 0> textures;
|
||||
|
||||
static constexpr auto vertex = R"(
|
||||
layout(location = 0) in ivec2 position;
|
||||
|
||||
@@ -6,16 +6,23 @@
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
#define COLLISION_SHADER_COMMON \
|
||||
R"(
|
||||
|
||||
#define idCollisionDrawableUBO idDrawableReservedVertexOnlyUBO
|
||||
#define idCollisionTilePropsUBO drawableReservedUBOCount
|
||||
|
||||
)"
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::CollisionBoxShader, gfx::Backend::Type::Vulkan> {
|
||||
static constexpr const char* name = "CollisionBoxShader";
|
||||
|
||||
static const std::array<UniformBlockInfo, 1> uniforms;
|
||||
static const std::array<AttributeInfo, 5> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static constexpr std::array<TextureInfo, 0> textures{};
|
||||
static const std::array<TextureInfo, 0> textures;
|
||||
|
||||
static constexpr auto vertex = R"(
|
||||
static constexpr auto vertex = COLLISION_SHADER_COMMON R"(
|
||||
|
||||
layout(location = 0) in ivec2 in_position;
|
||||
layout(location = 1) in ivec2 in_anchor_position;
|
||||
@@ -23,12 +30,15 @@ layout(location = 2) in ivec2 in_extrude;
|
||||
layout(location = 3) in uvec2 in_placed;
|
||||
layout(location = 4) in vec2 in_shift;
|
||||
|
||||
layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform CollisionBoxUBO {
|
||||
layout(set = DRAWABLE_UBO_SET_INDEX, binding = idCollisionDrawableUBO) uniform CollisionDrawableUBO {
|
||||
mat4 matrix;
|
||||
} drawable;
|
||||
|
||||
layout(set = DRAWABLE_UBO_SET_INDEX, binding = idCollisionTilePropsUBO) uniform CollisionTilePropsUBO {
|
||||
vec2 extrude_scale;
|
||||
float overscale_factor;
|
||||
float pad1;
|
||||
} drawable;
|
||||
} tileProps;
|
||||
|
||||
layout(location = 0) out float frag_placed;
|
||||
layout(location = 1) out float frag_notUsed;
|
||||
@@ -38,12 +48,12 @@ void main() {
|
||||
vec4 projectedPoint = drawable.matrix * vec4(in_anchor_position, 0.0, 1.0);
|
||||
float camera_to_anchor_distance = projectedPoint.w;
|
||||
float collision_perspective_ratio = clamp(
|
||||
0.5 + 0.5 * (global.camera_to_center_distance / camera_to_anchor_distance),
|
||||
0.5 + 0.5 * (paintParams.camera_to_center_distance / camera_to_anchor_distance),
|
||||
0.0, // Prevents oversized near-field boxes in pitched/overzoomed tiles
|
||||
4.0);
|
||||
|
||||
gl_Position = drawable.matrix * vec4(in_position, 0.0, 1.0);
|
||||
gl_Position.xy += (in_extrude + in_shift) * drawable.extrude_scale * gl_Position.w * collision_perspective_ratio;
|
||||
gl_Position.xy += (in_extrude + in_shift) * tileProps.extrude_scale * gl_Position.w * collision_perspective_ratio;
|
||||
applySurfaceTransform();
|
||||
|
||||
frag_placed = in_placed.x;
|
||||
@@ -51,20 +61,13 @@ void main() {
|
||||
}
|
||||
)";
|
||||
|
||||
static constexpr auto fragment = R"(
|
||||
static constexpr auto fragment = COLLISION_SHADER_COMMON R"(
|
||||
|
||||
layout(location = 0) in float frag_placed;
|
||||
layout(location = 1) in float frag_notUsed;
|
||||
|
||||
layout(location = 0) out vec4 out_color;
|
||||
|
||||
layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform CollisionBoxUBO {
|
||||
mat4 matrix;
|
||||
vec2 extrude_scale;
|
||||
float overscale_factor;
|
||||
float pad1;
|
||||
} drawable;
|
||||
|
||||
void main() {
|
||||
|
||||
float alpha = 0.5;
|
||||
@@ -91,24 +94,26 @@ template <>
|
||||
struct ShaderSource<BuiltIn::CollisionCircleShader, gfx::Backend::Type::Vulkan> {
|
||||
static constexpr const char* name = "CollisionCircleShader";
|
||||
|
||||
static const std::array<UniformBlockInfo, 1> uniforms;
|
||||
static const std::array<AttributeInfo, 4> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static constexpr std::array<TextureInfo, 0> textures{};
|
||||
static const std::array<TextureInfo, 0> textures;
|
||||
|
||||
static constexpr auto vertex = R"(
|
||||
static constexpr auto vertex = COLLISION_SHADER_COMMON R"(
|
||||
|
||||
layout(location = 0) in ivec2 in_position;
|
||||
layout(location = 1) in ivec2 in_anchor_position;
|
||||
layout(location = 2) in ivec2 in_extrude;
|
||||
layout(location = 3) in uvec2 in_placed;
|
||||
|
||||
layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform CollisionCircleUBO {
|
||||
layout(set = DRAWABLE_UBO_SET_INDEX, binding = idCollisionDrawableUBO) uniform CollisionDrawableUBO {
|
||||
mat4 matrix;
|
||||
} drawable;
|
||||
|
||||
layout(set = DRAWABLE_UBO_SET_INDEX, binding = idCollisionTilePropsUBO) uniform CollisionTilePropsUBO {
|
||||
vec2 extrude_scale;
|
||||
float overscale_factor;
|
||||
float pad1;
|
||||
} drawable;
|
||||
} tileProps;
|
||||
|
||||
layout(location = 0) out float frag_placed;
|
||||
layout(location = 1) out float frag_notUsed;
|
||||
@@ -121,24 +126,24 @@ void main() {
|
||||
vec4 projectedPoint = drawable.matrix * vec4(in_anchor_position, 0, 1);
|
||||
float camera_to_anchor_distance = projectedPoint.w;
|
||||
float collision_perspective_ratio = clamp(
|
||||
0.5 + 0.5 * (global.camera_to_center_distance / camera_to_anchor_distance),
|
||||
0.5 + 0.5 * (paintParams.camera_to_center_distance / camera_to_anchor_distance),
|
||||
0.0, // Prevents oversized near-field circles in pitched/overzoomed tiles
|
||||
4.0);
|
||||
|
||||
float padding_factor = 1.2; // Pad the vertices slightly to make room for anti-alias blur
|
||||
gl_Position = drawable.matrix * vec4(in_position, 0.0, 1.0);
|
||||
gl_Position.xy += in_extrude * drawable.extrude_scale * padding_factor * gl_Position.w * collision_perspective_ratio;
|
||||
gl_Position.xy += in_extrude * tileProps.extrude_scale * padding_factor * gl_Position.w * collision_perspective_ratio;
|
||||
applySurfaceTransform();
|
||||
|
||||
frag_placed = in_placed.x;
|
||||
frag_notUsed = in_placed.y;
|
||||
frag_radius = abs(float(in_extrude.y)); // We don't pitch the circles, so both units of the extrusion vector are equal in magnitude to the radius
|
||||
frag_extrude = in_extrude * padding_factor;
|
||||
frag_extrude_scale = drawable.extrude_scale * global.camera_to_center_distance * collision_perspective_ratio;
|
||||
frag_extrude_scale = tileProps.extrude_scale * paintParams.camera_to_center_distance * collision_perspective_ratio;
|
||||
}
|
||||
)";
|
||||
|
||||
static constexpr auto fragment = R"(
|
||||
static constexpr auto fragment = COLLISION_SHADER_COMMON R"(
|
||||
|
||||
layout(location = 0) in float frag_placed;
|
||||
layout(location = 1) in float frag_notUsed;
|
||||
@@ -148,12 +153,11 @@ layout(location = 4) in vec2 frag_extrude_scale;
|
||||
|
||||
layout(location = 0) out vec4 out_color;
|
||||
|
||||
layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform CollisionCircleUBO {
|
||||
mat4 matrix;
|
||||
layout(set = DRAWABLE_UBO_SET_INDEX, binding = idCollisionTilePropsUBO) uniform CollisionTilePropsUBO {
|
||||
vec2 extrude_scale;
|
||||
float overscale_factor;
|
||||
float pad1;
|
||||
} drawable;
|
||||
} tileProps;
|
||||
|
||||
void main() {
|
||||
|
||||
@@ -174,7 +178,7 @@ void main() {
|
||||
|
||||
float extrude_scale_length = length(frag_extrude_scale);
|
||||
float extrude_length = length(frag_extrude) * extrude_scale_length;
|
||||
float stroke_width = 15.0 * extrude_scale_length / drawable.overscale_factor;
|
||||
float stroke_width = 15.0 * extrude_scale_length / tileProps.overscale_factor;
|
||||
float radius = frag_radius * extrude_scale_length;
|
||||
|
||||
float distance_to_edge = abs(extrude_length - radius);
|
||||
|
||||
@@ -72,6 +72,11 @@ vec2 get_pattern_pos(const vec2 pixel_coord_upper, const vec2 pixel_coord_lower,
|
||||
#define DRAWABLE_UBO_SET_INDEX 2
|
||||
#define DRAWABLE_IMAGE_SET_INDEX 3
|
||||
|
||||
#define idDrawableReservedVertexOnlyUBO 0
|
||||
#define idDrawableReservedFragmentOnlyUBO 1
|
||||
#define drawableReservedUBOCount 2
|
||||
#define layerUBOStartId 3
|
||||
|
||||
layout(set = GLOBAL_SET_INDEX, binding = 0) uniform GlobalPaintParamsUBO {
|
||||
vec2 pattern_atlas_texsize;
|
||||
vec2 units_to_pixels;
|
||||
@@ -80,19 +85,19 @@ layout(set = GLOBAL_SET_INDEX, binding = 0) uniform GlobalPaintParamsUBO {
|
||||
float symbol_fade_change;
|
||||
float aspect_ratio;
|
||||
float pixel_ratio;
|
||||
float zoom;
|
||||
float map_zoom;
|
||||
float pad1;
|
||||
} global;
|
||||
} paintParams;
|
||||
|
||||
#ifdef USE_SURFACE_TRANSFORM
|
||||
layout(set = GLOBAL_SET_INDEX, binding = 1) uniform PlatformParamsUBO {
|
||||
layout(set = GLOBAL_SET_INDEX, binding = 1) uniform GlobalPlatformParamsUBO {
|
||||
mat2 rotation;
|
||||
} platform;
|
||||
} platformParams;
|
||||
#endif
|
||||
|
||||
void applySurfaceTransform() {
|
||||
#ifdef USE_SURFACE_TRANSFORM
|
||||
gl_Position.xy = platform.rotation * gl_Position.xy;
|
||||
gl_Position.xy = platformParams.rotation * gl_Position.xy;
|
||||
#endif
|
||||
|
||||
gl_Position.y *= -1.0;
|
||||
@@ -110,6 +115,11 @@ void applySurfaceTransform() {
|
||||
#define DRAWABLE_UBO_SET_INDEX 2
|
||||
#define DRAWABLE_IMAGE_SET_INDEX 3
|
||||
|
||||
#define idDrawableReservedVertexOnlyUBO 0
|
||||
#define idDrawableReservedFragmentOnlyUBO 1
|
||||
#define drawableReservedUBOCount 2
|
||||
#define layerUBOStartId 3
|
||||
|
||||
layout(set = GLOBAL_SET_INDEX, binding = 0) uniform GlobalPaintParamsUBO {
|
||||
vec2 pattern_atlas_texsize;
|
||||
vec2 units_to_pixels;
|
||||
@@ -118,89 +128,12 @@ layout(set = GLOBAL_SET_INDEX, binding = 0) uniform GlobalPaintParamsUBO {
|
||||
float symbol_fade_change;
|
||||
float aspect_ratio;
|
||||
float pixel_ratio;
|
||||
float zoom;
|
||||
float map_zoom;
|
||||
float pad1;
|
||||
} global;
|
||||
} paintParams;
|
||||
|
||||
)";
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::CommonShader, gfx::Backend::Type::Vulkan> {
|
||||
static constexpr const char* name = "CommonShader";
|
||||
|
||||
static const std::array<UniformBlockInfo, 1> uniforms;
|
||||
static const std::array<AttributeInfo, 1> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static constexpr std::array<TextureInfo, 0> textures{};
|
||||
|
||||
static constexpr auto vertex = R"(
|
||||
layout(location = 0) in vec2 in_position;
|
||||
|
||||
layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform CommonUBO {
|
||||
mat4 matrix;
|
||||
vec4 color;
|
||||
} ubo;
|
||||
|
||||
void main() {
|
||||
gl_Position = ubo.matrix * vec4(in_position, 0, 1);
|
||||
applySurfaceTransform();
|
||||
}
|
||||
)";
|
||||
|
||||
static constexpr auto fragment = R"(
|
||||
layout(location = 0) out vec4 out_color;
|
||||
|
||||
layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform CommonUBO {
|
||||
mat4 matrix;
|
||||
vec4 color;
|
||||
} ubo;
|
||||
|
||||
void main() {
|
||||
out_color = ubo.color;
|
||||
}
|
||||
)";
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::CommonTexturedShader, gfx::Backend::Type::Vulkan> {
|
||||
static constexpr const char* name = "CommonTexturedShader";
|
||||
|
||||
static const std::array<UniformBlockInfo, 1> uniforms;
|
||||
static const std::array<AttributeInfo, 2> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static const std::array<TextureInfo, 1> textures;
|
||||
|
||||
static constexpr auto vertex = R"(
|
||||
layout(location = 0) in vec2 in_position;
|
||||
layout(location = 1) in vec2 in_texcoord;
|
||||
|
||||
layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform CommonUBO {
|
||||
mat4 matrix;
|
||||
vec4 color;
|
||||
} ubo;
|
||||
|
||||
layout(location = 0) out vec2 frag_uv;
|
||||
|
||||
void main() {
|
||||
gl_Position = ubo.matrix * vec4(in_position, 0, 1);
|
||||
applySurfaceTransform();
|
||||
|
||||
frag_uv = in_texcoord;
|
||||
}
|
||||
)";
|
||||
|
||||
static constexpr auto fragment = R"(
|
||||
layout(location = 0) in vec2 frag_uv;
|
||||
layout(location = 0) out vec4 out_color;
|
||||
|
||||
layout(set = DRAWABLE_IMAGE_SET_INDEX, binding = 0) uniform sampler2D image_sampler;
|
||||
|
||||
void main() {
|
||||
out_color = texture(image_sampler, frag_uv);
|
||||
}
|
||||
)";
|
||||
};
|
||||
|
||||
} // namespace shaders
|
||||
} // namespace mbgl
|
||||
|
||||
107
include/mbgl/shaders/vulkan/custom_symbol_icon.hpp
Normal file
107
include/mbgl/shaders/vulkan/custom_symbol_icon.hpp
Normal file
@@ -0,0 +1,107 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/shaders/shader_source.hpp>
|
||||
#include <mbgl/shaders/vulkan/shader_program.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
#define CUSTOM_SYMBOL_ICON_SHADER_PRELUDE \
|
||||
R"(
|
||||
|
||||
#define idCustomSymbolDrawableUBO idDrawableReservedVertexOnlyUBO
|
||||
|
||||
)"
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::CustomSymbolIconShader, gfx::Backend::Type::Vulkan> {
|
||||
static constexpr const char* name = "CustomSymbolIconShader";
|
||||
|
||||
static const std::array<AttributeInfo, 2> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static const std::array<TextureInfo, 1> textures;
|
||||
|
||||
static constexpr auto vertex = CUSTOM_SYMBOL_ICON_SHADER_PRELUDE R"(
|
||||
|
||||
layout(location = 0) in vec2 in_position;
|
||||
layout(location = 1) in vec2 in_tex;
|
||||
|
||||
layout(set = DRAWABLE_UBO_SET_INDEX, binding = idCustomSymbolDrawableUBO) uniform CustomSymbolIconDrawableUBO {
|
||||
mat4 matrix;
|
||||
vec2 extrude_scale;
|
||||
vec2 anchor;
|
||||
float angle_degrees;
|
||||
bool scale_with_map;
|
||||
bool pitch_with_map;
|
||||
float camera_to_center_distance;
|
||||
float aspect_ratio;
|
||||
float pad1;
|
||||
float pad2;
|
||||
float pad3;
|
||||
} drawable;
|
||||
|
||||
layout(location = 0) out vec2 frag_tex;
|
||||
|
||||
vec2 rotateVec2(vec2 v, float angle) {
|
||||
float cosA = cos(angle);
|
||||
float sinA = sin(angle);
|
||||
return vec2(v.x * cosA - v.y * sinA, v.x * sinA + v.y * cosA);
|
||||
}
|
||||
|
||||
vec2 ellipseRotateVec2(vec2 v, float angle, float radiusRatio /* A/B */) {
|
||||
float cosA = cos(angle);
|
||||
float sinA = sin(angle);
|
||||
float invRatio = 1.0 / radiusRatio;
|
||||
return vec2(v.x * cosA - radiusRatio * v.y * sinA, invRatio * v.x * sinA + v.y * cosA);
|
||||
}
|
||||
|
||||
void main() {
|
||||
const vec2 extrude = mod(in_position, 2.0) * 2.0 - 1.0;
|
||||
const vec2 anchor = (drawable.anchor - vec2(0.5, 0.5)) * 2.0;
|
||||
const vec2 center = floor(in_position * 0.5);
|
||||
const float angle = radians(-drawable.angle_degrees);
|
||||
vec2 corner = extrude - anchor;
|
||||
|
||||
vec4 position;
|
||||
if (drawable.pitch_with_map) {
|
||||
if (drawable.scale_with_map) {
|
||||
corner *= drawable.extrude_scale;
|
||||
} else {
|
||||
vec4 projected_center = drawable.matrix * vec4(center, 0, 1);
|
||||
corner *= drawable.extrude_scale * (projected_center.w / drawable.camera_to_center_distance);
|
||||
}
|
||||
corner = center + rotateVec2(corner, angle);
|
||||
position = drawable.matrix * vec4(corner, 0, 1);
|
||||
} else {
|
||||
position = drawable.matrix * vec4(center, 0, 1);
|
||||
const float factor = drawable.scale_with_map ? drawable.camera_to_center_distance : position.w;
|
||||
position.xy += ellipseRotateVec2(corner * drawable.extrude_scale * factor, angle, drawable.aspect_ratio);
|
||||
}
|
||||
|
||||
gl_Position = position;
|
||||
applySurfaceTransform();
|
||||
|
||||
frag_tex = in_tex;
|
||||
}
|
||||
)";
|
||||
|
||||
static constexpr auto fragment = CUSTOM_SYMBOL_ICON_SHADER_PRELUDE R"(
|
||||
layout(location = 0) in vec2 frag_tex;
|
||||
layout(location = 0) out vec4 out_color;
|
||||
|
||||
layout(set = DRAWABLE_IMAGE_SET_INDEX, binding = 0) uniform sampler2D image_sampler;
|
||||
|
||||
void main() {
|
||||
|
||||
#if defined(OVERDRAW_INSPECTOR)
|
||||
out_color = vec4(1.0);
|
||||
return;
|
||||
#endif
|
||||
|
||||
out_color = texture(image_sampler, frag_tex);
|
||||
}
|
||||
)";
|
||||
};
|
||||
|
||||
} // namespace shaders
|
||||
} // namespace mbgl
|
||||
@@ -6,24 +6,32 @@
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
#define DEBUG_SHADER_PRELUDE \
|
||||
R"(
|
||||
|
||||
#define idDebugUBO drawableReservedUBOCount
|
||||
|
||||
)"
|
||||
|
||||
template <>
|
||||
struct ShaderSource<BuiltIn::DebugShader, gfx::Backend::Type::Vulkan> {
|
||||
static constexpr const char* name = "DebugShader";
|
||||
|
||||
static const std::array<UniformBlockInfo, 1> uniforms;
|
||||
static const std::array<AttributeInfo, 1> attributes;
|
||||
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
|
||||
static const std::array<TextureInfo, 1> textures;
|
||||
|
||||
static constexpr auto vertex = R"(
|
||||
static constexpr auto vertex = DEBUG_SHADER_PRELUDE R"(
|
||||
|
||||
layout(location = 0) in ivec2 in_position;
|
||||
|
||||
layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform DebugUBO {
|
||||
layout(set = DRAWABLE_UBO_SET_INDEX, binding = idDebugUBO) uniform DebugUBO {
|
||||
mat4 matrix;
|
||||
vec4 color;
|
||||
float overlay_scale;
|
||||
float pad1, pad2, pad3;
|
||||
float pad1;
|
||||
float pad2;
|
||||
float pad3;
|
||||
} debug;
|
||||
|
||||
layout(location = 0) out vec2 frag_uv;
|
||||
@@ -39,15 +47,17 @@ void main() {
|
||||
}
|
||||
)";
|
||||
|
||||
static constexpr auto fragment = R"(
|
||||
static constexpr auto fragment = DEBUG_SHADER_PRELUDE R"(
|
||||
layout(location = 0) in vec2 frag_uv;
|
||||
layout(location = 0) out vec4 out_color;
|
||||
|
||||
layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform DebugUBO {
|
||||
layout(set = DRAWABLE_UBO_SET_INDEX, binding = idDebugUBO) uniform DebugUBO {
|
||||
mat4 matrix;
|
||||
vec4 color;
|
||||
float overlay_scale;
|
||||
float pad1, pad2, pad3;
|
||||
float pad1;
|
||||
float pad2;
|
||||
float pad3;
|
||||
} debug;
|
||||
|
||||
layout(set = DRAWABLE_IMAGE_SET_INDEX, binding = 0) uniform sampler2D image_sampler;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user