aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-render/src
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-02 08:03:00 +0300
committerValentin Popov <valentin@popov.link>2026-12-02 08:03:00 +0300
commit9bb041a090dab428469647a203a57147a5d09c0b (patch)
tree5efbaba33e53c094fa6c0eaafd5c2f5b7bd15b72 /crates/fparkan-render/src
parente50b53e7a08d8b5e3393e477b890da95c4c8ef2a (diff)
downloadfparkan-9bb041a090dab428469647a203a57147a5d09c0b.tar.xz
fparkan-9bb041a090dab428469647a203a57147a5d09c0b.zip
fix(render): use the native lamps in the designer viewport
Use the pair of local directional lamps from iron3d.dll and convert their directions into the model coordinates as Terrain.dll does. Keep world point lights out of the model viewport. Verified the light vectors against the native setter and the assembled model in the stock Field Camp Vulkan window.
Diffstat (limited to 'crates/fparkan-render/src')
-rw-r--r--crates/fparkan-render/src/designer_lighting.rs51
-rw-r--r--crates/fparkan-render/src/lib.rs1
2 files changed, 52 insertions, 0 deletions
diff --git a/crates/fparkan-render/src/designer_lighting.rs b/crates/fparkan-render/src/designer_lighting.rs
new file mode 100644
index 00000000..7103f77b
--- /dev/null
+++ b/crates/fparkan-render/src/designer_lighting.rs
@@ -0,0 +1,51 @@
+//! The constructor's local lamps, evaluated in the unrotated model's coordinates.
+
+/// Elevation of the preview camera, equivalent to the original model pitch.
+pub const ELEVATION: f32 = 0.5;
+/// RGB of each original directional lamp.
+pub const LIGHT_RGB: [f32; 3] = [2.0; 3];
+
+/// Returns the two lamp directions with the inverse of the model's spin and pitch applied.
+#[must_use]
+pub fn light_directions(yaw: f64) -> [[f32; 3]; 2] {
+ let (sin_yaw, cos_yaw) = yaw.sin_cos();
+ let (sin_elevation, cos_elevation) = ELEVATION.sin_cos();
+ let diagonal = std::f32::consts::FRAC_1_SQRT_2;
+ // iron3d+0x9e780 supplies normalized (-1, 0, -1) and (1, 0, -1).
+ [-diagonal, diagonal].map(|x| {
+ let tilted_x = cos_elevation * x - sin_elevation * diagonal;
+ let z = -sin_elevation * x - cos_elevation * diagonal;
+ [tilted_x * cos_yaw as f32, -tilted_x * sin_yaw as f32, z]
+ })
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn lamps_match_the_native_light_setter_before_and_after_rotation() {
+ // Terrain.dll+0x4c4d0 with the preview's mode-2 transform.
+ for (yaw, expected) in [
+ (
+ 0.0,
+ [[-0.959550, 0.0, -0.281539], [0.281539, 0.0, -0.959550]],
+ ),
+ (
+ 0.75,
+ [
+ [-0.702092, 0.654066, -0.281539],
+ [0.205999, -0.191908, -0.959550],
+ ],
+ ),
+ ] {
+ for (actual, expected) in light_directions(yaw)
+ .into_iter()
+ .flatten()
+ .zip(expected.into_iter().flatten())
+ {
+ assert!((actual - expected).abs() < 1.0e-6, "{actual} != {expected}");
+ }
+ }
+ }
+}
diff --git a/crates/fparkan-render/src/lib.rs b/crates/fparkan-render/src/lib.rs
index 645cb25d..2c239061 100644
--- a/crates/fparkan-render/src/lib.rs
+++ b/crates/fparkan-render/src/lib.rs
@@ -3,6 +3,7 @@
pub mod cockpit_course;
pub mod cockpit_radar;
+pub mod designer_lighting;
pub mod water;
/// A 64-byte transform block returned by the original Terrain camera ABI.