From 9b2176185e02a271662e077a5ff710a8b4dc4686 Mon Sep 17 00:00:00 2001 From: Franklin Date: Wed, 29 Nov 2023 13:55:38 -0400 Subject: [PATCH] Adjustable Reticle brightness with bloom. --- Design.md | 2 +- assets/attachments/aimpoint_t1.glb | Bin 1489896 -> 1490000 bytes .../markers/proxy/character/player_eye.rs | 2 +- src/comps/core/markers/proxy/weapons/mod.rs | 3 ++- .../core/markers/proxy/weapons/reticle.rs | 5 ++++ src/comps/core/weapons/attachments/optic.rs | 5 ++-- src/comps/core/weapons/reticle.rs | 17 +++++++++--- src/logic/core/guns/reticle.rs | 25 +++++++++++++++--- src/logic/core/player/hands.rs | 19 ++++++++++--- src/ui/game/settings/player_controls.rs | 5 ++++ 10 files changed, 68 insertions(+), 15 deletions(-) create mode 100644 src/comps/core/markers/proxy/weapons/reticle.rs diff --git a/Design.md b/Design.md index 678cdba..5ccdec7 100644 --- a/Design.md +++ b/Design.md @@ -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 diff --git a/assets/attachments/aimpoint_t1.glb b/assets/attachments/aimpoint_t1.glb index d03deff4e95d5e81504844a86536faf4b2845dd9..c2b62d1aa854a98d706552a54a5b269440a164b1 100644 GIT binary patch delta 2648 zcmaKu&r23T7{^ylGk?6j>8q7=2nmCDecjoa+1>HrN=VQlk$zAZ)y0gWqyj+%8M8z8 zeu4f0bt(+Ogv{*{dCD$9bnIl8unyJ9dY*ZGXti+;4}6}T@Atd2yED7H`fKpR@4?)a z>!*)ZdY(71*y{DwzsS98Ti((EZ6XHU# z{l?Xi_U`kYtmFrr2_a%G!!U>ioREQDsSsMm70e8RQRl}Z3`HEUFc6Up=N78tYJG5R zw$(d&yx$w0e!aN5{w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3f 100644 --- a/src/comps/core/markers/proxy/character/player_eye.rs +++ b/src/comps/core/markers/proxy/character/player_eye.rs @@ -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}; diff --git a/src/comps/core/markers/proxy/weapons/mod.rs b/src/comps/core/markers/proxy/weapons/mod.rs index 696b9ad..db75712 100644 --- a/src/comps/core/markers/proxy/weapons/mod.rs +++ b/src/comps/core/markers/proxy/weapons/mod.rs @@ -2,4 +2,5 @@ pub mod firearm; pub mod initial_attachments; pub mod gun_colliders; pub mod sight_placement; -pub mod optic_sight_glass; \ No newline at end of file +pub mod optic_sight_glass; +pub mod reticle; \ No newline at end of file diff --git a/src/comps/core/markers/proxy/weapons/reticle.rs b/src/comps/core/markers/proxy/weapons/reticle.rs new file mode 100644 index 0000000..87323fb --- /dev/null +++ b/src/comps/core/markers/proxy/weapons/reticle.rs @@ -0,0 +1,5 @@ +use bevy::{ecs::component::Component, reflect::Reflect}; + + +#[derive(Component, Reflect, Clone, Debug, Default)] +pub struct DrawnReticle; \ No newline at end of file diff --git a/src/comps/core/weapons/attachments/optic.rs b/src/comps/core/weapons/attachments/optic.rs index 201c738..6f4dd35 100644 --- a/src/comps/core/weapons/attachments/optic.rs +++ b/src/comps/core/weapons/attachments/optic.rs @@ -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)), } } diff --git a/src/comps/core/weapons/reticle.rs b/src/comps/core/weapons/reticle.rs index 751eba1..3267abc 100644 --- a/src/comps/core/weapons/reticle.rs +++ b/src/comps/core/weapons/reticle.rs @@ -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>, materials: &mut ResMut>) { 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(), + } + } } \ No newline at end of file diff --git a/src/logic/core/guns/reticle.rs b/src/logic/core/guns/reticle.rs index d37c0c4..df1a591 100644 --- a/src/logic/core/guns/reticle.rs +++ b/src/logic/core/guns/reticle.rs @@ -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>, + sight_query_added: Query<(Entity, &OpticSightGlass), Added>, + sight_query: Query<(Entity, &OpticSightGlass)>, + reticle_query: Query<(&Parent, &Handle, &DrawnReticle),>, + firearm_state: Query<&FirearmState, Changed>, mut meshes: ResMut>, mut materials: ResMut>, ) { - 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); + } + } + } + } + } } \ No newline at end of file diff --git a/src/logic/core/player/hands.rs b/src/logic/core/player/hands.rs index fecf192..9deb40d 100644 --- a/src/logic/core/player/hands.rs +++ b/src/logic/core/player/hands.rs @@ -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, diff --git a/src/ui/game/settings/player_controls.rs b/src/ui/game/settings/player_controls.rs index 4375f16..1d36b68 100644 --- a/src/ui/game/settings/player_controls.rs +++ b/src/ui/game/settings/player_controls.rs @@ -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, } } } \ No newline at end of file