Light tweaks working

main
Elijah C. Voigt 2 years ago
parent 90a33be8be
commit 31041be37c

@ -71,6 +71,7 @@ intro_a = "GameCamIntro1"
intro_b = "GameCamIntro2" intro_b = "GameCamIntro2"
turn_a = "GameCamSide2>1" turn_a = "GameCamSide2>1"
turn_b = "GameCamSide1>2" turn_b = "GameCamSide1>2"
[display3d.models.animations.pick_up] [display3d.models.animations.pick_up]
pawn = "PawnPiecePickup" pawn = "PawnPiecePickup"
drone = "DronePiecePickup" drone = "DronePiecePickup"
@ -96,13 +97,13 @@ pawn_blue = "DroneBlue"
dots_red = "Dots" dots_red = "Dots"
dots_blue = "DotsBlue" dots_blue = "DotsBlue"
[display3d.lights] [display3d.lights.scaling]
# https://docs.rs/bevy/0.11.3/bevy/pbr/struct.SpotLight.html # https://docs.rs/bevy/0.11.3/bevy/pbr/struct.SpotLight.html
spot_light_scale = 1.0 spot = 1.0
# https://docs.rs/bevy/0.11.3/bevy/pbr/struct.PointLight.html # https://docs.rs/bevy/0.11.3/bevy/pbr/struct.PointLight.html
point_light_scale = 1.0 point = 0.01
# https://docs.rs/bevy/0.11.3/bevy/pbr/struct.DirectionalLight.html # https://docs.rs/bevy/0.11.3/bevy/pbr/struct.DirectionalLight.html
directional_light_scale = 1.0 directional = 1.0
### ###
# Fog # Fog

BIN
assets/models/Martian Chess.glb (Stored with Git LFS)

Binary file not shown.

@ -95,7 +95,7 @@ fn init_debug_ui(mut commands: Commands) {
padding: UiRect::all(Val::Px(10.0)), padding: UiRect::all(Val::Px(10.0)),
..default() ..default()
}, },
background_color: Color::BLACK.with_a(0.6).into(), background_color: Color::BLACK.into(),
visibility: Visibility::Hidden, visibility: Visibility::Hidden,
..default() ..default()
}, },

@ -57,6 +57,12 @@ impl Plugin for Display3dPlugin {
remove_valid_move_entity.run_if(any_component_removed::<game::Selected>()), remove_valid_move_entity.run_if(any_component_removed::<game::Selected>()),
set_valid_move_model.run_if(any_component_added::<game::ValidMove>), set_valid_move_model.run_if(any_component_added::<game::ValidMove>),
update_tweaks.run_if(on_event::<AssetEvent<Tweaks>>()), update_tweaks.run_if(on_event::<AssetEvent<Tweaks>>()),
scale_lighting.run_if(
any_component_added::<DirectionalLight>
.or_else(any_component_added::<SpotLight>)
.or_else(any_component_added::<PointLight>)
.or_else(on_event::<AssetEvent<Tweaks>>())
),
), ),
) )
.add_systems( .add_systems(
@ -1005,6 +1011,52 @@ fn switch_sides(
}); });
} }
fn scale_lighting(
mut directional: Query<(Entity, &mut DirectionalLight, Option<&Original<DirectionalLight>>)>,
mut spot: Query<(Entity, &mut SpotLight, Option<&Original<SpotLight>>)>,
mut point: Query<(Entity, &mut PointLight, Option<&Original<PointLight>>)>,
mut commands: Commands,
tweaks: Res<Assets<Tweaks>>,
tweaks_file: Res<tweak::GameTweaks>,
) {
let tweak = tweaks
.get(tweaks_file.handle.clone())
.expect("Load tweakfile");
let directional_tweak = tweak.get::<f32>("display3d_lights_scaling_directional").expect("Directional lighting scalar");
directional.iter_mut().for_each(|(entity, mut val, original)| {
info!("Scaling directional light {:?}", entity);
if let Some(Original(v)) = original {
val.illuminance = v.illuminance * directional_tweak;
} else {
commands.entity(entity).insert(Original(val.clone()));
val.illuminance *= directional_tweak;
}
});
let spot_tweak = tweak.get::<f32>("display3d_lights_scaling_spot").expect("Spot lighting scalar");
spot.iter_mut().for_each(|(entity, mut val, original)| {
info!("Scaling spot light {:?}", entity);
if let Some(Original(v)) = original {
val.intensity = v.intensity * spot_tweak;
} else {
commands.entity(entity).insert(Original(val.clone()));
val.intensity *= spot_tweak;
}
});
let point_tweak = tweak.get::<f32>("display3d_lights_scaling_point").expect("Point lighting scalar");
point.iter_mut().for_each(|(entity, mut val, original)| {
info!("Scaling point light {:?}", entity);
if let Some(Original(v)) = original {
val.intensity = v.intensity * point_tweak;
} else {
commands.entity(entity).insert(Original(val.clone()));
val.intensity *= point_tweak;
}
});
}
pub(super) mod tweaks { pub(super) mod tweaks {
use bevy::{ use bevy::{
core_pipeline::tonemapping::Tonemapping, core_pipeline::tonemapping::Tonemapping,

@ -131,3 +131,7 @@ pub(crate) fn _any_component_added_or_changed<C: Component>(
) -> bool { ) -> bool {
!q.is_empty() !q.is_empty()
} }
/// Stores the original value of a component which is modified at runtime
#[derive(Debug, Component)]
pub(crate) struct Original<T: Component>(T);
Loading…
Cancel
Save