library: globe space is black (dark) / white (light), not ocean (#maprender)
- Commit
de779a66eeff34ae02a809631dc32694b9ef2a2e- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-13 20:05 UTC (22 days ago)
- Parents
2648d99
Owner report: "For globe mode, space should be black (or white in light mode) instead of being ocean colored." Root cause: every frame cleared to `style::background`, which is the water colour by design (an unloaded flat map should read as sea). On globe frames that same clear filled the area outside the sphere, so the planet's limb dissolved into an ocean-coloured void. What changed: - `style::space(variant)`: 0xFF000000 in the dark palette, 0xFFFFFFFF in the light one. A fixed colour, not a style entry: space is not part of the map, and muting it would only soften the limb. - `style::clear_color(camera, variant)`: space while the globe is active and leaves part of the viewport uncovered, water otherwise. The frame bridge clears with it (Earth and Moon frames alike). - `Camera::globe_covers_viewport`: the disc is centred with radius `globe_radius`, so it covers the screen exactly when the half-diagonal fits inside it. - `Renderer::record_globe_backdrop` (new `record_globe.rs`): the sea on the ball used to come for free from the water clear, so it is now one analytic disc of the globe's screen radius in the water colour, drawn first in the pass under every globe tile. It reuses the puck pipeline (its shader already draws an antialiased disc of a pushed px radius) and the shared unit quad, so it costs one push constant and one draw, no new shader or geometry. When the sphere covers the viewport the frame clears straight to water and the disc is skipped, so a zoomed-in globe and the flat map pay exactly what they did before. User-visible: zoomed-out globe floats on black (dark theme) or white (light theme); oceans on the globe are unchanged; the flat map is byte-identical (flat frames never take the new branch). Verified: new host tests pin space colours, the covered/uncovered switch and that flat/zoomed-in globe frames keep the water clear (`cargo test -p map_renderer --lib globe`: 14 passed); the android target type-checks (`cargo check --target aarch64-linux-android`).
Diff
library/map/src/main/rust/src/bridge/frame.rs
diff --git a/library/map/src/main/rust/src/bridge/frame.rs b/library/map/src/main/rust/src/bridge/frame.rsindex b0ac2aa76e..44e740d543 100644--- a/library/map/src/main/rust/src/bridge/frame.rs+++ b/library/map/src/main/rust/src/bridge/frame.rs@@ -335,7 +335,8 @@ pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_render<'l>( &camera, &map.layers, map.palette,- style::background(map.palette.variant),+ // Globe frames with space around the ball clear to space (black/white), not sea.+ style::clear_color(&camera, map.palette.variant), &kinds, ); // The JNI-entry sample closes here: it covers drain + select + render, which is the whole
library/map/src/main/rust/src/camera_globe.rs
diff --git a/library/map/src/main/rust/src/camera_globe.rs b/library/map/src/main/rust/src/camera_globe.rsindex d3cf9b4d4d..4859a1d303 100644--- a/library/map/src/main/rust/src/camera_globe.rs+++ b/library/map/src/main/rust/src/camera_globe.rs@@ -75,4 +75,16 @@ impl Camera { self.height_dp as f64 / 2.0 - y * r, )) }++ /// Whether the globe disc covers the whole viewport, corners included.+ ///+ /// The disc is centred on the viewport with radius [`globe_radius`](crate::camera::globe_radius),+ /// so it covers everything exactly when the half-diagonal fits inside it. While it does,+ /// no space shows around the ball and the frame can clear straight to water.+ pub fn globe_covers_viewport(&self) -> bool {+ let r = crate::camera::globe_radius(self.zoom, self.center_lat);+ let hw = self.width_dp as f64 / 2.0;+ let hh = self.height_dp as f64 / 2.0;+ hw * hw + hh * hh <= r * r+ } }
library/map/src/main/rust/src/camera_globe_tests.rs
diff --git a/library/map/src/main/rust/src/camera_globe_tests.rs b/library/map/src/main/rust/src/camera_globe_tests.rsindex c01cace1d1..5befbc953f 100644--- a/library/map/src/main/rust/src/camera_globe_tests.rs+++ b/library/map/src/main/rust/src/camera_globe_tests.rs@@ -193,4 +193,36 @@ mod tests { assert!((sx_dp - 256.0).abs() < 1e-9, "sx {sx_dp}"); assert!((sy_dp - 256.0).abs() < 1e-9, "sy {sy_dp}"); }++ #[test]+ fn a_zoomed_out_globe_leaves_space_around_it_and_a_zoomed_in_one_does_not() {+ // z0 on a 512 dp square: the radius is half the 512 dp world, so the limb touches the+ // edges' midpoints and the corners are space.+ assert!(!globe_camera(0.0, 0.0, 0.0).globe_covers_viewport());+ // z3: radius 2048 dp, far past the 362 dp half-diagonal.+ assert!(globe_camera(0.0, 0.0, 3.0).globe_covers_viewport());+ }++ #[test]+ fn space_is_black_in_dark_and_white_in_light_and_only_on_an_uncovered_globe() {+ use crate::style::{background, clear_color, space, Variant};+ assert_eq!(space(Variant::Dark), 0xFF00_0000);+ assert_eq!(space(Variant::Light), 0xFFFF_FFFF);+ for variant in [Variant::Light, Variant::Dark] {+ // Globe with space visible: clears to space, never to the sea.+ let out = globe_camera(0.0, 0.0, 0.0);+ assert_eq!(clear_color(&out, variant), space(variant));+ assert_ne!(clear_color(&out, variant), background(variant));+ // Globe filling the screen: no space visible, so water exactly as before.+ assert_eq!(clear_color(&globe_camera(0.0, 0.0, 4.0), variant), background(variant));+ // Flat map (globe off, or past the flat threshold): unchanged water clear.+ let mut flat = globe_camera(0.0, 0.0, 0.0);+ flat.globe = false;+ assert_eq!(clear_color(&flat, variant), background(variant));+ assert_eq!(+ clear_color(&globe_camera(0.0, 0.0, GLOBE_FLAT_THRESHOLD + 1.0), variant),+ background(variant)+ );+ }+ } }
library/map/src/main/rust/src/style/mod.rs
diff --git a/library/map/src/main/rust/src/style/mod.rs b/library/map/src/main/rust/src/style/mod.rsindex 1aa8db5051..74661be274 100644--- a/library/map/src/main/rust/src/style/mod.rs+++ b/library/map/src/main/rust/src/style/mod.rs@@ -69,7 +69,8 @@ pub use self::layer::{kind_id, Layer}; #[cfg(test)] pub use self::palette::layers_with_lane_rendering; pub use self::palette::{- background, layers, road_carriageway_layer, Palette, LANE_RENDERING, MUTED_BLEND,+ background, clear_color, layers, road_carriageway_layer, space, Palette, LANE_RENDERING,+ MUTED_BLEND, }; // Private: restores the original `fn detail_id`'s scope (visible to `style` and its // children, e.g. `paint` via `super::detail_id`) without widening it crate-wide.
library/map/src/main/rust/src/style/palette.rs
diff --git a/library/map/src/main/rust/src/style/palette.rs b/library/map/src/main/rust/src/style/palette.rsindex e27be41848..e8747c7cd3 100644--- a/library/map/src/main/rust/src/style/palette.rs+++ b/library/map/src/main/rust/src/style/palette.rs@@ -45,6 +45,35 @@ pub fn background(variant: Variant) -> u32 { } } +/// The empty space around the globe: pure black in the dark palette, pure white in the light.+///+/// The globe is a ball floating in space, so what surrounds it must not read as sea. It used+/// to: the frame cleared to [`background`] (water) on globe frames too, so the area outside+/// the sphere was ocean-coloured and the planet's edge dissolved into it. Space is a fixed+/// colour rather than a style entry — it is not part of the map, and muting it would only+/// make the limb harder to see. The globe's own ocean is drawn as a disc in [`background`]+/// (see `Renderer::record_globe_backdrop`), so the sea on the ball is unchanged.+pub fn space(variant: Variant) -> u32 {+ match variant {+ Variant::Light => 0xFFFF_FFFF,+ Variant::Dark => 0xFF00_0000,+ }+}++/// The colour a frame clears to: [`space`] when the globe leaves part of the viewport+/// uncovered, [`background`] (water) otherwise.+///+/// When the sphere covers every corner (zoomed in past the point where its limb leaves the+/// screen) there is no space visible at all, so the frame clears straight to water and the+/// renderer skips the ocean disc — the zoomed-in globe pays exactly what the flat map does.+pub fn clear_color(camera: &crate::camera::Camera, variant: Variant) -> u32 {+ if crate::camera::globe_active(camera) && !camera.globe_covers_viewport() {+ space(variant)+ } else {+ background(variant)+ }+}+ /// Whether the lane-level road rendering is built and drawn at all. /// /// The one switch for the whole feature set: the `roads-carriageway` asphalt surface and its
library/map/src/main/rust/src/vulkan/renderer/mod.rs
diff --git a/library/map/src/main/rust/src/vulkan/renderer/mod.rs b/library/map/src/main/rust/src/vulkan/renderer/mod.rsindex 53477eeb41..be3dcbcf0c 100644--- a/library/map/src/main/rust/src/vulkan/renderer/mod.rs+++ b/library/map/src/main/rust/src/vulkan/renderer/mod.rs@@ -26,6 +26,7 @@ mod record_extra; mod record_extra2; mod record_extra3; mod record_extra4;+mod record_globe; mod record_markers; mod record_moon; mod record_symbol;
library/map/src/main/rust/src/vulkan/renderer/record.rs
diff --git a/library/map/src/main/rust/src/vulkan/renderer/record.rs b/library/map/src/main/rust/src/vulkan/renderer/record.rsindex 8a96f002f6..377a514049 100644--- a/library/map/src/main/rust/src/vulkan/renderer/record.rs+++ b/library/map/src/main/rust/src/vulkan/renderer/record.rs@@ -96,6 +96,9 @@ impl Renderer { // without reordering any draw): every pass below binds through this instead of // issuing raw binds, so repeated binds of the same state collapse to one. let mut binds = BindState::new();+ // Globe frames clear to space; the sea on the ball is this disc (`record_globe.rs`).+ let ocean = crate::style::background(palette.variant);+ self.record_globe_backdrop(command_buffer, camera, ocean, &mut binds, &mut submitted); // One tile-layer's draws, reused across the whole frame — and across frames: the // buffer lives on the renderer (`scratch_draws`) and is only cleared per tile below, // so a frame pays no allocation for it. Each draw carries its pool's bind offsets
library/map/src/main/rust/src/vulkan/renderer/record_globe.rs
diff --git a/library/map/src/main/rust/src/vulkan/renderer/record_globe.rs b/library/map/src/main/rust/src/vulkan/renderer/record_globe.rsnew file mode 100644index 0000000000..7d4e034f0e--- /dev/null+++ b/library/map/src/main/rust/src/vulkan/renderer/record_globe.rs@@ -0,0 +1,73 @@+//! The globe's ocean disc: the sea on the ball, drawn over the space-coloured clear.+//!+//! Split from `record.rs` (file-length limit). Globe frames clear to+//! [`style::space`](crate::style::space) — black in the dark palette, white in the light —+//! so the area outside the sphere reads as space rather than sea. The sphere itself still+//! needs the sea underneath its land, which the flat map gets for free from its water-blue+//! clear; this pass paints exactly that, as one analytic disc of the globe's screen radius.+//!+//! It reuses the user-puck pipeline and the shared unit quad: the puck shader already draws+//! an antialiased disc of a pushed pixel radius, so the sea costs one push constant and one+//! draw, no new shader and no geometry. When the sphere covers the whole viewport the frame+//! clears straight to water instead (see [`style::clear_color`](crate::style::clear_color))+//! and this draws nothing.+use super::bind_state::BindState;+use super::{argb_to_rgba, Renderer, QUAD_INDICES};+use crate::camera::Camera;+use crate::vulkan::pipeline::{Push, MORPH_NONE};+use ash::vk;++/// Extra quad margin past the disc edge, in Dp, so the shader's one-pixel edge falloff is not+/// clipped by the quad itself.+const EDGE_MARGIN_DP: f64 = 2.0;++impl Renderer {+ /// Draw the ocean disc under a globe frame that leaves space visible; no-op otherwise.+ ///+ /// Issued first in the pass, before any tile draw, so every globe fill/line lands on top+ /// of it exactly as the flat map's layers land on the water-blue clear.+ pub(super) unsafe fn record_globe_backdrop(+ &self,+ command_buffer: vk::CommandBuffer,+ camera: &Camera,+ ocean: u32,+ binds: &mut BindState,+ submitted: &mut usize,+ ) {+ if !crate::camera::globe_active(camera) || camera.globe_covers_viewport() {+ return;+ }+ let radius_dp = crate::camera::globe_radius(camera.zoom, camera.center_lat);+ let quad_dp = radius_dp + EDGE_MARGIN_DP;+ let density = camera.density;+ let matrix = super::placement::globe_screen_quad(+ camera,+ camera.width_dp as f64 / 2.0,+ camera.height_dp as f64 / 2.0,+ quad_dp,+ );+ let push = Push {+ tile_to_clip: matrix,+ color: argb_to_rgba(ocean),+ // Rim radius below zero: the puck shader's white rim contributes nothing, so the+ // disc is the core alone, in the ocean colour.+ line: [-1.0, (radius_dp as f32) * density, 0.0, 0.0],+ // No bearing cone; the quad radius in device px converts the local -1..1 to px.+ misc: [0.0, 0.0, (quad_dp as f32) * density, camera.time_seconds],+ morph: MORPH_NONE,+ };+ let device = &self.context.device;+ binds.bind_pipeline(device, command_buffer, self.pipelines.puck);+ device.cmd_push_constants(+ command_buffer,+ self.pipelines.layout,+ vk::ShaderStageFlags::VERTEX | vk::ShaderStageFlags::FRAGMENT,+ 0,+ push.as_bytes(),+ );+ device.cmd_bind_vertex_buffers(command_buffer, 0, &[self.quad.vertices.buffer], &[0]);+ device.cmd_bind_index_buffer(command_buffer, self.quad.indices.buffer, 0, vk::IndexType::UINT32);+ device.cmd_draw_indexed(command_buffer, QUAD_INDICES.len() as u32, 1, 0, 0, 0);+ *submitted += 1;+ }+}