Compare commits

..

No commits in common. "95d474c9565235f6cc34a65f6a9b3b4fa9dd4fd0" and "bb6b0e3e5df5220befd59e92479ac40c8f4be8f5" have entirely different histories.

3 changed files with 22 additions and 32 deletions

View File

@ -4,7 +4,6 @@
#include "utils.h" #include "utils.h"
#include "vec.h" #include "vec.h"
#include <math.h> #include <math.h>
#include <stdio.h>
#define TRIANGLE_VERTICES 3 #define TRIANGLE_VERTICES 3
@ -212,8 +211,7 @@ internal V3f get_barycentric_coords(V3f a, V3f b, V3f c, V3f p) {
internal V3f get_viewport_vertex(const V3f *vertex, const Image *img) { internal V3f get_viewport_vertex(const V3f *vertex, const Image *img) {
V4f vh = {.x = vertex->x, .y = 0.0f - vertex->y, .z = vertex->z, .w = 1.0f}; V4f vh = {.x = vertex->x, .y = 0.0f - vertex->y, .z = vertex->z, .w = 1.0f};
M4x4f vp = viewport(vh.x, vh.y, img->width, img->height); vh = mat4x4_mul_vec4(viewport(vh.x, vh.y, img->width, img->height), vh);
vh = mat4x4_mul_vec4(vp, vh);
V3f output = project_vec4(vh); V3f output = project_vec4(vh);
output.x = clamp(output.x, 0.0f, img->width); output.x = clamp(output.x, 0.0f, img->width);

View File

@ -30,6 +30,7 @@ internal PointLight g_directional_light = {
internal V3f g_eye = {0.2f, 0.1f, 0.75f}; internal V3f g_eye = {0.2f, 0.1f, 0.75f};
internal V3f g_target = {0}; internal V3f g_target = {0};
internal V3f g_up = {0.0f, 1.0f, 0.0f}; internal V3f g_up = {0.0f, 1.0f, 0.0f};
internal M4x4f g_cam_matrix = mat4x4_identity;
internal V3f general_shader_vertex(void *shader, const V3f *vertex); internal V3f general_shader_vertex(void *shader, const V3f *vertex);
internal FragmentResult phong_shader_fragment(void *shader, internal FragmentResult phong_shader_fragment(void *shader,

View File

@ -5,6 +5,8 @@
#include "typed_list.h" #include "typed_list.h"
#include <math.h> #include <math.h>
#define V3_ELEM_COUNT 3
typedef struct i64x2 V2i; typedef struct i64x2 V2i;
struct i64x2 { struct i64x2 {
i64 x; i64 x;
@ -31,7 +33,7 @@ struct f32x2 {
typedef union f32x3 V3f; typedef union f32x3 V3f;
union f32x3 { union f32x3 {
f32 elements[3]; f32 elements[V3_ELEM_COUNT];
struct { struct {
union { union {
f32 x; f32 x;
@ -48,16 +50,13 @@ union f32x3 {
}; };
}; };
typedef union f32x4 V4f; typedef struct f32x4 V4f;
union f32x4 { struct f32x4 {
f32 elements[4];
struct {
f32 x; f32 x;
f32 y; f32 y;
f32 z; f32 z;
f32 w; f32 w;
}; };
};
typedef struct u64x3 V3u; typedef struct u64x3 V3u;
struct u64x3 { struct u64x3 {
@ -66,26 +65,20 @@ struct u64x3 {
u64 z; u64 z;
}; };
typedef union f32_3x3 M3x3f; typedef struct f32_3x3 M3x3f;
union f32_3x3 { struct f32_3x3 {
V3f rows[3];
struct {
V3f row0; V3f row0;
V3f row1; V3f row1;
V3f row2; V3f row2;
}; };
};
typedef union f32_4x4 M4x4f; typedef struct f32_4x4 M4x4f;
union f32_4x4 { struct f32_4x4 {
V4f rows[4];
struct {
V4f row0; V4f row0;
V4f row1; V4f row1;
V4f row2; V4f row2;
V4f row3; V4f row3;
}; };
};
MAKE_LIST_TYPE(V3f); MAKE_LIST_TYPE(V3f);
MAKE_LIST_TYPE(V2f); MAKE_LIST_TYPE(V2f);
@ -240,8 +233,6 @@ MAKE_LIST_TYPE(V2f);
#define project_vec4(V) ((V3f){.x = V.x / V.w, .y = V.y / V.w, .z = V.z / V.w}) #define project_vec4(V) ((V3f){.x = V.x / V.w, .y = V.y / V.w, .z = V.z / V.w})
#define mat_access(MAT, i, j) (MAT.rows[i].elements[j])
M4x4f lookat(V3f eye, V3f target, V3f up); M4x4f lookat(V3f eye, V3f target, V3f up);
M4x4f projection(f32 coeff); M4x4f projection(f32 coeff);
M4x4f viewport(f32 x, f32 y, u64 w, u64 h); M4x4f viewport(f32 x, f32 y, u64 w, u64 h);