Split scene definition to use it in both raytracer and rasteriser

This commit is contained in:
2024-06-22 16:46:55 +01:00
parent fbe4513a14
commit 8fc3a2577a
5 changed files with 117 additions and 98 deletions

View File

@@ -1,5 +1,6 @@
#include "c_cpp_aliases/aliases.h"
#include "raytracer/raytracer.h"
#include "scene/scene.h"
#include "vector/vec.h"
#include "window/window.h"
#include <SDL2/SDL_events.h>
@@ -8,7 +9,6 @@
#include <stdbool.h>
#include <stdlib.h>
#define ARR_LEN(ARR) sizeof(ARR) / sizeof(ARR[0])
#define RECURSION_DEPTH 3
typedef struct {
@@ -31,72 +31,11 @@ i32 main(i32 argc, char *argv[]) {
return EXIT_FAILURE;
}
const scene_t *scene = build_test_scene();
bool running = true;
SDL_Event event = {0};
sphere_t spheres[] = {
(sphere_t){
.radius = 1.0f,
.centre = (vec3f_t){.x = 0.0f, .y = -1.0f, .z = 3.0f},
.colour =
(colour_t){
.rgba.r = 245, .rgba.g = 238, .rgba.b = 158, .rgba.a = 255},
.specular = 500.0f,
.reflective = 0.3f,
},
(sphere_t){
.radius = 1.0f,
.centre = (vec3f_t){.x = -2.0f, .y = 0.0f, .z = 4.0f},
.colour =
(colour_t){
.rgba.r = 59, .rgba.g = 142, .rgba.b = 165, .rgba.a = 255},
.specular = 10.0f,
.reflective = 0.1f,
},
(sphere_t){
.radius = 1.0f,
.centre = (vec3f_t){.x = 2.0f, .y = 0.0f, .z = 4.0f},
.colour =
(colour_t){
.rgba.r = 171, .rgba.g = 52, .rgba.b = 40, .rgba.a = 255},
.specular = 500.0f,
.reflective = 0.4f,
},
(sphere_t){
.radius = 5000.0f,
.centre = (vec3f_t){.x = 0.0f, .y = -5001.0f, .z = 0.0f},
.colour =
(colour_t){
.rgba.r = 255, .rgba.g = 255, .rgba.b = 0, .rgba.a = 255},
.specular = 1000.0f,
.reflective = 0.5f,
},
};
light_t lights[] = {
(light_t){
.type = LIGHT_TYPE_AMBIENT,
.intensity = 0.2f,
},
(light_t){
.type = LIGHT_TYPE_POINT,
.intensity = 0.6f,
.position = (vec3f_t){.x = 2.0f, .y = 1.0f, .z = 0.0f},
},
(light_t){
.type = LIGHT_TYPE_DIRECTIONAL,
.intensity = 0.2f,
.direction = (vec3f_t){.x = 1.0f, .y = 4.0f, .z = 4.0f},
},
};
scene_t scene = {
.spheres = spheres,
.lights = lights,
.spheres_count = ARR_LEN(spheres),
.lights_count = ARR_LEN(lights),
};
i32 w_min = ((i32)window.half_width) * -1;
i32 w_max = (i32)window.half_width;
i32 h_min = ((i32)window.half_height) * -1;
@@ -118,7 +57,7 @@ i32 main(i32 argc, char *argv[]) {
vec3f_t direction = window_to_viewport(&window, x, y, viewport);
vec3f_t rotated = vec_rotate_vec3f_t(direction, camera.rotation);
colour_t colour = trace_ray(camera.position, rotated, 1, INFINITY,
&scene, bg, RECURSION_DEPTH);
scene, bg, RECURSION_DEPTH);
set_pixel(&window, x, y, colour);
}
}