diff options
| author | Valentin Popov <valentin@popov.link> | 2026-12-02 20:55:24 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-12-02 20:55:24 +0300 |
| commit | bd3fbb71cdef1cda0e4db5efa14c632ae72859d6 (patch) | |
| tree | 610ba427410fcabdb59e80dcf26bf430852d5d08 /crates/fparkan-render | |
| parent | f35ccda5dd88cb0ddebed33efa2660c1b9742cbe (diff) | |
| download | fparkan-bd3fbb71cdef1cda0e4db5efa14c632ae72859d6.tar.xz fparkan-bd3fbb71cdef1cda0e4db5efa14c632ae72859d6.zip | |
fix(ui): restore native cockpit miniature lighting
Diffstat (limited to 'crates/fparkan-render')
| -rw-r--r-- | crates/fparkan-render/src/cockpit_lighting.rs | 35 | ||||
| -rw-r--r-- | crates/fparkan-render/src/lib.rs | 1 |
2 files changed, 36 insertions, 0 deletions
diff --git a/crates/fparkan-render/src/cockpit_lighting.rs b/crates/fparkan-render/src/cockpit_lighting.rs new file mode 100644 index 00000000..fa87397d --- /dev/null +++ b/crates/fparkan-render/src/cockpit_lighting.rs @@ -0,0 +1,35 @@ +//! Lighting used by the two cockpit model views. + +use crate::LegacyIron3dEulerTransform; + +/// Additive RGB supplied by the cockpit camera in Terrain's color-only mode. +pub const CAMERA_ADDITIVE: [f32; 3] = [0.0, 0.5, 0.0]; +/// Per-channel floor used by CShade for the miniature. +pub const LIGHTING_FLOOR: [f32; 3] = [40.0 / 255.0; 3]; + +/// World direction and intensity of the local lamps, preserving the repeated pair +/// and the original direction lengths. +pub fn lamps(orientation_radians: [f32; 3]) -> Option<[([f32; 3], f32); 4]> { + let orientation = LegacyIron3dEulerTransform { + translation: [0.0; 3], + orientation_radians, + }; + // Terrain+0x2e4a0 receives both copies of the owner-local light pair. + let direction = orientation.try_transform_scaled_point([-1.0, 1.0, -1.0], [1.0; 3])?; + let primary = (direction, 0.25); + let fill = (direction.map(|axis| -axis), 0.25 * 0.35); + Some([primary, fill, primary, fill]) +} + +#[cfg(test)] +#[test] +fn lamps_follow_the_model_and_keep_the_native_direction_length() { + let hero = lamps([0.0; 3]).unwrap(); + let primary = ([-1.0, 1.0, -1.0], 0.25); + let fill = ([1.0, -1.0, 1.0], 0.0875); + assert_eq!(hero, [primary, fill, primary, fill]); + let bunker = lamps([0.0, 0.0, -1.6734]).unwrap(); + for (actual, expected) in bunker[0].0.into_iter().zip([1.097175, 0.892305, -1.0]) { + assert!((actual - expected).abs() < 0.0002); + } +} diff --git a/crates/fparkan-render/src/lib.rs b/crates/fparkan-render/src/lib.rs index 2c239061..8eaab4f9 100644 --- a/crates/fparkan-render/src/lib.rs +++ b/crates/fparkan-render/src/lib.rs @@ -2,6 +2,7 @@ //! Camera mathematics and graphics pipeline state. pub mod cockpit_course; +pub mod cockpit_lighting; pub mod cockpit_radar; pub mod designer_lighting; pub mod water; |
