|
|
|
@ -2,10 +2,14 @@
|
|
|
|
|
#include <time.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
#include <sys/sysinfo.h>
|
|
|
|
|
#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);
|
|
|
|
|
|
|
|
|
|