fixed maybe?

This commit is contained in:
2021-10-29 17:07:29 +02:00
parent 28576035eb
commit 6ecd5b6082
8 changed files with 66 additions and 20 deletions

View File

@@ -35,6 +35,7 @@ out gl_PerVertex {
void main() {
// Vertex position in camera
gl_Position = ubo.projection * ubo.view * push.model * vec4(position, 1.0);
// gl_Position.y = -gl_Position.y;
// Vertex position in world
position_wld = vec3(push.model * vec4(position, 1.0));

View File

@@ -1,6 +1,6 @@
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};
@@ -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 game_object: GameObjectHandle,
pub background_color: Vector4<f32>,
@@ -44,7 +69,7 @@ impl UiQuad {
TextVertex { position: [1., 0., 0.], uv: [1., 0.] },
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_handle = MeshHandle {
index: mesh_index,

View File

@@ -6,7 +6,7 @@ use winit::event::Event;
use level::{load_level, save_level};
use player::Player;
use crate::game::entities::{FpsCounter, UiQuad};
use crate::game::entities::{FpsCounter, UiQuad, WorldQuad};
use crate::text::create_brush;
use crate::{config::LogConfig, vulkan};
use crate::input::InputState;
@@ -154,6 +154,11 @@ impl TestGame {
let test_quad = UiQuad::new(self, renderer);
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!");
}

View File

@@ -3,7 +3,7 @@ use cgmath::{Deg, InnerSpace, Matrix4, One, Quaternion, Rad, Rotation, Rotation3
use crate::game::player::PlayerMovementMode::{FirstPerson, Flying};
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::Updatable,

View File

@@ -1,10 +1,10 @@
#[cfg(test)]
#[allow(deprecated)]
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 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;
fn epsilon_eq(f1: f32, f2: f32) {

View File

@@ -3,6 +3,7 @@ use vulkano::buffer::TypedBufferAccess;
use crate::vulkan::{Mesh, gameobject::GameObject};
#[allow(dead_code)]
pub fn print_matrix(mat: Matrix4<f32>) {
let cols = [
[mat.x.x, mat.x.y, mat.x.z, mat.x.w],

View File

@@ -89,12 +89,20 @@ pub fn load_mesh<V>(mesh_path: &str, print_status: bool) -> Result<(Vec<CPUMesh>
reader.read_joints(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 mut inds: Vec<u32> = indices.into_u32().collect();
inds.reverse();
let cpu_mesh = CPUMesh {
vertices: CPUVertexList::Vertex3D(verts),
indices: indices.into_u32().collect(),
indices: inds,
local_texture_index: texture_index,
local_normal_map_index: normal_map_index,
name: mesh.name().map(|n| n.to_owned()),

View File

@@ -230,7 +230,7 @@ impl VulkanRenderer {
q.supports_graphics() && surface.is_supported(q).unwrap_or(false)
}).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,
[(queue_family, 0.5)].iter().cloned()).unwrap();
let queue = queues.next().unwrap();
@@ -261,11 +261,7 @@ impl VulkanRenderer {
};
let size = images[0].dimensions().width_height();
let viewport = Viewport {
origin: [0.0, 0.0],
dimensions: [size[0] as f32, size[1] as f32],
depth_range: 0.0..1.0,
};
let viewport = create_viewport(size[0] as f32, size[1] as f32);
// Render pass
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();
self.viewport = Viewport {
origin: [0.0, 0.0],
dimensions: [size[0] as f32, size[1] as f32],
depth_range: 0.0..1.0,
};
self.viewport = create_viewport(size[0] as f32, size[1] as f32);
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, .. } => {
*control_flow = ControlFlow::Exit;
},
Event::WindowEvent { event: WindowEvent::Resized(..), .. } => {
renderer.recreate_swapchain = true;
},
Event::RedrawEventsCleared => {
let ubo = game.update(&mut renderer);
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,
// }
}