#pragma once #include #include #include namespace mbgl { namespace shaders { template <> struct ShaderSource { static constexpr const char* name = "HeatmapTextureShader"; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; static constexpr auto vertex = R"( struct VertexInput { @location(5) position: vec2, }; struct VertexOutput { @builtin(position) position: vec4, @location(0) tex_coord: vec2, }; struct HeatmapTextureUBO { matrix: mat4x4, opacity: f32, pad1: f32, pad2: f32, pad3: f32, }; struct GlobalPaintParamsUBO { pattern_atlas_texsize: vec2, units_to_pixels: vec2, world_size: vec2, // remaining fields unused }; @group(0) @binding(0) var paintParams: GlobalPaintParamsUBO; @group(0) @binding(4) var ubo: HeatmapTextureUBO; @vertex fn main(in: VertexInput) -> VertexOutput { var out: VertexOutput; let quad_pos = vec2(f32(in.position.x), f32(in.position.y)); let scaled = quad_pos * paintParams.world_size; out.position = ubo.matrix * vec4(scaled, 0.0, 1.0); out.tex_coord = quad_pos; return out; } )"; static constexpr auto fragment = R"( struct FragmentInput { @location(0) tex_coord: vec2, }; struct HeatmapTextureUBO { matrix: mat4x4, opacity: f32, pad1: f32, pad2: f32, pad3: f32, }; @group(0) @binding(4) var ubo: HeatmapTextureUBO; @group(1) @binding(0) var texture_sampler: sampler; @group(1) @binding(1) var heatmap_texture: texture_2d; @group(1) @binding(2) var color_ramp_texture: texture_2d; @fragment fn main(in: FragmentInput) -> @location(0) vec4 { let t = textureSample(heatmap_texture, texture_sampler, in.tex_coord).r; let color = textureSample(color_ramp_texture, texture_sampler, vec2(t, 0.5)); return color * ubo.opacity; } )"; }; } // namespace shaders } // namespace mbgl