mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-12-24 21:08:19 -06:00
ok this is better
This commit is contained in:
parent
c071986f2a
commit
4f114be002
|
@ -21,7 +21,7 @@ fn update_perspective_matrix(
|
||||||
size: UniqueView<WindowSize>,
|
size: UniqueView<WindowSize>,
|
||||||
) {
|
) {
|
||||||
for mut camera in (&mut vm_camera).iter() {
|
for mut camera in (&mut vm_camera).iter() {
|
||||||
camera.perspective_matrix = Mat4::perspective_rh_gl(
|
camera.perspective_matrix = Mat4::perspective_rh(
|
||||||
camera.fov,
|
camera.fov,
|
||||||
size.0.x as f32 / size.0.y as f32,
|
size.0.x as f32 / size.0.y as f32,
|
||||||
camera.z_near,
|
camera.z_near,
|
||||||
|
|
|
@ -15,12 +15,12 @@ pub mod camera;
|
||||||
//pub mod entities;
|
//pub mod entities;
|
||||||
//pub mod sumberge;
|
//pub mod sumberge;
|
||||||
|
|
||||||
pub const WGPU_COORDINATE_SYSTEM: Mat4 = mat4(
|
// pub const WGPU_COORDINATE_SYSTEM: Mat4 = mat4(
|
||||||
vec4(1.0, 0.0, 0.0, 0.0),
|
// vec4(1.0, 0.0, 0.0, 0.0),
|
||||||
vec4(0.0, 1.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.5, 0.5),
|
||||||
vec4(0.0, 0.0, 0.0, 1.0),
|
// vec4(0.0, 0.0, 0.0, 1.0),
|
||||||
);
|
// );
|
||||||
|
|
||||||
// #[repr(C)]
|
// #[repr(C)]
|
||||||
// #[derive(Debug, Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)]
|
// #[derive(Debug, Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)]
|
||||||
|
|
|
@ -3,13 +3,12 @@ use kubi_shared::transform::Transform;
|
||||||
use shipyard::{AllStoragesView, IntoIter, Unique, UniqueView, View};
|
use shipyard::{AllStoragesView, IntoIter, Unique, UniqueView, View};
|
||||||
use wgpu::util::DeviceExt;
|
use wgpu::util::DeviceExt;
|
||||||
use crate::camera::{self, Camera};
|
use crate::camera::{self, Camera};
|
||||||
|
use super::Renderer;
|
||||||
use super::{Renderer, WGPU_COORDINATE_SYSTEM};
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, Default, Pod, Zeroable)]
|
#[derive(Debug, Clone, Copy, Default, Pod, Zeroable)]
|
||||||
#[repr(C, packed)]
|
#[repr(C, packed)]
|
||||||
pub struct CameraUniformData {
|
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>,
|
camera: View<Camera>,
|
||||||
) {
|
) {
|
||||||
let Some(camera) = camera.iter().next() else { return };
|
let Some(camera) = camera.iter().next() else { return };
|
||||||
let proj = camera.view_matrix * camera.perspective_matrix * WGPU_COORDINATE_SYSTEM;
|
let proj = camera.perspective_matrix * camera.view_matrix;
|
||||||
camera_uniform_buffer.update(&renderer, CameraUniformData { view_proj: proj.to_cols_array_2d() });
|
camera_uniform_buffer.update(&renderer, CameraUniformData { view_proj: proj.to_cols_array() });
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ use crate::{
|
||||||
settings::GameSettings,
|
settings::GameSettings,
|
||||||
world::{ChunkMeshStorage, ChunkStorage},
|
world::{ChunkMeshStorage, ChunkStorage},
|
||||||
};
|
};
|
||||||
use super::{camera::CameraUniformBuffer, RenderCtx, WGPU_COORDINATE_SYSTEM};
|
use super::{camera::CameraUniformBuffer, RenderCtx};
|
||||||
|
|
||||||
mod pipeline;
|
mod pipeline;
|
||||||
mod vertex;
|
mod vertex;
|
||||||
|
@ -32,14 +32,9 @@ pub fn draw_world(
|
||||||
textures: UniqueView<TexturePrefabs>,
|
textures: UniqueView<TexturePrefabs>,
|
||||||
chunks: UniqueView<ChunkStorage>,
|
chunks: UniqueView<ChunkStorage>,
|
||||||
meshes: NonSendSync<UniqueView<ChunkMeshStorage>>,
|
meshes: NonSendSync<UniqueView<ChunkMeshStorage>>,
|
||||||
//transform: View<Transform>,
|
|
||||||
camera: View<Camera>,
|
|
||||||
camera_ubo: UniqueView<CameraUniformBuffer>,
|
camera_ubo: UniqueView<CameraUniformBuffer>,
|
||||||
settings: UniqueView<GameSettings>,
|
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 {
|
let mut render_pass = ctx.encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||||
label: Some("draw_world"),
|
label: Some("draw_world"),
|
||||||
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
|
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
|
||||||
|
@ -68,11 +63,11 @@ pub fn draw_world(
|
||||||
}
|
}
|
||||||
|
|
||||||
//Frustum culling
|
//Frustum culling
|
||||||
let minp = world_position;
|
// let minp = world_position;
|
||||||
let maxp = world_position + Vec3::splat(CHUNK_SIZE as f32);
|
// let maxp = world_position + Vec3::splat(CHUNK_SIZE as f32);
|
||||||
if !camera.frustum.is_box_visible(minp, maxp) {
|
// if !camera.frustum.is_box_visible(minp, maxp) {
|
||||||
continue
|
// continue
|
||||||
}
|
// }
|
||||||
|
|
||||||
//Draw chunk mesh
|
//Draw chunk mesh
|
||||||
if mesh.main.index.size() > 0 {
|
if mesh.main.index.size() > 0 {
|
||||||
|
|
Loading…
Reference in a new issue