Light tweaks working

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

@ -71,6 +71,7 @@ intro_a = "GameCamIntro1"
intro_b = "GameCamIntro2"
turn_a = "GameCamSide2>1"
turn_b = "GameCamSide1>2"
[display3d.models.animations.pick_up]
pawn = "PawnPiecePickup"
drone = "DronePiecePickup"
@ -96,13 +97,13 @@ pawn_blue = "DroneBlue"
dots_red = "Dots"
dots_blue = "DotsBlue"
[display3d.lights]
[display3d.lights.scaling]
# 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
point_light_scale = 1.0
point = 0.01
# https://docs.rs/bevy/0.11.3/bevy/pbr/struct.DirectionalLight.html
directional_light_scale = 1.0
directional = 1.0
###
# 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)),
..default()
},
background_color: Color::BLACK.with_a(0.6).into(),
background_color: Color::BLACK.into(),
visibility: Visibility::Hidden,
..default()
},

@ -57,6 +57,12 @@ impl Plugin for Display3dPlugin {
remove_valid_move_entity.run_if(any_component_removed::<game::Selected>()),
set_valid_move_model.run_if(any_component_added::<game::ValidMove>),
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(
@ -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 {
use bevy::{
core_pipeline::tonemapping::Tonemapping,

@ -131,3 +131,7 @@ pub(crate) fn _any_component_added_or_changed<C: Component>(
) -> bool {
!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