minor improvements

rework
Anton Lydike 5 years ago
parent 67889c9f74
commit 67b2c70f25

@ -65,7 +65,10 @@ double mandelbulb_dist(Point pt, SceneObject *self) {
float r = 0.0; float r = 0.0;
for (int i = 0; i < iters ; i++) { for (int i = 0; i < iters ; i++) {
r = pt_length(z); r = pt_length(z);
if (r>2) break;
if (r>2) {
break;
}
// convert to polar coordinates // convert to polar coordinates
float theta = acos(z.z/r); float theta = acos(z.z/r);
@ -73,7 +76,7 @@ double mandelbulb_dist(Point pt, SceneObject *self) {
dr = pow(r, power-1.0)*power*dr + 1.0; dr = pow(r, power-1.0)*power*dr + 1.0;
// scale and rotate the point // scale and rotate the point
float zr = pow( r,power); float zr = pow(r, power);
theta = theta*power; theta = theta*power;
phi = phi*power; phi = phi*power;
@ -85,6 +88,7 @@ double mandelbulb_dist(Point pt, SceneObject *self) {
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(Point hit, Point direction, SceneObject *self) {
return self->color; return self->color;
} }
@ -92,12 +96,13 @@ Color mandelbulb_color(Point hit, Point direction, SceneObject *self) {
SceneObject mandelbulb_new(Point location, int iters, double power) { SceneObject mandelbulb_new(Point location, int iters, double power) {
SceneObject so; SceneObject so;
so.location = location; so.location = location;
so.args = malloc(sizeof(double) * 2); so.args = malloc(sizeof(double) * 3);
so.args[0] = iters; // iterations so.args[0] = iters; // iterations
so.args[1] = power; // power so.args[1] = power; // power
so.args[2] = -1; // reserved for color calculations
so.distance = mandelbulb_dist; so.distance = mandelbulb_dist;
so.get_color = mandelbulb_color; so.get_color = mandelbulb_color;
so.color = color_new(255,255,255); so.color = color_new(0,0,0);
return so; return so;
} }
@ -117,13 +122,14 @@ int main(int argc, char* argv[]) {
printf("threads: %d\n", threads); printf("threads: %d\n", threads);
// create basic scene with up to 10 objects // create basic scene with up to 10 objects
Scene scene = scene_new(512, 512, 10); Scene scene = scene_new(4000, 4000, 10);
scene.max_steps = 1000; scene.max_steps = 1000;
scene.threshold = 0.0001; scene.threshold = 0.0001;
scene.background = color_new(255,255,255);
//scene_add_obj(&scene, circle_new(pt_new(SCENE_MOD / 2.0, SCENE_MOD/ 2.0, SCENE_MOD / 2.0), .2)); //scene_add_obj(&scene, circle_new(pt_new(SCENE_MOD / 2.0, SCENE_MOD/ 2.0, SCENE_MOD / 2.0), .2));
scene_add_obj(&scene, mandelbulb_new(pt_new(1,1,1), 2000, 3)); scene_add_obj(&scene, mandelbulb_new(pt_new(1,1,1), 2000, 2.5));
Image *img = render_scene(&scene, &cam, threads); Image *img = render_scene(&scene, &cam, threads);

@ -150,7 +150,7 @@ void camera_iterate_rays_const_dist(Camera camera, int width, int height, int th
if (y % threads != thread_id) continue; if (y % threads != thread_id) continue;
// display progress in percent // display progress in percent
if (y % (height / 100) == 0 && y != 0) { if (height > 200 && y % (height / 100) == 0 && y != 0) {
printf("\r%02i%%", (y * 100) / height); printf("\r%02i%%", (y * 100) / height);
fflush(stdout); fflush(stdout);
} }

@ -108,10 +108,10 @@ Color march_ray(Point origin, Point direction, Scene* scene) {
#ifndef SCENE_NO_AM_OCC #ifndef SCENE_NO_AM_OCC
double f = (steps / (double) scene->max_steps); double f = (steps / (double) scene->max_steps);
f = f * f * f * f; f = f * f * f * f; // to the fourth power to make smaller values bigger
Color c = closest_obj->get_color(pos, direction, closest_obj); Color c = closest_obj->get_color(pos, direction, closest_obj);
return color_mix(c, color_new(0,0,0), f); return color_mix(c, scene->background, f);
#else #else

Loading…
Cancel
Save