Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / library / map / src / main / rust / shaders / symbol_billboard.vert
symbol_billboard.vert51 lines · 2.8 KiBRaw
| 1 | #version 450 |
| 2 | |
| 3 | // Billboard symbol vertex: point-label glyph quads and POI icon quads that stay upright and |
| 4 | // pinned to their ground anchor under camera tilt. Both are tessellated per frame (positions |
| 5 | // arrive tile-local and final), and each vertex also carries the label's ground anchor plus its |
| 6 | // tile-normalised ground height, so this shader can, when tilted, project the anchor with |
| 7 | // perspective at the terrain height and hang the corner off it at a constant screen offset. |
| 8 | // Text and icons share this shader on purpose: they hang off the same anchor in the same pass, |
| 9 | // so two implementations of it could drift apart and separate the pictogram from its name. |
| 10 | // |
| 11 | // `misc.x` carries the tile's world-px span (Dp) for this frame; multiplying the anchor height |
| 12 | // recovers the world-px height the perspective matrix expects — the same scale the flat drape |
| 13 | // paths push in `morph.z`. |
| 14 | // |
| 15 | // At pitch 0 the renderer clears the billboard flag (push.line.w) and this reduces to the plain |
| 16 | // `tileToClip * position` the flat map has always used - byte-identical output. A curved (line) |
| 17 | // label writes each glyph vertex as its own anchor (offset zero), so even with the flag set it |
| 18 | // projects straight onto the ground at the glyph's own terrain height and stays map-aligned - |
| 19 | // which is correct: a road name belongs along the road, and is the one label that should lie flat. |
| 20 | layout(location = 0) in vec2 inPosition; |
| 21 | layout(location = 1) in vec2 inUv; |
| 22 | layout(location = 2) in vec2 inAnchor; |
| 23 | layout(location = 3) in float inAnchorH; |
| 24 | layout(location = 0) out vec2 outUv; |
| 25 | layout(push_constant) uniform Push { |
| 26 | mat4 tileToClip; |
| 27 | vec4 color; |
| 28 | // x: text size in px per em (halo SDF), y: halo width px, z: atlas sdf-per-em, |
| 29 | // w: billboard flag (>0.5 = tilt billboard; 0 = flat, drawn straight through tileToClip). |
| 30 | vec4 line; |
| 31 | // x: the tile's world-px span (Dp) for this frame, the anchor-height -> world-px scale; |
| 32 | // yzw: halo color rgb. |
| 33 | vec4 misc; |
| 34 | // The pitch-0 tile matrix's linear 2x2 (column-major m0,m1,m4,m5), so the screen-constant |
| 35 | // offset can be reconstructed while the anchor goes through the perspective matrix. |
| 36 | vec4 morph; |
| 37 | } push; |
| 38 | void main() { |
| 39 | outUv = inUv; |
| 40 | if (push.line.w > 0.5) { |
| 41 | vec4 a = push.tileToClip * vec4(inAnchor, inAnchorH * push.misc.x, 1.0); |
| 42 | vec2 off = inPosition - inAnchor; |
| 43 | // Column-major 2x2 * off: the same screen offset the ortho matrix would give this corner, |
| 44 | // scaled by the anchor's clip-w so the perspective divide leaves it screen-constant. |
| 45 | vec2 offClip = vec2(push.morph.x * off.x + push.morph.z * off.y, |
| 46 | push.morph.y * off.x + push.morph.w * off.y); |
| 47 | gl_Position = vec4(a.xy + offClip * a.w, a.z, a.w); |
| 48 | } else { |
| 49 | gl_Position = push.tileToClip * vec4(inPosition, 0.0, 1.0); |
| 50 | } |
| 51 | } |