defocus-modules/bin/defocus.c

61 lines
1.5 KiB
C
Raw Normal View History

/* Main command line executable. */
2023-05-23 13:20:59 +02:00
#include <defocus/defocus.h>
2023-05-23 13:20:59 +02:00
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include <stb_image_write.h>
int main(int argc, char **argv) {
df_sphere spheres[2];
spheres[0].center_x = 0.f;
spheres[0].center_y = 0.f;
spheres[0].center_z = -1.f;
spheres[0].radius = .5f;
spheres[1].center_x = 0.25f;
spheres[1].center_y = 0.25f;
spheres[1].center_z = -1.5f;
spheres[1].radius = .75f;
int image_width = 1024;
int image_height = 512;
df_image_handle input_image = df_load_image("../test_image.png", &image_width, &image_height);
float aspect = (float)image_width / (float)image_height;
df_plane plane;
plane.base_x = 0.f;
plane.base_y = 0.f;
plane.base_z = -1.f;
plane.normal_x = 0.f;
plane.normal_y = 0.f;
plane.normal_z = 1.f;
plane.img_p0_x = -aspect;
plane.img_p0_y = -1.f;
plane.img_p0_z = plane.base_z;
2023-06-19 17:29:28 +02:00
plane.img_w = 2.f * aspect;
plane.img_h = 2.f;
plane.img_ax0_x = 1.f;
plane.img_ax0_y = 0.f;
plane.img_ax0_z = 0.f;
plane.img_ax1_x = 0.f;
plane.img_ax1_y = 1.f;
plane.img_ax1_z = 0.f;
plane.image = input_image;
uint8_t *image = NULL;
df_trace_rays((df_trace_rays_settings){
.focal_length = 1.f,
.image_width = image_width,
2023-06-19 17:29:28 +02:00
.image_height = image_height,
},
spheres, 0,
&plane, 1,
&image);
stbi_write_png("raytracer.png", image_width, image_height, 3, image, image_width * 3);
2023-05-23 13:20:59 +02:00
2023-05-09 13:04:14 +02:00
return 0;
2023-04-19 13:13:08 +02:00
}