From 390ab7c3b4e73ca7be118ae4aa5e71b0f724fe6b Mon Sep 17 00:00:00 2001 From: Abdelrahman Date: Sat, 14 Sep 2024 00:59:49 +0100 Subject: [PATCH] Reformatting and cleanup --- src/shader/depth_shader.c | 8 +++----- src/shader/main_shader.c | 13 +++++-------- src/vec/vec.c | 2 -- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/shader/depth_shader.c b/src/shader/depth_shader.c index 9534151..5277364 100644 --- a/src/shader/depth_shader.c +++ b/src/shader/depth_shader.c @@ -19,14 +19,12 @@ FragmentResult depth_shader_fragment(void *shader, const V3f *barycentric, const const Model *model) { DepthShader *shdr = (DepthShader *)shader; - // clang-format off M3x3f pos_mat = {.rows = {shdr->vertices[0].position, shdr->vertices[1].position, shdr->vertices[2].position}}; pos_mat = mat3x3_transpose(pos_mat); - // clang-format on - V3f position = mat3x3_mul_vec3(pos_mat, (*barycentric)); - f32 channel = clamp(position.z + DEPTH_MAX, 0.0f, DEPTH_MAX); - Colour output = {.r = (u8)(channel), .g = (u8)(channel), .b = (u8)(channel), .a = 255}; + V3f position = mat3x3_mul_vec3(pos_mat, (*barycentric)); + f32 channel = clamp(position.z + DEPTH_MAX, 0.0f, DEPTH_MAX); + Colour output = {.r = (u8)(channel), .g = (u8)(channel), .b = (u8)(channel), .a = 255}; return (FragmentResult){.colour = output}; } diff --git a/src/shader/main_shader.c b/src/shader/main_shader.c index 30ad597..e21a2e6 100644 --- a/src/shader/main_shader.c +++ b/src/shader/main_shader.c @@ -48,8 +48,8 @@ FragmentResult diffuse_shader_fragment(void *shader, const V3f *barycentric, con u64 nm_x = uv.u * model->normal->width; u64 nm_y = uv.v * model->normal->height; - Colour pixel = get_pixel(Colour, model->normal, nm_x, nm_y); - V3f tangent = (V3f){ + Colour pixel = get_pixel(Colour, model->normal, nm_x, nm_y); + V3f tangent = (V3f){ .x = pixel.r / 255.f * 2.f - 1.f, .y = pixel.g / 255.f * 2.f - 1.f, .z = pixel.b / 255.f * 2.f - 1.f, @@ -58,7 +58,7 @@ FragmentResult diffuse_shader_fragment(void *shader, const V3f *barycentric, con V3f p0p1 = sub_v3(shdr->vertices[1].position, shdr->vertices[0].position); V3f p0p2 = sub_v3(shdr->vertices[2].position, shdr->vertices[0].position); - M3x3f A = {.rows = {p0p1, p0p2, normal}}; + M3x3f A = {.rows = {p0p1, p0p2, normal}}; M3x3f A_inv = mat3x3_inv(A); V2f uv0 = shdr->vertices[0].uv; @@ -106,12 +106,9 @@ FragmentResult albedo_shader_fragment(void *shader, const V3f *barycentric, cons const Model *model) { Shader *shdr = (Shader *)shader; - // clang-format off - M3x2f uvs = {shdr->vertices[0].uv, shdr->vertices[1].uv, shdr->vertices[2].uv}; + M3x2f uvs = {shdr->vertices[0].uv, shdr->vertices[1].uv, shdr->vertices[2].uv}; M2x3f uv_mat = mat3x2_transpose(uvs); - // clang-format on - - V2f uv = mat2x3_mul_vec3(uv_mat, (*barycentric)); + V2f uv = mat2x3_mul_vec3(uv_mat, (*barycentric)); Colour output; if (model->texture) { diff --git a/src/vec/vec.c b/src/vec/vec.c index ba5a1dd..4634885 100644 --- a/src/vec/vec.c +++ b/src/vec/vec.c @@ -29,14 +29,12 @@ M4x4f lookat(V3f eye, V3f target, V3f up) { } M4x4f projection(f32 coeff) { - // clang-format off return (M4x4f){ .row0 = {1.0f, 0.0f, 0.0f, 0.0f}, .row1 = {0.0f, 1.0f, 0.0f, 0.0f}, .row2 = {0.0f, 0.0f, 1.0f, 0.0f}, .row3 = {0.0f, 0.0f, coeff, 1.0f}, }; - // clang-format on } M4x4f viewport(f32 x, f32 y, u64 w, u64 h) {