bench also working

bench
Anton Lydike 3 years ago
parent 4ed2c6dd08
commit 693f00e113

@ -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 march: obj/camera.o obj/scene.o obj/point.o obj/images.o
$(CC) $(CFLAGS) -o out/march $^ marcher.c $(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

@ -2,10 +2,14 @@
#include <time.h> #include <time.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <stdlib.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/sysinfo.h> #include <sys/sysinfo.h>
#include "images/images.h" #include "images/src/images.h"
#include "marcher.h" #include "src/scene.h"
#include "src/camera.h"
#include "src/point.h"
typedef int bool; typedef int bool;
#define true 1 #define true 1
@ -23,11 +27,11 @@ typedef int bool;
Color function is just a flat shader, detail is displayed with ambient occlusion 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]; int iters = self->args[0];
double power = self->args[1]; double power = self->args[1];
Point z = pt; struct point z = pt;
float dr = 1.0; float dr = 1.0;
float r = 0.0; float r = 0.0;
for (int i = 0; i < iters ; i++) { for (int i = 0; i < iters ; i++) {
@ -48,21 +52,24 @@ double mandelbulb_dist(Point pt, SceneObject *self) {
phi = phi*power; phi = phi*power;
// convert back to cartesian coordinates // convert back to cartesian coordinates
z = pt_mult(pt_new(sin(theta)*cos(phi), sin(phi)*sin(theta), cos(theta)), zr); z = (struct point) {
pt_add(&z, pt); .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; 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; return self->color;
} }
// constructs the scene object // constructs the scene object
SceneObject mandelbulb_new(Point location, int iters, double power) { struct scene_object mandelbulb_new(struct point location, int iters, double power) {
SceneObject so; struct scene_object so;
so.location = location; so.location = location;
so.args = malloc(sizeof(double) * 3); so.args = malloc(sizeof(double) * 3);
so.args[0] = iters; // iterations 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; int iters = 1000;
float threshold = 0.0001; float threshold = 0.0001;
Camera cam; struct camera cam;
cam.fov = 90; 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 // 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.max_steps = steps;
scene.perf_opts.threshold = threshold; scene.perf_opts.threshold = threshold;
scene.perf_opts.speed_cutoff = 10; scene.perf_opts.speed_cutoff = 10;
scene.background = color_new(0,0,0); 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); Image *img = render_scene(&scene, &cam, threads);

@ -1 +1 @@
Subproject commit 329520da739f07aded44841eb1b5de6e5903a425 Subproject commit a71e319fb4929135d51e4585a334643c194f5196
Loading…
Cancel
Save