Skip to content

Commit

Permalink
Shadow fix fow wasm and safe area get center logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ayamaev-se committed Dec 6, 2023
1 parent 9041dea commit 9b0d635
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 38 deletions.
2 changes: 1 addition & 1 deletion assets/shaders/sprite_prepass.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ fn fragment(
out.motion_vector = pbr_prepass_functions::calculate_motion_vector(in.world_position, in.previous_world_position);
#endif

if textureSample(base_teture, base_teture_sampler, in.uv).a < 0.5 { discard; };
if textureSample(base_teture, base_teture_sampler, in.uv).a != 1.0 { discard; };

return out;
}
56 changes: 29 additions & 27 deletions src/debug_diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ impl Plugin for DiagnosticPlugin {
fn build(&self, app: &mut App) {
app.add_systems(
Startup,
(setup_diagnostic_panel, apply_deferred, setup_counter, setup_sheep_counter).chain(),
(
setup_diagnostic_panel,
apply_deferred,
setup_counter,
setup_sheep_counter,
)
.chain(),
)
.add_systems(Update, (
fps_counting,
sheep_counter_text,
))
.add_systems(Update, (fps_counting, sheep_counter_text))
.add_plugins(bevy_inspector_egui::quick::WorldInspectorPlugin::default());
}
}
Expand All @@ -24,23 +27,25 @@ impl Plugin for DiagnosticPlugin {
pub struct DiagnosticPanel;

pub fn setup_diagnostic_panel(mut commands: Commands) {
commands.spawn(NodeBundle {
style: Style {
top: Val::Px(0.0),
left: Val::Px(0.0),
width: Val::Px(200.0),
position_type: PositionType::Absolute,
flex_direction: FlexDirection::Column,
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,

align_self: AlignSelf::Stretch,

commands
.spawn(NodeBundle {
style: Style {
top: Val::Px(0.0),
left: Val::Px(0.0),
width: Val::Px(200.0),
position_type: PositionType::Absolute,
flex_direction: FlexDirection::Column,
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,

align_self: AlignSelf::Stretch,

..default()
},
background_color: BackgroundColor(Color::rgba(0.0, 0.0, 0.0, 0.5)),
..default()
},
background_color: BackgroundColor(Color::rgba(0.0, 0.0, 0.0, 0.5)),
..default()
}).insert(DiagnosticPanel);
})
.insert(DiagnosticPanel);
}

#[derive(Component)]
Expand Down Expand Up @@ -69,10 +74,7 @@ fn fps_counting(mut query: Query<&mut Text, With<FrameCounter>>, time: Res<Time>
#[derive(Component)]
pub struct ShipDebugCounter;

pub fn setup_sheep_counter(
mut commands: Commands,
panels: Query<Entity, With<DiagnosticPanel>>,
) {
pub fn setup_sheep_counter(mut commands: Commands, panels: Query<Entity, With<DiagnosticPanel>>) {
let mut text_style = TextStyle::default();
text_style.font_size = FONT_SIZE;
let sheep_counter = commands
Expand All @@ -87,9 +89,9 @@ pub fn setup_sheep_counter(

pub fn sheep_counter_text(
mut query: Query<&mut Text, With<ShipDebugCounter>>,
sheep_counter : Res<SheepCounter>,
sheep_counter: Res<SheepCounter>,
) {
for mut text in &mut query {
text.sections[0].value = format!("Sheep in safe area: {}", sheep_counter.count);
}
}
}
2 changes: 1 addition & 1 deletion src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ fn camera_movement(
distance.0 /= 1.1;
}

distance.0 = distance.0.clamp(10.0, 300.0);
distance.0 = distance.0.clamp(10.0, 150.0);
}

let cam_frw = camera.forward();
Expand Down
23 changes: 16 additions & 7 deletions src/safe_area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,28 @@ pub enum SafeArea {
}

impl SafeArea {
fn in_area(&self, sheep_pos: Vec2) -> bool {
pub fn in_area(&self, sheep_pos: Vec2) -> bool {
match self {
SafeArea::Rect { pos, size } => {
let dx = sheep_pos.x - pos.x;
let dy = sheep_pos.y - pos.y;

dx.abs() < size.x / 2.0 && dy.abs() < size.y / 2.0
},
}
SafeArea::Ellipse { pos1, pos2, radius } => {
let d = (*pos1 - *pos2).length();
let r = (*pos1 - sheep_pos).length();
r * r <= d * d
},
}
}
}

pub fn get_center(&self) -> Vec3 {
match self {
SafeArea::Rect { pos, size } => Vec3::new(pos.x, 0.0, pos.y),
SafeArea::Ellipse { pos1, pos2, radius } => {
Vec3::new((pos1.x + pos2.x) / 2.0, 0.0, (pos1.y + pos2.y) / 2.0)
}
}
}
}
Expand All @@ -64,9 +73,9 @@ pub struct SheepCounter {
}

fn count_sheeps(
mut safe_areas : Query<&SafeArea>,
mut sheep : Query<&Transform, With<Sheep>>,
mut counter : ResMut<SheepCounter>,
mut safe_areas: Query<&SafeArea>,
mut sheep: Query<&Transform, With<Sheep>>,
mut counter: ResMut<SheepCounter>,
) {
let mut count = 0;
for safe_area in safe_areas.iter() {
Expand All @@ -77,4 +86,4 @@ fn count_sheeps(
}
}
counter.count = count;
}
}
5 changes: 3 additions & 2 deletions src/test_level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn setup(
) {
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(0.0, 100.0, 100.0).looking_at(Vec3::ZERO, Vec3::Y),
camera : Camera {
camera: Camera {
hdr: true,
..default()
},
Expand All @@ -38,7 +38,8 @@ pub fn setup(
});

//spawn sun
let cascades = CascadeShadowConfigBuilder::default();
let mut cascades = CascadeShadowConfigBuilder::default();
cascades.maximum_distance = 250.0;
commands.spawn(DirectionalLightBundle {
transform: Transform::from_xyz(100.0, 100.0, 100.0).looking_at(Vec3::ZERO, Vec3::Y),
directional_light: DirectionalLight {
Expand Down

0 comments on commit 9b0d635

Please sign in to comment.