Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / library / map / src / main / rust / shaders / sprite.frag
sprite.frag34 lines · 1.7 KiBRaw
| 1 | #version 450 |
| 2 | // Sprite fragment: a POI icon, sampled straight out of the RGBA sheet. |
| 3 | // |
| 4 | // Deliberately not `symbol.frag`. A glyph is a signed distance field that has to be |
| 5 | // thresholded, smoothed and haloed; an icon is already the picture. Sampling it through |
| 6 | // the SDF path would read its red channel as a distance and draw a smeared silhouette. |
| 7 | // |
| 8 | // Pairs with `symbol_billboard.vert` for POI icons (which billboard under tilt like the text |
| 9 | // beside them) and with `symbol.vert` for app markers (already resolved to clip space on the |
| 10 | // CPU). Same pipeline layout, same push block prefix, same descriptor set slot in both cases — |
| 11 | // only the bound atlas and this shader differ from the glyph path. |
| 12 | layout(location = 0) in vec2 inUv; |
| 13 | layout(location = 0) out vec4 outColor; |
| 14 | layout(push_constant) uniform Push { |
| 15 | mat4 tileToClip; |
| 16 | // rgb is the layer's TEXT colour and is deliberately unused here: the reference style |
| 17 | // sets no `icon-color`, so an icon draws in its own colours. Only `.a` is read, which |
| 18 | // carries the layer's opacity ramp. |
| 19 | vec4 color; |
| 20 | vec4 line; |
| 21 | vec4 misc; |
| 22 | } push; |
| 23 | layout(set = 0, binding = 0) uniform sampler2D atlas; |
| 24 | void main() { |
| 25 | vec4 texel = texture(atlas, inUv); |
| 26 | float alpha = texel.a * push.color.a; |
| 27 | // A sprite sheet is mostly empty space between icons, and the pipeline has no depth |
| 28 | // test, so discarding fully-transparent fragments is what keeps one icon's padding |
| 29 | // from blending over the label beside it. |
| 30 | if (alpha <= 0.001) discard; |
| 31 | // The sheet stores straight (unpremultiplied) alpha and the pipeline blends |
| 32 | // SRC_ALPHA / ONE_MINUS_SRC_ALPHA, so the colour must not be premultiplied here. |
| 33 | outColor = vec4(texel.rgb, alpha); |
| 34 | } |