I have no idea what i'm doing

This commit is contained in:
2025-09-14 12:35:20 -04:00
parent a160d4d068
commit faa18bbd8c
3 changed files with 33 additions and 28 deletions

View File

@@ -83,13 +83,14 @@ fn setup(mut commands: Commands, mut images: ResMut<Assets<Image>>, window: Sing
commands.spawn(Camera2d);
commands.spawn((
// Camera3d::default(),
Projection::Perspective(PerspectiveProjection {
aspect_ratio: size.x as f32 / size.y as f32,
..default()
}),
Camera3d::default(),
Camera { order: -1, ..default() },
// Projection::Perspective(PerspectiveProjection {
// aspect_ratio: size.x as f32 / size.y as f32,
// ..default()
// }),
RTCamera,
Transform::from_xyz(0.0, 0.0, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
Transform::from_xyz(0.0, 5.0, 20.0).looking_at(Vec3::ZERO, Vec3::Y),
Name::new("RT Camera"),
));

View File

@@ -174,21 +174,19 @@ pub struct TracerImageBindGroups(pub [BindGroup; 2]);
fn update_tracer_uniforms(
mut tracer_uniforms: ResMut<TracerUniforms>,
rt_camera: Single<(&GlobalTransform, &Projection, &Camera), With<RTCamera>>,
rt_camera: Single<(&GlobalTransform, &Camera), With<RTCamera>>,
) {
let (transform, projection, cam) = rt_camera.into_inner();
let (transform, cam) = rt_camera.into_inner();
let view = transform.compute_matrix().inverse();
let clip_from_view = match projection {
Projection::Perspective(perspective_projection) => perspective_projection.get_clip_from_view(),
_ => unreachable!("This should never happen: Invalid projection type on RT Camera"),
};
let clip_from_world = clip_from_view * view;
let world_from_clip = clip_from_world.inverse();
// info!("clip_from_view = {:?}", clip_from_view);
// info!("world_from_clip = {:?}", world_from_clip);
let clip_from_view = cam.clip_from_view();
let world_from_clip = view * clip_from_view.inverse();
tracer_uniforms.world_from_clip = world_from_clip;
tracer_uniforms.world_position = transform.translation();
// info!("clip_from_view = {:?}", clip_from_view);
// info!("world_from_clip = {:?}", world_from_clip);
}
fn prepare_bind_groups(