Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / library / map / src / main / rust / shaders / building.frag
building.frag35 lines · 1.7 KiBRaw
| 1 | #version 450 |
| 2 | |
| 3 | // Building fragment: flat per-face shading (WS-A). |
| 4 | // |
| 5 | // The face normal is constant across the triangle (the CPU gives all three vertices the same |
| 6 | // one), so lighting it against a single fixed direction gives every face one flat tone - the |
| 7 | // S3DB look, and no shadows. The colour is the per-vertex ARGB the wall/roof carries; blending |
| 8 | // is the pipeline's job, so it passes straight through with its own alpha. |
| 9 | layout(location = 0) in vec3 vNormal; |
| 10 | layout(location = 1) in vec4 vColor; |
| 11 | layout(push_constant) uniform Push { |
| 12 | mat4 tileToClip; |
| 13 | // The palette's building colour, for geometry the archive gave none. See below. |
| 14 | vec4 color; |
| 15 | vec4 line; |
| 16 | vec4 misc; |
| 17 | vec4 morph; |
| 18 | } push; |
| 19 | layout(location = 0) out vec4 outColor; |
| 20 | void main() { |
| 21 | vec3 n = normalize(vNormal); |
| 22 | // A fixed light from above and the north-west, in tile-local space (x east, y south, z up), |
| 23 | // so roofs read brightest and the walls facing away sit a shade darker. |
| 24 | vec3 lightDir = normalize(vec3(-0.4, -0.4, 1.0)); |
| 25 | float diffuse = max(dot(n, lightDir), 0.0); |
| 26 | // Generous ambient so a shadowed wall stays legible rather than going black. |
| 27 | float light = 0.55 + 0.45 * diffuse; |
| 28 | // Zero alpha is the tessellator's "this wall or roof has no colour of its own" marker (see |
| 29 | // `extrude_building`): fall back to the pushed palette colour. Vertex colour is baked when the |
| 30 | // tile is tessellated, where the palette is not known, so this is what lets a light/dark |
| 31 | // switch recolour untagged buildings without re-tessellating them. A building that carries an |
| 32 | // OSM `building:colour` has a real alpha and keeps it in both palettes. |
| 33 | vec4 base = vColor.a < 0.5 ? push.color : vColor; |
| 34 | outColor = vec4(base.rgb * light, base.a); |
| 35 | } |