render: create toggleable debug light cull view

This commit is contained in:
SeanOMik 2024-03-20 19:03:39 -04:00
parent f0b413d9ae
commit e2844a11a6
Signed by: SeanOMik
GPG Key ID: FEC9E2FC15235964
7 changed files with 49 additions and 13 deletions

View File

@ -86,6 +86,10 @@ pub fn free_fly_camera_controller(delta_time: Res<DeltaTime>, handler: Res<Actio
cam.transform.rotation = Quat::from_axis_angle(Vec3::Y, y)
* Quat::from_axis_angle(Vec3::X, x);
}
if handler.was_action_just_pressed("Debug") {
cam.debug = !cam.debug;
}
}
Ok(())

View File

@ -22,6 +22,7 @@ const ACTLBL_MOVE_FORWARD_BACKWARD: &str = "MoveForwardBackward";
const ACTLBL_LOOK_LEFT_RIGHT: &str = "LookLeftRight";
const ACTLBL_LOOK_UP_DOWN: &str = "LookUpDown";
const ACTLBL_LOOK_ROLL: &str = "LookRoll";
const ACTLBL_DEBUG: &str = "Debug";
struct FixedTimestep {
max_tps: u32,
@ -127,7 +128,7 @@ async fn main() {
light_tran.rotate_y(math::Angle::Degrees(25.0));
world.spawn((
DirectionalLight {
enabled: false,
enabled: true,
color: Vec3::ONE,
intensity: 0.35
//..Default::default()
@ -175,7 +176,7 @@ async fn main() {
cube_mesh.clone(),
));
/* world.spawn((
world.spawn((
SpotLight {
enabled: true,
color: Vec3::new(1.0, 0.0, 0.0),
@ -192,7 +193,7 @@ async fn main() {
Vec3::new(0.15, 0.15, 0.15),
),
cube_mesh.clone(),
)); */
));
}
/* {
@ -310,6 +311,7 @@ async fn main() {
.add_action(ACTLBL_LOOK_LEFT_RIGHT, Action::new(ActionKind::Axis))
.add_action(ACTLBL_LOOK_UP_DOWN, Action::new(ActionKind::Axis))
.add_action(ACTLBL_LOOK_ROLL, Action::new(ActionKind::Axis))
.add_action(ACTLBL_DEBUG, Action::new(ActionKind::Button))
.add_mapping(ActionMapping::builder(LayoutId::from(0), ActionMappingId::from(0))
.bind(ACTLBL_MOVE_FORWARD_BACKWARD, &[
@ -340,6 +342,9 @@ async fn main() {
ActionSource::Keyboard(KeyCode::E).into_binding_modifier(-1.0),
ActionSource::Keyboard(KeyCode::Q).into_binding_modifier(1.0),
])
.bind(ACTLBL_DEBUG, &[
ActionSource::Keyboard(KeyCode::B).into_binding(),
])
.finish()
).finish();

View File

@ -93,11 +93,24 @@ impl<T: Button> InputButtons<T> {
let hash = Self::get_button_hash(&button);
match self.button_events.get(&hash) {
Some(button_event) => match button_event {
// this if statement should always be true, but just in case ;)
ButtonEvent::JustPressed(b) if button == *b => true,
_ => false,
},
None => false
}
}
/// Update any JustPressed events into Pressed events
///
/// This must be done so that a key does not stay as JustPressed between multiple ticks
pub fn update(&mut self) {
for bev in self.button_events.values_mut() {
match bev {
ButtonEvent::JustPressed(btn) => {
*bev = ButtonEvent::Pressed(btn.clone());
},
_ => {},
}
}
}
}

View File

@ -102,12 +102,15 @@ impl crate::ecs::system::System for InputSystem {
let queue = world.try_get_resource_mut::<EventQueue>()
.and_then(|q| q.read_events::<InputEvent>());
let mut e = world.get_resource_or_else(InputButtons::<winit::event::VirtualKeyCode>::new);
e.update();
drop(e);
if queue.is_none() {
return Ok(());
}
let mut events = queue.unwrap();
while let Some(event) = events.pop_front() {
self.process_event(world, &event);
}

View File

@ -46,7 +46,8 @@ pub struct CameraUniform {
pub view_projection: glam::Mat4,
/// The position of the camera
pub position: glam::Vec3,
_padding: u32,
pub tile_debug: u32,
//_padding: [u8; 3],
}
@ -57,7 +58,8 @@ impl Default for CameraUniform {
inverse_projection: glam::Mat4::IDENTITY,
view_projection: glam::Mat4::IDENTITY,
position: Default::default(),
_padding: 0,
tile_debug: 0,
//_padding: 0,
}
}
}
@ -69,7 +71,7 @@ impl CameraUniform {
inverse_projection,
view_projection,
position,
_padding: 0
tile_debug: 0
}
}
}
@ -128,7 +130,7 @@ impl RenderCamera {
inverse_projection: proj.inverse(),
view_projection: self.view_proj,
position,
_padding: 0,
tile_debug: camera.debug as u32,
}
},
CameraProjectionMode::Orthographic => {
@ -150,7 +152,7 @@ impl RenderCamera {
inverse_projection: proj.inverse(),
view_projection: self.view_proj,
position,
_padding: 0,
tile_debug: camera.debug as u32,
}
},
}

View File

@ -24,6 +24,7 @@ struct CameraUniform {
inverse_projection: mat4x4<f32>,
view_projection: mat4x4<f32>,
position: vec3<f32>,
tile_debug: u32,
};
struct Light {
@ -127,7 +128,10 @@ fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return vec4<f32>(light_object_res, object_color.a);*/
if (u_camera.tile_debug == 1u) {
return debug_grid(in);
}
let tile_index = vec2<u32>(floor(in.clip_position.xy / 16.0));
let tile: vec2<u32> = textureLoad(t_light_grid, tile_index).xy;
@ -168,11 +172,14 @@ fn debug_grid(in: VertexOutput) -> vec4<f32> {
let ta: bool = x < 0.05 || y < 0.05;
let tb: bool = x > 0.95 || y > 0.95;
if ( ta || tb ) {
let ratio = f32(tile.y) / f32(u_lights.light_count);
return vec4<f32>(ratio, ratio, ratio, 1.0);
/* if ( ta || tb ) {
return vec4<f32>(0.0, 0.0, 0.0, 1.0);
} else {
return vec4<f32>(f32(tile_index.x) / 50.0, f32(tile_index.y) / 38.0, 0.0, 1.0);
}
} */
}
fn blinn_phong_dir_light(world_pos: vec3<f32>, world_norm: vec3<f32>, dir_light: Light, material: Material, specular_factor: vec3<f32>) -> vec3<f32> {

View File

@ -7,6 +7,7 @@ pub struct CameraComponent {
pub transform: Transform,
pub fov: Angle,
pub mode: CameraProjectionMode,
pub debug: bool,
}
impl Default for CameraComponent {
@ -15,6 +16,7 @@ impl Default for CameraComponent {
transform: Transform::default(),
fov: Angle::Degrees(45.0),
mode: CameraProjectionMode::Perspective,
debug: false,
}
}
}