summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--assets/shaders/blinn_phong.vert11
-rw-r--r--src/maths/maths.h24
-rw-r--r--src/renderer/backends/backend_vulkan.c17
3 files changed, 9 insertions, 43 deletions
diff --git a/assets/shaders/blinn_phong.vert b/assets/shaders/blinn_phong.vert
index 041c3d1..6028178 100644
--- a/assets/shaders/blinn_phong.vert
+++ b/assets/shaders/blinn_phong.vert
@@ -4,13 +4,10 @@ layout (location = 0) in vec3 inPos;
layout (location = 1) in vec3 inNormal;
layout (location = 2) in vec2 inTexCoords;
-// Uniform block
-layout (std140, binding = 0) uniform MatrixBlock {
- mat4 model;
- mat4 view;
- mat4 projection;
- mat4 lightSpaceMatrix;
-};
+uniform mat4 model;
+uniform mat4 view;
+uniform mat4 projection;
+uniform mat4 lightSpaceMatrix;
// Output
out VS_OUT {
diff --git a/src/maths/maths.h b/src/maths/maths.h
index 1432581..c9bcaad 100644
--- a/src/maths/maths.h
+++ b/src/maths/maths.h
@@ -157,38 +157,16 @@ static mat4 mat4_transposed(mat4 matrix) {
/** @brief Creates a perspective projection matrix compatible with Vulkan */
static inline mat4 mat4_perspective(f32 fov_radians, f32 aspect_ratio, f32 near_clip,
f32 far_clip) {
- // near_clip *= -1.0;
- // far_clip *= -1.0;
-
f32 half_tan_fov = tanf(fov_radians * 0.5f);
mat4 out_matrix = { .data = { 0 } };
out_matrix.data[0] = 1.0f / (aspect_ratio * half_tan_fov);
- out_matrix.data[5] = 1.0f / half_tan_fov; // Flip Y-axis for Vulkan
+ out_matrix.data[5] = -1.0f / half_tan_fov; // Flip Y-axis for Vulkan
out_matrix.data[10] = -((far_clip + near_clip) / (far_clip - near_clip));
out_matrix.data[11] = -1.0f;
out_matrix.data[14] = -((2.0f * far_clip * near_clip) / (far_clip - near_clip));
- // float half_tan_fov = tanf(fov_radians * 0.5);
- // float k = far_clip / (far_clip - near_clip);
-
- // out_matrix.data[0] = 1.0f / (aspect_ratio * half_tan_fov);
- // out_matrix.data[5] = 1.0f / half_tan_fov;
- // out_matrix.data[10] = k;
- // out_matrix.data[11] = -1.0;
- // out_matrix.data[14] = -1.0 * near_clip * k;
-
- // f32 half_tan_fov = tan(fov_radians * 0.5f);
- // out_matrix.data[0] = 1.0f / (aspect_ratio * half_tan_fov);
- // out_matrix.data[5] = 1.0f / half_tan_fov;
- // out_matrix.data[10] = -((far_clip + near_clip) / (far_clip - near_clip));
- // out_matrix.data[11] = -1.0f;
- // out_matrix.data[14] =
- // -((2.0f * far_clip * near_clip) / (far_clip - near_clip));
- // return out_matrix;
-
return out_matrix;
- // return mat4_transposed(out_matrix);
}
#else
/** @brief Creates a perspective projection matrix */
diff --git a/src/renderer/backends/backend_vulkan.c b/src/renderer/backends/backend_vulkan.c
index 97e0a44..d149e15 100644
--- a/src/renderer/backends/backend_vulkan.c
+++ b/src/renderer/backends/backend_vulkan.c
@@ -1,7 +1,8 @@
#include "camera.h"
#include "primitives.h"
#define CDEBUG
-#define CEL_PLATFORM_LINUX
+// #define CEL_PLATFORM_LINUX
+#if CEL_REND_BACKEND_VULKAN
// ^ Temporary
#include <assert.h>
@@ -30,8 +31,6 @@
#define SCR_WIDTH 1000
#define SCR_HEIGHT 1000
-#if CEL_REND_BACKEND_VULKAN
-
#include <glad/glad.h>
#include <glfw3.h>
@@ -1661,9 +1660,9 @@ void backend_begin_frame(renderer* ren, f32 delta_time) {
VkViewport viewport;
viewport.x = 0.0;
- viewport.y = (f32)context.framebuffer_height;
+ viewport.y = 0;
viewport.width = (f32)context.framebuffer_width;
- viewport.height = -(f32)context.framebuffer_height;
+ viewport.height = (f32)context.framebuffer_height;
viewport.minDepth = 0.0;
viewport.maxDepth = 1.0;
@@ -1741,14 +1740,6 @@ void gfx_backend_draw_frame(renderer* ren, camera* cam, mat4 model) {
camera_view_projection(cam, SCR_HEIGHT, SCR_WIDTH, &view, &proj);
- // proj = mat4_perspective(deg_to_rad(45.0), (f32)SCR_WIDTH / SCR_HEIGHT, 0.1, 100.0);
-
- // proj.data[5] *= -1.0;
-
- // vec3 pos = vec3_create(2, 2, 2);
- // vec3 up = VEC3_Y;
- // view = mat4_look_at(pos, VEC3_ZERO, up);
-
gfx_backend_update_global_state(proj, view, cam->position, vec4(1.0, 1.0, 1.0, 1.0), 0);
vulkan_object_shader_update_object(&context, &context.object_shader, model);