fixed maybe?
This commit is contained in:
@@ -35,6 +35,7 @@ out gl_PerVertex {
|
|||||||
void main() {
|
void main() {
|
||||||
// Vertex position in camera
|
// Vertex position in camera
|
||||||
gl_Position = ubo.projection * ubo.view * push.model * vec4(position, 1.0);
|
gl_Position = ubo.projection * ubo.view * push.model * vec4(position, 1.0);
|
||||||
|
// gl_Position.y = -gl_Position.y;
|
||||||
|
|
||||||
// Vertex position in world
|
// Vertex position in world
|
||||||
position_wld = vec3(push.model * vec4(position, 1.0));
|
position_wld = vec3(push.model * vec4(position, 1.0));
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use cgmath::{Vector4, vec4};
|
use cgmath::{Vector4, vec4};
|
||||||
|
|
||||||
use crate::{input::InputState, text::{create_text_object, update_text}, vulkan::{MeshHandle, PERF_COUNTER_SIZE, TextVertex, VulkanRenderer, gameobject::{GameObject, GameObjectHandle, Updatable}, mesh::{CPUMesh, CPUVertexList}}};
|
use crate::{input::InputState, text::{create_text_object, update_text}, vulkan::{MeshHandle, PERF_COUNTER_SIZE, TextVertex, Vertex, VulkanRenderer, gameobject::{GameObject, GameObjectHandle, Updatable}, mesh::{CPUMesh, CPUVertexList}}};
|
||||||
|
|
||||||
use super::{GameState, TestGame};
|
use super::{GameState, TestGame};
|
||||||
|
|
||||||
@@ -31,6 +31,31 @@ impl Updatable for FpsCounter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct WorldQuad {
|
||||||
|
pub game_object: GameObjectHandle,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WorldQuad {
|
||||||
|
pub fn new(game: &mut TestGame, renderer: &mut VulkanRenderer) -> WorldQuad {
|
||||||
|
let quad_verts = vec![
|
||||||
|
Vertex { position: [0., 0., 0.], uv: [0., 0.], normal: [0., 1., 0.], tangent: [1., 0., 0., 1.], bone_index: [0, 0, 0, 0], bone_weight: [0., 0., 0., 0.] },
|
||||||
|
Vertex { position: [1., 0., 0.], uv: [1., 0.], normal: [0., 1., 0.], tangent: [1., 0., 0., 1.], bone_index: [0, 0, 0, 0], bone_weight: [0., 0., 0., 0.] },
|
||||||
|
Vertex { position: [0., 0., 1.], uv: [0., 1.], normal: [0., 1., 0.], tangent: [1., 0., 0., 1.], bone_index: [0, 0, 0, 0], bone_weight: [0., 0., 0., 0.] },
|
||||||
|
Vertex { position: [1., 0., 1.], uv: [1., 1.], normal: [0., 1., 0.], tangent: [1., 0., 0., 1.], bone_index: [0, 0, 0, 0], bone_weight: [0., 0., 0., 0.] },
|
||||||
|
];
|
||||||
|
let cpu_mesh = CPUMesh { vertices: CPUVertexList::Vertex3D(quad_verts), indices: vec![0, 2, 1, 1, 2, 3], local_texture_index: None, local_normal_map_index: None, name: None };
|
||||||
|
let mesh_index = renderer.upload_mesh(cpu_mesh, None);
|
||||||
|
let mesh_handle = MeshHandle {
|
||||||
|
index: mesh_index,
|
||||||
|
textures: vec![1, 0],
|
||||||
|
original_path: None,
|
||||||
|
pipeline_index: 0
|
||||||
|
};
|
||||||
|
let game_object = game.add_game_object(renderer, mesh_handle);
|
||||||
|
WorldQuad { game_object }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct UiQuad {
|
pub struct UiQuad {
|
||||||
pub game_object: GameObjectHandle,
|
pub game_object: GameObjectHandle,
|
||||||
pub background_color: Vector4<f32>,
|
pub background_color: Vector4<f32>,
|
||||||
@@ -44,7 +69,7 @@ impl UiQuad {
|
|||||||
TextVertex { position: [1., 0., 0.], uv: [1., 0.] },
|
TextVertex { position: [1., 0., 0.], uv: [1., 0.] },
|
||||||
TextVertex { position: [1., 1., 0.], uv: [1., 1.] },
|
TextVertex { position: [1., 1., 0.], uv: [1., 1.] },
|
||||||
];
|
];
|
||||||
let cpu_mesh = CPUMesh { vertices: CPUVertexList::VertexText(quad_verts), indices: vec![0, 1, 2, 1, 3, 2], local_texture_index: None, local_normal_map_index: None, name: None };
|
let cpu_mesh = CPUMesh { vertices: CPUVertexList::VertexText(quad_verts), indices: vec![0, 2, 1, 1, 2, 3], local_texture_index: None, local_normal_map_index: None, name: None };
|
||||||
let mesh_index = renderer.upload_mesh(cpu_mesh, None);
|
let mesh_index = renderer.upload_mesh(cpu_mesh, None);
|
||||||
let mesh_handle = MeshHandle {
|
let mesh_handle = MeshHandle {
|
||||||
index: mesh_index,
|
index: mesh_index,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use winit::event::Event;
|
|||||||
use level::{load_level, save_level};
|
use level::{load_level, save_level};
|
||||||
use player::Player;
|
use player::Player;
|
||||||
|
|
||||||
use crate::game::entities::{FpsCounter, UiQuad};
|
use crate::game::entities::{FpsCounter, UiQuad, WorldQuad};
|
||||||
use crate::text::create_brush;
|
use crate::text::create_brush;
|
||||||
use crate::{config::LogConfig, vulkan};
|
use crate::{config::LogConfig, vulkan};
|
||||||
use crate::input::InputState;
|
use crate::input::InputState;
|
||||||
@@ -154,6 +154,11 @@ impl TestGame {
|
|||||||
let test_quad = UiQuad::new(self, renderer);
|
let test_quad = UiQuad::new(self, renderer);
|
||||||
self.components.push(Box::new(test_quad));
|
self.components.push(Box::new(test_quad));
|
||||||
|
|
||||||
|
let world_quad = WorldQuad::new(self, renderer);
|
||||||
|
let quad_go = &mut self.game_objects[world_quad.game_object];
|
||||||
|
quad_go.position = vec3(0.0, 0.01, 0.0);
|
||||||
|
quad_go.scale = vec3(10., 10., 10.);
|
||||||
|
|
||||||
println!("Game loaded!");
|
println!("Game loaded!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use cgmath::{Deg, InnerSpace, Matrix4, One, Quaternion, Rad, Rotation, Rotation3
|
|||||||
use crate::game::player::PlayerMovementMode::{FirstPerson, Flying};
|
use crate::game::player::PlayerMovementMode::{FirstPerson, Flying};
|
||||||
|
|
||||||
use crate::input::InputState;
|
use crate::input::InputState;
|
||||||
use crate::util::{intersection_distance, print_matrix};
|
use crate::util::intersection_distance;
|
||||||
use crate::vulkan::gameobject::GameObject;
|
use crate::vulkan::gameobject::GameObject;
|
||||||
use crate::vulkan::{
|
use crate::vulkan::{
|
||||||
gameobject::Updatable,
|
gameobject::Updatable,
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use cgmath::{vec3};
|
use cgmath::vec3;
|
||||||
use winit::{dpi::PhysicalPosition, event::{DeviceId, ElementState, Event, Force, KeyboardInput, ModifiersState, Touch, TouchPhase, WindowEvent}, window::WindowId};
|
use winit::{dpi::PhysicalPosition, event::{DeviceId, ElementState, Event, Force, KeyboardInput, ModifiersState, Touch, TouchPhase, WindowEvent}, window::WindowId};
|
||||||
|
|
||||||
use crate::{config::LogConfig, game::player::{intersect_triangle}, input::InputState};
|
use crate::{config::LogConfig, input::InputState, util::intersect_triangle};
|
||||||
use crate::input::vk_to_scan_code;
|
use crate::input::vk_to_scan_code;
|
||||||
|
|
||||||
fn epsilon_eq(f1: f32, f2: f32) {
|
fn epsilon_eq(f1: f32, f2: f32) {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use vulkano::buffer::TypedBufferAccess;
|
|||||||
|
|
||||||
use crate::vulkan::{Mesh, gameobject::GameObject};
|
use crate::vulkan::{Mesh, gameobject::GameObject};
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn print_matrix(mat: Matrix4<f32>) {
|
pub fn print_matrix(mat: Matrix4<f32>) {
|
||||||
let cols = [
|
let cols = [
|
||||||
[mat.x.x, mat.x.y, mat.x.z, mat.x.w],
|
[mat.x.x, mat.x.y, mat.x.z, mat.x.w],
|
||||||
|
|||||||
@@ -89,12 +89,20 @@ pub fn load_mesh<V>(mesh_path: &str, print_status: bool) -> Result<(Vec<CPUMesh>
|
|||||||
reader.read_joints(0),
|
reader.read_joints(0),
|
||||||
reader.read_weights(0));
|
reader.read_weights(0));
|
||||||
|
|
||||||
let verts = vertices_result?;
|
let mut verts = vertices_result?;
|
||||||
|
verts.iter_mut().for_each(|v| {
|
||||||
|
v.position[1] = -v.position[1];
|
||||||
|
v.normal[1] = -v.normal[1];
|
||||||
|
});
|
||||||
|
|
||||||
let vert_count = verts.len();
|
let vert_count = verts.len();
|
||||||
|
|
||||||
|
let mut inds: Vec<u32> = indices.into_u32().collect();
|
||||||
|
inds.reverse();
|
||||||
|
|
||||||
let cpu_mesh = CPUMesh {
|
let cpu_mesh = CPUMesh {
|
||||||
vertices: CPUVertexList::Vertex3D(verts),
|
vertices: CPUVertexList::Vertex3D(verts),
|
||||||
indices: indices.into_u32().collect(),
|
indices: inds,
|
||||||
local_texture_index: texture_index,
|
local_texture_index: texture_index,
|
||||||
local_normal_map_index: normal_map_index,
|
local_normal_map_index: normal_map_index,
|
||||||
name: mesh.name().map(|n| n.to_owned()),
|
name: mesh.name().map(|n| n.to_owned()),
|
||||||
|
|||||||
@@ -230,7 +230,7 @@ impl VulkanRenderer {
|
|||||||
q.supports_graphics() && surface.is_supported(q).unwrap_or(false)
|
q.supports_graphics() && surface.is_supported(q).unwrap_or(false)
|
||||||
}).unwrap();
|
}).unwrap();
|
||||||
|
|
||||||
let device_ext = DeviceExtensions { khr_swapchain: true, ..DeviceExtensions::none() };
|
let device_ext = DeviceExtensions { khr_swapchain: true, khr_maintenance1: true, ..DeviceExtensions::none() };
|
||||||
let (device, mut queues) = Device::new(physical, &Features::none(), &device_ext,
|
let (device, mut queues) = Device::new(physical, &Features::none(), &device_ext,
|
||||||
[(queue_family, 0.5)].iter().cloned()).unwrap();
|
[(queue_family, 0.5)].iter().cloned()).unwrap();
|
||||||
let queue = queues.next().unwrap();
|
let queue = queues.next().unwrap();
|
||||||
@@ -261,11 +261,7 @@ impl VulkanRenderer {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let size = images[0].dimensions().width_height();
|
let size = images[0].dimensions().width_height();
|
||||||
let viewport = Viewport {
|
let viewport = create_viewport(size[0] as f32, size[1] as f32);
|
||||||
origin: [0.0, 0.0],
|
|
||||||
dimensions: [size[0] as f32, size[1] as f32],
|
|
||||||
depth_range: 0.0..1.0,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Render pass
|
// Render pass
|
||||||
let render_pass = renderpass::create_render_pass(device.clone(), &render_config, swapchain.format());
|
let render_pass = renderpass::create_render_pass(device.clone(), &render_config, swapchain.format());
|
||||||
@@ -368,12 +364,7 @@ impl VulkanRenderer {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let size = new_images[0].dimensions().width_height();
|
let size = new_images[0].dimensions().width_height();
|
||||||
|
self.viewport = create_viewport(size[0] as f32, size[1] as f32);
|
||||||
self.viewport = Viewport {
|
|
||||||
origin: [0.0, 0.0],
|
|
||||||
dimensions: [size[0] as f32, size[1] as f32],
|
|
||||||
depth_range: 0.0..1.0,
|
|
||||||
};
|
|
||||||
|
|
||||||
self.render_pass = renderpass::create_render_pass(self.device.clone(), &self.render_config, new_swapchain.format());
|
self.render_pass = renderpass::create_render_pass(self.device.clone(), &self.render_config, new_swapchain.format());
|
||||||
|
|
||||||
@@ -694,6 +685,9 @@ pub fn start_event_loop(mut renderer: VulkanRenderer, mut game: Box<dyn Game>, e
|
|||||||
Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => {
|
Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => {
|
||||||
*control_flow = ControlFlow::Exit;
|
*control_flow = ControlFlow::Exit;
|
||||||
},
|
},
|
||||||
|
Event::WindowEvent { event: WindowEvent::Resized(..), .. } => {
|
||||||
|
renderer.recreate_swapchain = true;
|
||||||
|
},
|
||||||
Event::RedrawEventsCleared => {
|
Event::RedrawEventsCleared => {
|
||||||
let ubo = game.update(&mut renderer);
|
let ubo = game.update(&mut renderer);
|
||||||
renderer.render_loop(ubo, &game.get_game_objects());
|
renderer.render_loop(ubo, &game.get_game_objects());
|
||||||
@@ -706,3 +700,15 @@ pub fn start_event_loop(mut renderer: VulkanRenderer, mut game: Box<dyn Game>, e
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn create_viewport(width: f32, height: f32) -> Viewport {
|
||||||
|
Viewport {
|
||||||
|
origin: [0.0, 0.0],
|
||||||
|
dimensions: [width, height],
|
||||||
|
depth_range: 0.0..1.0,
|
||||||
|
}
|
||||||
|
// Viewport {
|
||||||
|
// origin: [0.0, height],
|
||||||
|
// dimensions: [width, -height],
|
||||||
|
// depth_range: 0.0..1.0,
|
||||||
|
// }
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user