diff --git a/Makefile b/Makefile index 57b4a0b..273fe2f 100644 --- a/Makefile +++ b/Makefile @@ -25,3 +25,5 @@ obj/images.o: images/src/images.c images/src/images.h march: obj/camera.o obj/scene.o obj/point.o obj/images.o $(CC) $(CFLAGS) -o out/march $^ marcher.c +bench: obj/camera.o obj/scene.o obj/point.o obj/images.o + $(CC) $(CFLAGS) -o out/bench $^ bench.c diff --git a/bench.c b/bench.c index cc9442c..20bc774 100644 --- a/bench.c +++ b/bench.c @@ -2,10 +2,14 @@ #include #include #include +#include #include #include -#include "images/images.h" -#include "marcher.h" +#include "images/src/images.h" +#include "src/scene.h" +#include "src/camera.h" +#include "src/point.h" + typedef int bool; #define true 1 @@ -23,11 +27,11 @@ typedef int bool; Color function is just a flat shader, detail is displayed with ambient occlusion */ -double mandelbulb_dist(Point pt, SceneObject *self) { +double mandelbulb_dist(struct point pt, struct scene_object *self) { int iters = self->args[0]; double power = self->args[1]; - Point z = pt; + struct point z = pt; float dr = 1.0; float r = 0.0; for (int i = 0; i < iters ; i++) { @@ -48,21 +52,24 @@ double mandelbulb_dist(Point pt, SceneObject *self) { phi = phi*power; // convert back to cartesian coordinates - z = pt_mult(pt_new(sin(theta)*cos(phi), sin(phi)*sin(theta), cos(theta)), zr); - pt_add(&z, pt); + z = (struct point) { + .x = sin(theta)*cos(phi) * zr + pt.x, + .y = sin(phi)*sin(theta) * zr + pt.y, + .z = cos(theta) * zr + pt.z + }; } return 0.5*log(r)*r/dr; } -Color mandelbulb_color(Point hit, Point direction, SceneObject *self) { +Color mandelbulb_color(struct point hit, struct point direction, struct scene_object *self) { return self->color; } // constructs the scene object -SceneObject mandelbulb_new(Point location, int iters, double power) { - SceneObject so; +struct scene_object mandelbulb_new(struct point location, int iters, double power) { + struct scene_object so; so.location = location; so.args = malloc(sizeof(double) * 3); so.args[0] = iters; // iterations @@ -80,19 +87,19 @@ int run_bench(int size, float pow, int threads, const char path[], bool save) { int iters = 1000; float threshold = 0.0001; - Camera cam; + struct camera cam; cam.fov = 90; - camera_set_looking_at(&cam, pt_new(cam_position, cam_position, cam_position), pt_new(0,0,0)); + camera_set_looking_at(&cam, (struct point){.x = cam_position, .y = cam_position, .z = cam_position}, PT_ZERO); // create basic scene with up to 10 objects - Scene scene = scene_new(size, size, 1); + struct scene scene = scene_new(size, size, 1); scene.perf_opts.max_steps = steps; scene.perf_opts.threshold = threshold; scene.perf_opts.speed_cutoff = 10; scene.background = color_new(0,0,0); - scene_add_obj(&scene, mandelbulb_new(pt_new(0,0,0), iters, pow)); + scene_add_obj(&scene, mandelbulb_new(PT_ZERO, iters, pow)); Image *img = render_scene(&scene, &cam, threads); diff --git a/images b/images index 329520d..a71e319 160000 --- a/images +++ b/images @@ -1 +1 @@ -Subproject commit 329520da739f07aded44841eb1b5de6e5903a425 +Subproject commit a71e319fb4929135d51e4585a334643c194f5196