Adjustable Reticle brightness with bloom.

This commit is contained in:
Franklin 2023-11-29 13:55:38 -04:00
parent 340b516cab
commit 9b2176185e
10 changed files with 68 additions and 15 deletions

View File

@ -39,7 +39,7 @@ Multiplayer
- [x] All optics implementing a fn/trait that gives a specific gun offset to use the optic correctly
- [x] Find some way to implement a shader for the optics (AFTER IMPLEMENTING NEW BULLET SYSTEM)
- [x] Optic glass material
- [ ] TODO: Reticle render
- [x] Reticle render
- [ ] Parallax effect on reticle
- [ ] Weapon Clipping
- [x] Make the player's collider bigger towards the front

Binary file not shown.

View File

@ -1,4 +1,4 @@
use bevy::{prelude::*, core_pipeline::{tonemapping::Tonemapping, bloom::{BloomSettings, BloomCompositeMode}}};
use bevy::{prelude::*, core_pipeline::{tonemapping::Tonemapping, bloom::BloomSettings}};
use bevy_rapier3d::prelude::*;
use crate::{comps::core::markers::{proxy::physics::rapier::LinkToPlayer, camera::MainCamera}, logic::core::player::player_values_state::PlayerValuesState};

View File

@ -2,4 +2,5 @@ pub mod firearm;
pub mod initial_attachments;
pub mod gun_colliders;
pub mod sight_placement;
pub mod optic_sight_glass;
pub mod optic_sight_glass;
pub mod reticle;

View File

@ -0,0 +1,5 @@
use bevy::{ecs::component::Component, reflect::Reflect};
#[derive(Component, Reflect, Clone, Debug, Default)]
pub struct DrawnReticle;

View File

@ -20,13 +20,14 @@ impl Optic {
}
}
/// Goes from 1-300
pub fn default_reticle_brightness(&self) -> f32 {
1.0
200.0
}
pub fn reticle(&self) -> SightReticle {
match self {
Optic::AimpointT1 => SightReticle::Dot(0.1, Color::rgb_linear(100.0, 0.0, 0.0)),
Optic::AimpointT1 => SightReticle::Dot(0.05, Color::rgb_linear(1.0, 0.0, 0.0)),
}
}

View File

@ -1,5 +1,7 @@
use bevy::{prelude::*, sprite::MaterialMesh2dBundle};
use crate::comps::core::markers::proxy::weapons::reticle::DrawnReticle;
#[derive(Reflect, PartialEq, Clone, Debug)]
pub enum SightReticle {
/// Reticle Radius & Reticle Color
@ -8,7 +10,7 @@ pub enum SightReticle {
impl Default for SightReticle {
fn default() -> Self {
Self::Dot(0.05, Color::rgb_linear(100.0, 0.0, 0.0))
Self::Dot(0.05, Color::rgb_linear(1.0, 0.0, 0.0))
}
}
@ -16,7 +18,7 @@ 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(
commands.spawn((
MaterialMeshBundle {
mesh: meshes.add(shape::Circle::new(radius).into()).into(),
material: materials.add(StandardMaterial {
@ -30,8 +32,17 @@ impl SightReticle {
},
..default()
}
).set_parent(parent);
,
Name::new("Reticle"),
DrawnReticle,
)).set_parent(parent);
},
}
}
pub fn get_color(&self) -> Color {
match self {
SightReticle::Dot(_, color) => color.clone(),
}
}
}

View File

