Compare commits
3 Commits
bb6b0e3e5d
...
95d474c956
Author | SHA1 | Date | |
---|---|---|---|
95d474c956 | |||
41c30256b7 | |||
4b178de784 |
@ -4,6 +4,7 @@
|
||||
#include "utils.h"
|
||||
#include "vec.h"
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define TRIANGLE_VERTICES 3
|
||||
|
||||
@ -211,7 +212,8 @@ internal V3f get_barycentric_coords(V3f a, V3f b, V3f c, V3f p) {
|
||||
|
||||
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};
|
||||
vh = mat4x4_mul_vec4(viewport(vh.x, vh.y, img->width, img->height), vh);
|
||||
M4x4f vp = viewport(vh.x, vh.y, img->width, img->height);
|
||||
vh = mat4x4_mul_vec4(vp, vh);
|
||||
|
||||
V3f output = project_vec4(vh);
|
||||
output.x = clamp(output.x, 0.0f, img->width);
|
||||
|
@ -30,7 +30,6 @@ internal PointLight g_directional_light = {
|
||||
internal V3f g_eye = {0.2f, 0.1f, 0.75f};
|
||||
internal V3f g_target = {0};
|
||||
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 FragmentResult phong_shader_fragment(void *shader,
|
||||
|
@ -5,8 +5,6 @@
|
||||
#include "typed_list.h"
|
||||
#include <math.h>
|
||||
|
||||
#define V3_ELEM_COUNT 3
|
||||
|
||||
typedef struct i64x2 V2i;
|
||||
struct i64x2 {
|
||||
i64 x;
|
||||
@ -33,7 +31,7 @@ struct f32x2 {
|
||||
|
||||
typedef union f32x3 V3f;
|
||||
union f32x3 {
|
||||
f32 elements[V3_ELEM_COUNT];
|
||||
f32 elements[3];
|
||||
struct {
|
||||
union {
|
||||
f32 x;
|
||||
@ -50,13 +48,16 @@ union f32x3 {
|
||||
};
|
||||
};
|
||||
|
||||
typedef struct f32x4 V4f;
|
||||
struct f32x4 {
|
||||
typedef union f32x4 V4f;
|
||||
union f32x4 {
|
||||
f32 elements[4];
|
||||
struct {
|
||||
f32 x;
|
||||
f32 y;
|
||||
f32 z;
|
||||
f32 w;
|
||||
};
|
||||
};
|
||||
|
||||
typedef struct u64x3 V3u;
|
||||
struct u64x3 {
|
||||
@ -65,20 +66,26 @@ struct u64x3 {
|
||||
u64 z;
|
||||
};
|
||||
|
||||
typedef struct f32_3x3 M3x3f;
|
||||
struct f32_3x3 {
|
||||
typedef union f32_3x3 M3x3f;
|
||||
union f32_3x3 {
|
||||
V3f rows[3];
|
||||
struct {
|
||||
V3f row0;
|
||||
V3f row1;
|
||||
V3f row2;
|
||||
};
|
||||
};
|
||||
|
||||
typedef struct f32_4x4 M4x4f;
|
||||
struct f32_4x4 {
|
||||
typedef union f32_4x4 M4x4f;
|
||||
union f32_4x4 {
|
||||
V4f rows[4];
|
||||
struct {
|
||||
V4f row0;
|
||||
V4f row1;
|
||||
V4f row2;
|
||||
V4f row3;
|
||||
};
|
||||
};
|
||||
|
||||
MAKE_LIST_TYPE(V3f);
|
||||
MAKE_LIST_TYPE(V2f);
|
||||
@ -233,6 +240,8 @@ 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 mat_access(MAT, i, j) (MAT.rows[i].elements[j])
|
||||
|
||||
M4x4f lookat(V3f eye, V3f target, V3f up);
|
||||
M4x4f projection(f32 coeff);
|
||||
M4x4f viewport(f32 x, f32 y, u64 w, u64 h);
|
||||
|
Loading…
x
Reference in New Issue
Block a user