Bloom and static reticle

This commit is contained in:
Franklin 2023-11-29 11:23:38 -04:00
parent afe34105e4
commit 340b516cab
9 changed files with 81 additions and 6 deletions

Binary file not shown.

View File

@ -1,4 +1,4 @@
use bevy::prelude::*;
use bevy::{prelude::*, core_pipeline::{tonemapping::Tonemapping, bloom::{BloomSettings, BloomCompositeMode}}};
use bevy_rapier3d::prelude::*;
use crate::{comps::core::markers::{proxy::physics::rapier::LinkToPlayer, camera::MainCamera}, logic::core::player::player_values_state::PlayerValuesState};
@ -24,6 +24,14 @@ pub fn insert_components_into_spawned_player(
.spawn(MainCamera)
.insert(Camera3dBundle {
transform: Transform::from_xyz(0.0, 0.0, 0.0),
camera: Camera {
hdr: true,
..Default::default()
},
tonemapping: Tonemapping::TonyMcMapface,
..Default::default()
})
.insert(BloomSettings {
..Default::default()
})
//s.insert(Skybox(skybox_handle.clone()))

View File

@ -1,7 +1,7 @@
use bevy::{reflect::{Reflect, std_traits::ReflectDefault}, ecs::{component::Component, reflect::ReflectComponent}, math::Vec3, pbr::StandardMaterial, render::color::Color};
use bevy_inspector_egui::egui::Rgba;
use crate::comps::core::weapons::optic_data::OpticData;
use crate::comps::core::weapons::{optic_data::OpticData, reticle::SightReticle};
use super::attachment::Attachment;
@ -24,6 +24,12 @@ impl Optic {
1.0
}
pub fn reticle(&self) -> SightReticle {
match self {
Optic::AimpointT1 => SightReticle::Dot(0.1, Color::rgb_linear(100.0, 0.0, 0.0)),
}
}
pub fn optic_data(&self) -> OpticData {
OpticData { optic_pos_y: None, reticle_brightness: self.default_reticle_brightness() }
}

View File

@ -8,4 +8,5 @@ pub mod slot;
pub mod parts;
pub mod firearm_state;
pub mod attachment_slot;
pub mod optic_data;
pub mod optic_data;
pub mod reticle;

View File

@ -0,0 +1,37 @@
use bevy::{prelude::*, sprite::MaterialMesh2dBundle};
#[derive(Reflect, PartialEq, Clone, Debug)]
pub enum SightReticle {
/// Reticle Radius & Reticle Color
Dot(f32, Color),
}
impl Default for SightReticle {
fn default() -> Self {
Self::Dot(0.05, Color::rgb_linear(100.0, 0.0, 0.0))
}
}
impl SightReticle {
pub fn spawn(self, commands: &mut Commands, parent: Entity, meshes: &mut ResMut<Assets<Mesh>>, materials: &mut ResMut<Assets<StandardMaterial>>) {
match self {
SightReticle::Dot(radius, color) => {
commands.spawn(
MaterialMeshBundle {
mesh: meshes.add(shape::Circle::new(radius).into()).into(),
material: materials.add(StandardMaterial {
emissive: color,
..Default::default()
}),
transform: {
let mut t = Transform::from_translation(Vec3::ZERO);
t.rotate_x(90.0f32.to_radians());
t
},
..default()
}
).set_parent(parent);
},
}
}
}

View File

@ -3,4 +3,5 @@ pub mod player_firing;
pub mod shoot;
pub mod inspect;
pub mod equipped_gun_collisions;
pub mod update_bullet;
pub mod update_bullet;
pub mod reticle;

View File

@ -0,0 +1,20 @@
use bevy::prelude::*;
use crate::comps::core::markers::proxy::weapons::optic_sight_glass::OpticSightGlass;
/// How?
/// Achieve parallax on all reticles by drawing a line straight out of the barrel and a straight line from the sight that intersected at the specified zeroed range for the optic.
/// Make sure that the reticle is where the bullets will land at the specified zeroed range.
pub fn update_reticle(
mut commands: Commands,
// TODO: make this identify which optic is on the gun, but meanwhile just start doing it to all the optics in
sight_query: Query<(Entity, &OpticSightGlass), Added<OpticSightGlass>>,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
for (entity, sight) in sight_query.iter() {
let reticle = sight.0.reticle();
reticle.spawn(&mut commands, entity, &mut meshes, &mut materials);
println!("Added reticle");
}
}

View File

@ -7,7 +7,7 @@ use crate::{
spawners::{player::player_spawner, spawn::SpawnerPlugin}, events::{bullet_collision::BulletCollisionEvent, equipped_gun_collision::EquippedGunCollisionEvent},
},
logic::core::{
guns::{despawn_shots::{despawn_muzzle_flashes, despawn_stray_bullets}, inspect::inspect_firearm, equipped_gun_collisions::update_gun_position_on_collision, update_bullet::update_bullet},
guns::{despawn_shots::{despawn_muzzle_flashes, despawn_stray_bullets}, inspect::inspect_firearm, equipped_gun_collisions::update_gun_position_on_collision, update_bullet::update_bullet, reticle::update_reticle},
player::{
camera_player_sync::{
follow_cursor_with_camera, update_camera_vertical_position, MouseMovementSettings,
@ -63,6 +63,7 @@ pub fn load_scene(application: &mut App) {
application.add_systems(Update, collision_handler);
application.add_systems(Update, update_gun_position_on_collision);
application.add_systems(Update, update_bullet);
application.add_systems(Update, update_reticle);
//application.add_systems(Update, animate_player);
//application.add_systems(Update, register_bullet_hits);

View File

@ -6,7 +6,7 @@ use crate::{
comps::core::{markers::{
holdable::{HoldableObjectData, InPlayerHands},
player::{Player, PlayerData, PlayerHand}, inspect_screen::InspectScreenSlotUiMarker, bullet::BulletMarker,
}, weapons::{firearm_data::FirearmData, magazine_data::MagazineData, caliber::Caliber, firearm::Firearm, spray_pattern::FirearmSprayPattern, firearm_state::FirearmState}},
}, weapons::{firearm_data::FirearmData, magazine_data::MagazineData, caliber::Caliber, firearm::Firearm, spray_pattern::FirearmSprayPattern, firearm_state::FirearmState, reticle::SightReticle}},
logic::core::{
guns::player_firing::PlayerFiringInfo,
player::{
@ -57,6 +57,7 @@ impl Plugin for MainEditorUiPlugin {
.register_type::<PlayerSettings>()
.register_type::<InspectScreenSlotUiMarker>()
.register_type::<PlayerControls>()
.register_type::<SightReticle>()
//.register_type::<AllAnimations>()
//.register_type::<FirearmAnimations>()
.register_type::<GltfAssetType>()