@ -1,6 +1,6 @@
use bevy::prelude::*;
use crate::comps::core::markers::proxy::weapons::optic_sight_glass::OpticSightGlass;
use crate::comps::core::{markers::proxy::weapons::{optic_sight_glass::OpticSightGlass, reticle::DrawnReticle}, weapons::firearm_state::FirearmState};
/// 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.
@ -8,13 +8,32 @@ use crate::comps::core::markers::proxy::weapons::optic_sight_glass::OpticSightGl
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>>,
sight_query_added: Query<(Entity, &OpticSightGlass), Added<OpticSightGlass>>,
sight_query: Query<(Entity, &OpticSightGlass)>,
reticle_query: Query<(&Parent, &Handle<StandardMaterial>, &DrawnReticle),>,
firearm_state: Query<&FirearmState, Changed<FirearmState>>,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
for (entity, sight) in sight_query.iter() {
// Spawn reticles
for (entity, sight) in sight_query_added.iter() {
let reticle = sight.0.reticle();
reticle.spawn(&mut commands, entity, &mut meshes, &mut materials);
println!("Added reticle");
}
// Modify reticle brightness
for (optic_entity, optic_sight_glass) in sight_query.iter() {
for (reticle_parent, reticle_material, _) in reticle_query.iter() {
if optic_entity != reticle_parent.get() { continue; }
for firearm_state in firearm_state.iter() {
if let Some(ref optic_data) = firearm_state.optic_data {
if let Some(mat) = materials.get_mut(reticle_material) {
mat.emissive = optic_sight_glass.0.reticle().get_color() * optic_data.reticle_brightness.clamp(1.0, 500.0);
}
}
}
}
}
}

View File

@ -50,7 +50,6 @@ pub struct CaptureHandUsageQueryParams<'w, 's> {
children: Query<'w, 's, &'static Children>,
}
#[allow(unused)]
#[allow(irrefutable_let_patterns)]
pub fn capture_hand_usage(
mut resources: CaptureHandUsageResourcesParams,
@ -92,7 +91,7 @@ pub fn capture_hand_usage(
};
*hand_transform = hand_transform.lerp(default_hand_transform, resources.time.delta_seconds() / 0.25);
}
let scroll_events: Vec<&MouseWheel> = mouse_wheel_events.read().collect();
if !resources.game_ui_state.any_window() && !player_firing_info.is_reloading {
if resources.keyboard_input.just_pressed(resources.player_controls.primary_weapon) {
if let Some(primary_item) = player_inventory.get_primary() {
@ -142,9 +141,9 @@ pub fn capture_hand_usage(
if player.0.equipment.is_firearm() {
player_firing_info.is_inspecting = true;
}
} else if !mouse_wheel_events.is_empty() {
} else if !scroll_events.is_empty() {
if player.0.equipment.is_firearm() {
for mouse_wheel_event in mouse_wheel_events.read() {
for mouse_wheel_event in scroll_events.iter() {
if player_firing_info.gun_colliding_with_object { continue; }
if mouse_wheel_event.y >= 0.0 {
player_firing_info.gun_ready_pose = GunReadyPose::HighReady;
@ -216,6 +215,18 @@ pub fn capture_hand_usage(
);
in_hand_transform.rotation = rotation_lerp_quat;
in_hand_transform.translation = position_lerp_vec3;
if resources.keyboard_input.pressed(resources.player_controls.reticle_adjustment_requisite) {
if let Some(ref mut optic_data) = firearm_state.optic_data {
for mouse_wheel_event in scroll_events.iter() {
let add_to_brightness = mouse_wheel_event.y * resources.time.delta_seconds() * 200.0;
println!("Changed reticle bright by {}", add_to_brightness);
// TODO: Clamp values correctly
optic_data.reticle_brightness = (optic_data.reticle_brightness + add_to_brightness).clamp(1.0, 500.0);
//println!("Changed reticle bright by {}", add_to_brightness);
}
}
}
} else {
in_hand_transform.rotation = in_hand_transform.rotation.lerp(
firearm_data.rotation_offset + resources.player_settings.rot_offset,

View File

@ -57,6 +57,9 @@ pub struct PlayerControls {
pub inventory: KeyCode,
/// Press this key and then adjust with another key
pub reticle_adjustment_requisite: KeyCode,
}
impl Default for PlayerControls {
@ -100,6 +103,8 @@ impl Default for PlayerControls {
low_ready: ControlsInput::ScrollWheel(ScrollWheelInput::Down),
inventory: KeyCode::Tab,
reticle_adjustment_requisite: KeyCode::ShiftLeft,
}
}
}