make light pillars slowly light up

main
annieversary 2022-08-13 12:34:51 +01:00
parent 96453bfd49
commit 264eab0308
4 changed files with 33 additions and 15 deletions

View File

@ -18,7 +18,7 @@ fn fragment(
let uv = position.xy / vec2<f32>(view.width, view.height);
let uv = floor(uv * 400.0) / 400.0;
let col = texturesample(texture, our_sampler, uv);
let col = textureSample(texture, our_sampler, uv);
return round(col * 50.0) / 50.0;
}

View File

@ -1,6 +1,7 @@
#![allow(clippy::type_complexity)]
use bevy::{pbr::AmbientLight, prelude::*, sprite::Material2dPlugin, window::close_on_esc};
use bevy_mod_raycast::{DefaultRaycastingPlugin, RayCastMesh, RaycastSystem};
// use bevy_prototype_debug_lines::*;
mod camera;
mod columns;
@ -28,7 +29,6 @@ fn main() {
.insert_resource(Msaa { samples: 1 })
.insert_resource(ClearColor(Color::rgb(0.0, 0.0, 0.0)))
.add_plugins(DefaultPlugins)
// .add_plugin(DebugLinesPlugin::with_depth_test(true))
.add_plugin(Material2dPlugin::<PostProcessingMaterial>::default())
.init_resource::<Debug>()
.init_resource::<LightBallMaterials>()
@ -69,6 +69,7 @@ fn main() {
.with_system(light_up_ball_when_close_to_player)
.with_system(increase_progress_when_activating_pillar)
.with_system(activate_pillar_when_progress_is_1)
.with_system(increase_range_up_to_max)
.with_system(decrease_pillar_strength)
.with_system(update_light_excitation_state)
.with_system(toggle_debug),

View File

@ -1,11 +1,20 @@
use bevy::{pbr::CubemapVisibleEntities, prelude::*, render::primitives::CubemapFrusta};
use bevy::{
pbr::CubemapVisibleEntities,
prelude::*,
render::{primitives::CubemapFrusta, view::NoFrustumCulling},
};
use crate::{camera::MouseCoords, player::LightFriends};
// TODO maybe change these per pillar
const SIZE: f32 = 10.0;
const HEIGHT: f32 = 20.0;
/// duration of pillar activation, in secs
/// how many seconds a pillar lasts activated
const PILLAR_DURATION: f32 = 30.0;
/// the range for the pillar
const MAX_RANGE: f32 = 40.0;
const INTENSITY: f32 = 2000.0;
#[derive(Component)]
pub struct UnlitPillar;
@ -31,8 +40,11 @@ pub fn spawn_pillar(
transform: Transform::from_translation(pos),
..Default::default()
})
// idk what these do
.insert(CubemapFrusta::default())
.insert(CubemapVisibleEntities::default())
// we want the light to keep working even if it's out of the camera
.insert(NoFrustumCulling)
.insert(UnlitPillar);
}
@ -94,7 +106,8 @@ pub fn activate_pillar_when_progress_is_1(
})
.insert(PointLight {
color: Color::rgb(15.0, 15.0, 15.0),
intensity: 500.0,
range: 1.0,
intensity: INTENSITY,
..Default::default()
});
@ -104,17 +117,21 @@ pub fn activate_pillar_when_progress_is_1(
mat.emissive = Color::rgb(15.0, 15.0, 15.0);
}
}
} else {
if let Ok((handle, _)) = query.get(entity) {
if let Some(mat) = materials.get_mut(handle) {
mat.base_color = Color::rgb(15.0, 15.0, 15.0) * progress;
mat.emissive = Color::rgb(15.0, 15.0, 15.0) * progress;
}
} else if let Ok((handle, _)) = query.get(entity) {
if let Some(mat) = materials.get_mut(handle) {
mat.base_color = Color::rgb(15.0, 15.0, 15.0) * progress;
mat.emissive = Color::rgb(15.0, 15.0, 15.0) * progress;
}
}
}
}
pub fn increase_range_up_to_max(mut query: Query<&mut PointLight, With<LitPillar>>) {
for mut light in &mut query {
light.range += (MAX_RANGE - light.range) / MAX_RANGE;
}
}
pub fn decrease_pillar_strength(
mut commands: Commands,
mut query: Query<(
@ -144,7 +161,7 @@ pub fn decrease_pillar_strength(
mat.emissive = Color::rgb(0., 0., 0.);
}
} else {
light.intensity = i * 500.0;
light.intensity = i * INTENSITY;
if let Some(mat) = materials.get_mut(handle) {
mat.base_color = Color::rgb(15.0, 15.0, 15.0) * i.powf(1.3);

View File

@ -182,7 +182,7 @@ pub fn move_player(
mut animation_player: Query<&mut AnimationPlayer>,
mut is_walking: Local<bool>,
) {
let ds = time.delta_seconds() * 5.0;
let ds = time.delta_seconds() * 7.0;
let mut anim = if let Ok(player) = animation_player.get_single_mut() {
player
@ -207,7 +207,7 @@ pub fn move_player(
if !*is_walking && delta.length_squared() > 0.2 {
anim.play(animations.run.clone_weak()).repeat();
anim.set_speed(0.5);
anim.set_speed(0.7);
*is_walking = true;
}
if *is_walking && delta.length_squared() < 0.2 {