#include #include "color.h" #include "vec3.h" #include "ray.h" #include "util.h" #include "hittable_list.h" #include "sphere.h" #include "camera.h" Color ray_color(const Ray& r, const Hittable& world, int depth) { hit_record rec; if (depth <= 0) return Color(0, 0, 0); if (world.hit(r, 0, infinity, rec)) { Point3 target = rec.p + rec.normal + random_in_unit_sphere(); return 0.5 * ray_color(Ray(rec.p, target - rec.p), world, depth-1); } Vec3 unit_direction = unit_vector(r.direction()); auto t = 0.5 * (unit_direction.y() + 1.0); return (1.0 - t) * Color(1.0, 1.0, 1.0) + t * Color(0.5, 0.7, 1.0); } int main() { const auto aspect_ratio = 16.0 / 9.0; //const int image_width = 1280; const int image_width = 384; const int image_height = static_cast(image_width / aspect_ratio); const int samples_per_pixel = 250; const int max_depth = 50; std::cout << "P3\n" << image_width << " " << image_height << "\n255\n"; Hittable_list world; world.add(std::make_shared(Point3(0, 0, -1), 0.5)); world.add(std::make_shared(Point3(0, -100.5, -1), 100)); Camera cam; for (int j = image_height - 1; j >= 0; --j) { std::cerr << "\rScanlines remaining: " << j << " " << std::flush; for (int i = 0; i < image_width; ++i) { Color pixel_color(0, 0, 0); for (int s = 0; s