#pragma once #include #include #include namespace mbgl { namespace shaders { template <> struct ShaderSource { static constexpr const char* name = "DebugShader"; 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) uv: vec2, }; struct DebugUBO { matrix: mat4x4, color: vec4, overlay_scale: f32, pad1: f32, pad2: f32, pad3: f32, }; @group(0) @binding(0) var debug: DebugUBO; @vertex fn main(in: VertexInput) -> VertexOutput { var out: VertexOutput; let scaled_pos = vec2(f32(in.position.x), f32(in.position.y)) * debug.overlay_scale; out.position = debug.matrix * vec4(scaled_pos, 0.0, 1.0); // This vertex shader expects a EXTENT x EXTENT quad, // The UV coordinates for the overlay texture can be calculated using that knowledge out.uv = vec2(f32(in.position.x), f32(in.position.y)) / 8192.0; return out; } )"; static constexpr auto fragment = R"( struct FragmentInput { @location(0) uv: vec2, }; struct DebugUBO { matrix: mat4x4, color: vec4, overlay_scale: f32, pad1: f32, pad2: f32, pad3: f32, }; @group(0) @binding(0) var debug: DebugUBO; @group(1) @binding(0) var texture_sampler: sampler; @group(1) @binding(1) var overlay_texture: texture_2d; @fragment fn main(in: FragmentInput) -> @location(0) vec4 { let overlay_color = textureSample(overlay_texture, texture_sampler, in.uv); return mix(debug.color, overlay_color, overlay_color.a); } )"; }; } // namespace shaders } // namespace mbgl