Refactor and add reflections

This commit is contained in:
2024-02-04 19:07:34 +00:00
parent 6d8f332500
commit c2560ccbdd
8 changed files with 314 additions and 253 deletions

View File

@@ -0,0 +1,8 @@
#ifndef MATH_UTILS_H
#define MATH_UTILS_H
#include "c_cpp_aliases/aliases.h"
f32 clamp(f32 value, f32 min, f32 max);
#endif // !MATH_UTILS_H

View File

@@ -0,0 +1,54 @@
#ifndef RAYTRACER_H
#define RAYTRACER_H
#include "c_cpp_aliases/aliases.h"
#include "vector/vec.h"
#include "window/window.h"
typedef struct {
f32 radius;
vec3f_t centre;
colour_t colour;
f32 specular;
f32 reflective;
} sphere_t;
typedef enum {
LIGHT_TYPE_POINT,
LIGHT_TYPE_DIRECTIONAL,
LIGHT_TYPE_AMBIENT,
COUNT_LIGHT_TYPE,
} light_type_t;
typedef struct {
light_type_t type;
f32 intensity;
union {
vec3f_t position;
vec3f_t direction;
};
} light_t;
typedef struct {
sphere_t *spheres;
light_t *lights;
u32 spheres_count;
u32 lights_count;
} scene_t;
typedef struct {
f32 t1;
f32 t2;
} solutions_t;
typedef struct {
f32 closest_t;
sphere_t *closest_sphere;
} intersection_t;
colour_t trace_ray(vec3f_t origin, vec3f_t direction, f32 t_min, f32 t_max,
const scene_t *scene, colour_t default_colour,
u32 recursion_depth);
#endif // !RAYTRACER_H

View File

@@ -40,4 +40,7 @@ void swap_buffers(window_t *wnd);
vec3f_t window_to_viewport(window_t *wnd, i32 x, i32 y, vec3f_t viewport);
colour_t colour_add_colour(colour_t a, colour_t b);
colour_t colour_mul(colour_t colour, f32 scalar);
#endif // !WINDOW_H