diff options
Diffstat (limited to 'apps/fparkan-game/src/cockpit_instrument.rs')
| -rw-r--r-- | apps/fparkan-game/src/cockpit_instrument.rs | 84 |
1 files changed, 55 insertions, 29 deletions
diff --git a/apps/fparkan-game/src/cockpit_instrument.rs b/apps/fparkan-game/src/cockpit_instrument.rs index 400f3a7d..bf7485a3 100644 --- a/apps/fparkan-game/src/cockpit_instrument.rs +++ b/apps/fparkan-game/src/cockpit_instrument.rs @@ -1,16 +1,17 @@ //! The cockpit instruments use live unit meshes and the original HUD resources. use super::{ - append_environment_gradient_material, append_static_preview_component, - clip_from_world_for_view, cross3, live_root_pose, + append_static_preview_component, clip_from_world_for_view, cross3, live_root_pose, mission_overlay::{add_overlay_sprite, overlay_texture}, - native_msh_cull_mode, native_msh_handedness, normalize3, scale3, sub3, DirectoryVfs, - EnvironmentGpuRange, LegacyBlendMode, LegacyDepthMode, LegacyIron3dEulerTransform, ModelAsset, - NodePoseBuffer, StaticPreviewScene, VulkanNodePose, VulkanSmokeRenderer, VulkanStaticCamera, - VulkanStaticMesh, WorldSnapshot, + native_msh_cull_mode, native_msh_handedness, normalize3, scale3, + static_preview_component_materials, sub3, DirectoryVfs, EnvironmentGpuRange, LegacyBlendMode, + LegacyDepthMode, LegacyIron3dEulerTransform, ModelAsset, ModelMaterialStyle, NodePoseBuffer, + StaticPreviewScene, VulkanNodePose, VulkanSmokeRenderer, VulkanStaticCamera, VulkanStaticMesh, + WorldSnapshot, }; use fparkan_assets::cockpit_instrument::{Images, Readout, Side}; use fparkan_platform_winit::text::StringResources; +use fparkan_render::cockpit_lighting::{lamps, LIGHTING_FLOOR}; use fparkan_render_vulkan::{ project_instrument_msh, VulkanDirectionalLight, VulkanModelPreview, VULKAN_DIRECTIONAL_LIGHT_COUNT, @@ -20,7 +21,7 @@ use fparkan_runtime::{ instrument_bounds, instrument_distance, instrument_readout, instrument_sphere, InstrumentReadout, InstrumentStatus, }, - Engine, StartingCockpit, + loaded_mission_assets, Engine, StartingCockpit, }; use fparkan_world::{ObjectHandle, TransformState}; use std::{ops::Range, path::Path, sync::Arc}; @@ -77,13 +78,7 @@ impl CockpitInstrument { Panel::load(scene, &images, Side::Left)?, Panel::load(scene, &images, Side::Right)?, ]; - let material = append_environment_gradient_material(&mut scene.materials)?; - let shading = &mut scene.materials[material]; - shading.sky_far_depth = false; - shading.unlit = false; - shading.additive_rgb = [0.52, 0.84, 0.39]; - shading.directional_rgb = [0.22, 0.16, 0.21]; - let material = shading.material_index; + let assets = loaded_mission_assets(engine).ok_or("instrument has no mission assets")?; let mut models = Vec::with_capacity(scene.dynamic_component_geometry.len()); for (object, components) in scene.dynamic_component_geometry.iter().enumerate() { let start = scene.mesh.draw_ranges.len(); @@ -106,19 +101,32 @@ impl CockpitInstrument { native_msh_handedness(component.root_transform, component.owner_scale); for range in &mut mesh.draw_ranges { range.lightmap_index = u8::MAX; - range.material_index = material; range.pipeline_state.blend = LegacyBlendMode::Opaque; range.pipeline_state.depth = LegacyDepthMode::TestWrite; range.pipeline_state.alpha_test = false; range.pipeline_state.cull = native_msh_cull_mode(range.batch_flags, handedness); counts.push(range.index_count); } + let visuals = assets.visuals_for_object(object); + let visual = visuals + .get(index) + .and_then(|&id| assets.visual_by_id(id)) + .ok_or_else(|| format!("instrument has no visual for {object}:{index}"))?; + let selectors = static_preview_component_materials( + assets, + visual, + &mesh, + None, + &mut scene.materials, + &mut scene.material_animations, + ModelMaterialStyle::Instrument, + )?; let first = scene.mesh.vertices.len(); append_static_preview_component( &mut scene.mesh, mesh, - &[(material, material)], - None, + &selectors, + Some(&mut scene.material_animations), )?; projected.push(ModelComponent { index, @@ -197,6 +205,7 @@ impl CockpitInstrument { let (center, radius) = subject_sphere?; let pose = live_root_pose(subject, snapshot)?; model_pose = Some(pose); + let orientation_radians = pose.orientation.map(f32::from_bits); let forward = if observing { let (origin, _) = observer?; let mut offset = sub3(center, origin); @@ -210,13 +219,17 @@ impl CockpitInstrument { } else { let orientation = LegacyIron3dEulerTransform { translation: [0.0; 3], - orientation_radians: pose.orientation.map(f32::from_bits), + orientation_radians, }; orientation.try_transform_scaled_point([0.0, 1.0, 0.0], [1.0; 3])? }; - self.models - .get(unit.object_index)? - .view(panel.side, center, radius, forward) + self.models.get(unit.object_index)?.view( + panel.side, + center, + radius, + forward, + orientation_radians, + ) })(); if views[index].is_some() { active[index] = Some(unit.object_index); @@ -369,6 +382,7 @@ impl Model { center: [f32; 3], radius: f32, forward: [f32; 3], + orientation_radians: [f32; 3], ) -> Option<VulkanModelPreview> { let near = 0.5; let far = 300.0; @@ -400,12 +414,16 @@ impl Model { ), }; let mut lights = [VulkanDirectionalLight::default(); VULKAN_DIRECTIONAL_LIGHT_COUNT]; - lights[0] = VulkanDirectionalLight { - direction: [0.0, 0.0, -1.0], - rgb: [1.0; 3], - active: true, - ..VulkanDirectionalLight::default() - }; + for (light, (direction, intensity)) in lights.iter_mut().zip(lamps(orientation_radians)?) { + *light = VulkanDirectionalLight { + direction, + rgb: [intensity; 3], + active: true, + specular_enabled: false, + preserve_direction_length: true, + ..VulkanDirectionalLight::default() + }; + } Some(VulkanModelPreview { ranges: self.ranges.clone(), draw_before: None, @@ -413,13 +431,14 @@ impl Model { camera, eye, lights, + lighting_floor: Some(LIGHTING_FLOOR), }) } } #[cfg(test)] #[test] -fn targeter_projection_uses_the_original_focal_scale_on_both_axes() { +fn targeter_projection_and_lighting_are_shared_by_both_panels() { let model = Model { bounds: None, ranges: 0..1, @@ -427,10 +446,17 @@ fn targeter_projection_uses_the_original_focal_scale_on_both_axes() { components: Vec::new(), }; for side in [Side::Left, Side::Right] { - let view = model.view(side, [0.0; 3], 2.0, [0.0, 1.0, 0.0]).unwrap(); + let view = model + .view(side, [0.0; 3], 2.0, [0.0, 1.0, 0.0], [0.0; 3]) + .unwrap(); let matrix = view.camera.clip_from_world; let focal = 1.303_225_4; assert!((matrix[0] - focal).abs() < 1e-6); assert!((matrix[9] + focal).abs() < 1e-6); + assert!(view + .lights + .iter() + .all(|light| light.active && !light.specular_enabled)); + assert_eq!(view.lighting_floor, Some(LIGHTING_FLOOR)); } } |
