ok this is better

This commit is contained in:
griffi-gh 2024-05-06 14:29:07 +02:00
parent f4e4886d33
commit d14b5e1b40
4 changed files with 17 additions and 23 deletions

View file

@ -21,7 +21,7 @@ fn update_perspective_matrix(
size: UniqueView<WindowSize>,
) {
for mut camera in (&mut vm_camera).iter() {
camera.perspective_matrix = Mat4::perspective_rh_gl(
camera.perspective_matrix = Mat4::perspective_rh(
camera.fov,
size.0.x as f32 / size.0.y as f32,
camera.z_near,

View file

@ -15,12 +15,12 @@ pub mod camera;
//pub mod entities;
//pub mod sumberge;
pub const WGPU_COORDINATE_SYSTEM: Mat4 = mat4(
vec4(1.0, 0.0, 0.0, 0.0),
vec4(0.0, 1.0, 0.0, 0.0),
vec4(0.0, 0.0, 0.5, 0.5),
vec4(0.0, 0.0, 0.0, 1.0),
);
// pub const WGPU_COORDINATE_SYSTEM: Mat4 = mat4(
// vec4(1.0, 0.0, 0.0, 0.0),
// vec4(0.0, 1.0, 0.0, 0.0),
// vec4(0.0, 0.0, 0.5, 0.5),
// vec4(0.0, 0.0, 0.0, 1.0),
// );
// #[repr(C)]
// #[derive(Debug, Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)]

View file

@ -3,13 +3,12 @@ use kubi_shared::transform::Transform;
use shipyard::{AllStoragesView, IntoIter, Unique, UniqueView, View};
use wgpu::util::DeviceExt;
use crate::camera::{self, Camera};
use super::{Renderer, WGPU_COORDINATE_SYSTEM};
use super::Renderer;
#[derive(Debug, Clone, Copy, Default, Pod, Zeroable)]
#[repr(C, packed)]
pub struct CameraUniformData {
pub view_proj: [[f32; 4]; 4],
pub view_proj: [f32; 4 * 4],
}
@ -79,6 +78,6 @@ pub fn update_camera_unform_buffer(
camera: View<Camera>,
) {
let Some(camera) = camera.iter().next() else { return };
let proj = camera.view_matrix * camera.perspective_matrix * WGPU_COORDINATE_SYSTEM;
camera_uniform_buffer.update(&renderer, CameraUniformData { view_proj: proj.to_cols_array_2d() });
let proj = camera.perspective_matrix * camera.view_matrix;
camera_uniform_buffer.update(&renderer, CameraUniformData { view_proj: proj.to_cols_array() });
}

View file

@ -7,7 +7,7 @@ use crate::{
settings::GameSettings,
world::{ChunkMeshStorage, ChunkStorage},
};
use super::{camera::CameraUniformBuffer, RenderCtx, WGPU_COORDINATE_SYSTEM};
use super::{camera::CameraUniformBuffer, RenderCtx};
mod pipeline;
mod vertex;
@ -32,14 +32,9 @@ pub fn draw_world(
textures: UniqueView<TexturePrefabs>,
chunks: UniqueView<ChunkStorage>,
meshes: NonSendSync<UniqueView<ChunkMeshStorage>>,
//transform: View<Transform>,
camera: View<Camera>,
camera_ubo: UniqueView<CameraUniformBuffer>,
settings: UniqueView<GameSettings>,
) {
let camera = camera.iter().next().expect("No cameras in the scene");
let matrix = WGPU_COORDINATE_SYSTEM * camera.view_matrix * camera.perspective_matrix;
let mut render_pass = ctx.encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("draw_world"),
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
@ -68,11 +63,11 @@ pub fn draw_world(
}
//Frustum culling
let minp = world_position;
let maxp = world_position + Vec3::splat(CHUNK_SIZE as f32);
if !camera.frustum.is_box_visible(minp, maxp) {
continue
}
// let minp = world_position;
// let maxp = world_position + Vec3::splat(CHUNK_SIZE as f32);
// if !camera.frustum.is_box_visible(minp, maxp) {
// continue
// }
//Draw chunk mesh
if mesh.main.index.size() > 0 {