/* Main command line executable. */ #include #define STB_IMAGE_WRITE_IMPLEMENTATION #include df_plane get_image_filling_plane(int width, int height, df_image_handle image, float focal_length) { float aspect = (float)width / (float)height; df_plane plane; plane.base_x = 0.f; plane.base_y = 0.f; plane.base_z = -2 * focal_length; plane.normal_x = 0.f; plane.normal_y = 0.f; plane.normal_z = 1.f; plane.img_p0_x = -aspect / focal_length; plane.img_p0_y = -1.f / focal_length; plane.img_p0_z = plane.base_z; plane.img_w = 2.f * aspect / focal_length; plane.img_h = 2.f / focal_length; 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 = image; return plane; } 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 = 0; int image_height = 0; float focal_length = 1.f; 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 = get_image_filling_plane(image_width, image_height, input_image, focal_length); uint8_t *image = NULL; df_thin_lense_camera_data camera_data = df_create_thin_lense_camera_data(image_width, image_height, 42.f, focal_length); df_trace_rays((df_trace_rays_settings){ .image_width = image_width, .image_height = image_height, .samples_per_pixel = 64, .camera = df_thin_lense_camera, .camera_data = &camera_data, }, spheres, 0, &plane, 1, &image); stbi_write_png("raytracer.png", image_width, image_height, 3, image, image_width * 3); return 0; }