Create FragmentData struct

This commit is contained in:
2024-08-18 22:19:23 +01:00
parent 760d9b6b9c
commit 29749c834a
4 changed files with 50 additions and 26 deletions

View File

@@ -1,5 +1,7 @@
#include "render.h"
#include "shader.h"
#include "utils.h"
#include "vec.h"
#include <math.h>
#define TRIANGLE_VERTICES 3
@@ -117,11 +119,14 @@ internal void fill_triangle(Render *render, ShaderID shader,
V3f coords;
f32 z;
f32 zbuf;
f32 px, py, pz;
V3f position;
f32 nx, ny, nz;
V3f normal;
f32 tx_u, tx_v;
u64 tx_x, tx_y;
V2f tex_coords;
FragmentData data = {0};
FragmentResult result;
f32 intensity = 1.0f;
@@ -142,6 +147,16 @@ internal void fill_triangle(Render *render, ShaderID shader,
continue;
}
px = vertices[0].x * coords.x + vertices[1].x * coords.y +
vertices[2].x * coords.z;
py = vertices[0].y * coords.x + vertices[1].y * coords.y +
vertices[2].y * coords.z;
pz = vertices[0].z * coords.x + vertices[1].z * coords.y +
vertices[2].z * coords.z;
position = (V3f){px, py, pz};
normalise_v3(position);
data.position = position;
nx = normals[0].x * coords.x + normals[1].x * coords.y +
normals[2].x * coords.z;
ny = normals[0].y * coords.x + normals[1].y * coords.y +
@@ -149,14 +164,16 @@ internal void fill_triangle(Render *render, ShaderID shader,
nz = normals[0].z * coords.x + normals[1].z * coords.y +
normals[2].z * coords.z;
normal = (V3f){nx, ny, nz};
data.normal = normal;
tx_u = coordinates[0].u * coords.x + coordinates[1].u * coords.y +
coordinates[2].u * coords.z;
tx_v = coordinates[0].v * coords.x + coordinates[1].v * coords.y +
coordinates[2].v * coords.z;
tex_coords = (V2f){tx_u, tx_v};
data.tex_coords = tex_coords;
result = run_fragment_shader(shader, normal, tex_coords, &colour, model);
result = run_fragment_shader(shader, &data, &colour, model);
if (DISCARD_FRAGMENT(result)) {
continue;
}