Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / library / map / src / main / rust / shaders / fill.vert
fill.vert53 lines · 2.6 KiBRaw
| 1 | #version 450 |
| 2 | |
| 3 | // Fill: solid triangles from the earcut tessellator. |
| 4 | // |
| 5 | // Vertices carry position plus the draped ground height, in tile-local 0..1. The |
| 6 | // tile's placement and the camera both live in the transform, and the layer's |
| 7 | // colour is a constant, so a fill vertex is 12 bytes. `z` is 0.0 straight out of |
| 8 | // the tessellator and filled in by the drape pass where the tile carries a |
| 9 | // heightmap; at pitch 0 it is ignored for x/y. |
| 10 | // |
| 11 | // The incoming height is **tile-normalised** (metres over the tile's ground width, the |
| 12 | // same unit x/y are) so the mesh is zoom-independent. `morph.z` carries the tile's |
| 13 | // world-px span for this frame (Dp, matching what buildings/terrain push as `line.x`); |
| 14 | // multiplying the two recovers the real world-px height the perspective matrix expects |
| 15 | // in its `z` input — exactly as `building.vert`/`terrain.vert` scale their heights. |
| 16 | // |
| 17 | // Everything per-draw arrives in a **push constant** block rather than a uniform |
| 18 | // buffer. 112 bytes is inside the 128 the spec guarantees, and it means the |
| 19 | // renderer needs no descriptor sets, no descriptor pool, and no per-tile uniform |
| 20 | // buffers to keep in sync with the camera. |
| 21 | |
| 22 | layout(location = 0) in vec3 inPosition; |
| 23 | |
| 24 | layout(push_constant) uniform Push { |
| 25 | // Tile-local (u, v, height, 1) to clip space. `height` (the vertex z) is a |
| 26 | // world-px height once scaled — see below. |
| 27 | mat4 tileToClip; |
| 28 | vec4 color; |
| 29 | // x: half stroke width in px, y: half the casing gap in px, |
| 30 | // z: dash length, w: gap length (both in line widths). |
| 31 | vec4 line; |
| 32 | // x: the screen size of one tile in px, which is what converts a pixel width |
| 33 | // into tile-local units. y: edge-AA flag. z: lane lateral offset px. w: the |
| 34 | // per-frame clock in seconds (WS0), read by the animated line paths. |
| 35 | vec4 misc; |
| 36 | // x: per-tile opacity/morph factor (1.0 = fully present), reserved for WS-D's |
| 37 | // LOD cross-fade. y: dash phase speed (line paths). z: the tile's world-px span |
| 38 | // (Dp) for this frame, the tile-norm-height -> world-px scale. w reserved. |
| 39 | vec4 morph; |
| 40 | } push; |
| 41 | |
| 42 | void main() { |
| 43 | float worldHeight = inPosition.z * push.morph.z; |
| 44 | // The height column's w term (tileToClip[2][3]) is 0 on the ortho fast-path (pitch 0) |
| 45 | // and -cos(pitch) once tilted — the same test the building shader uses. At pitch 0 |
| 46 | // feed 0.0 exactly as before, so the flat map is byte-identical with or without a DEM; |
| 47 | // tilted, feed the world-px height so the layer drapes onto the relief. |
| 48 | if (abs(push.tileToClip[2][3]) < 1e-6) { |
| 49 | gl_Position = push.tileToClip * vec4(inPosition.xy, 0.0, 1.0); |
| 50 | } else { |
| 51 | gl_Position = push.tileToClip * vec4(inPosition.xy, worldHeight, 1.0); |
| 52 | } |
| 53 | } |