Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Tim Sylvester <tim@wetdogweather.com> Co-authored-by: mwilsnd <mwilsnd@gmail.com> Co-authored-by: Stefan Karschti <stefan.karschti@gmail.com> Co-authored-by: Bart Louwers <bart@emeel.net> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: mwilsnd <53413200+mwilsnd@users.noreply.github.com> Co-authored-by: Alex Cristici <alex@skoon.energy> Co-authored-by: Bart Louwers <bart.louwers@gmail.com> Co-authored-by: Wei Chen <alanchenboy@gmail.com> Co-authored-by: Siarhei Fedartsou <siarhei.fedartsou@gmail.com> Co-authored-by: tdcosta100 <tdcosta100@gmail.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
78 lines
2.3 KiB
C++
78 lines
2.3 KiB
C++
#pragma once
|
|
|
|
#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 {
|
|
|
|
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 constexpr AttributeInfo attributes[] = {
|
|
{0, gfx::AttributeDataType::Short2, 1, "a_pos"},
|
|
};
|
|
static constexpr UniformBlockInfo uniforms[] = {
|
|
MLN_MTL_UNIFORM_BLOCK(1, true, true, HeatmapTextureDrawableUBO),
|
|
};
|
|
static constexpr TextureInfo textures[] = {
|
|
{0, "u_image"},
|
|
{1, "u_color_ramp"},
|
|
};
|
|
static constexpr auto source = R"(
|
|
|
|
struct VertexStage {
|
|
short2 pos [[attribute(0)]];
|
|
};
|
|
|
|
struct FragmentStage {
|
|
float4 position [[position, invariant]];
|
|
float2 pos;
|
|
};
|
|
|
|
struct alignas(16) HeatmapTextureDrawableUBO {
|
|
float4x4 matrix;
|
|
float2 world;
|
|
float opacity;
|
|
bool overdrawInspector;
|
|
uint8_t pad1, pad2, pad3;
|
|
};
|
|
|
|
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]],
|
|
device const HeatmapTextureDrawableUBO& drawable [[buffer(1)]]) {
|
|
|
|
const float2 pos = float2(vertx.pos);
|
|
const float4 position = drawable.matrix * float4(pos * drawable.world, 0, 1);
|
|
|
|
return {
|
|
.position = position,
|
|
.pos = pos,
|
|
};
|
|
}
|
|
|
|
half4 fragment fragmentMain(FragmentStage in [[stage_in]],
|
|
device const HeatmapTextureDrawableUBO& drawable [[buffer(1)]],
|
|
texture2d<float, access::sample> image [[texture(0)]],
|
|
texture2d<float, access::sample> color_ramp [[texture(1)]],
|
|
sampler image_sampler [[sampler(0)]],
|
|
sampler color_ramp_sampler [[sampler(1)]]) {
|
|
|
|
if (drawable.overdrawInspector) {
|
|
return half4(0.0);
|
|
}
|
|
|
|
float t = image.sample(image_sampler, in.pos).r;
|
|
float4 color = color_ramp.sample(color_ramp_sampler, float2(t, 0.5));
|
|
return half4(color * drawable.opacity);
|
|
}
|
|
)";
|
|
};
|
|
|
|
} // namespace shaders
|
|
} // namespace mbgl
|