diff options
Diffstat (limited to 'src/main.cpp')
| -rw-r--r-- | src/main.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/main.cpp b/src/main.cpp index f7c4b0e..62ef981 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,7 +6,10 @@ color ground_color { 1.0, 1.0, 1.0 }; color sky_color { 0.5, 0.7, 1.0 }; -color ray_color(ray& r, const hittable& world) { +color ray_color(ray& r, const hittable& world, uint32_t depth) { + if (depth <= 0) { + return color{}; + } sphere sphere { { 0.0, 0.0, -1.0 }, 0.5 }; auto unit_dir = r.direction.unit(); @@ -15,8 +18,13 @@ color ray_color(ray& r, const hittable& world) { auto c = lerp(ground_color, sky_color, t); struct hit_info info; - if (world.hit(r, 0.0, infinity, info)) { - c = 0.5 * (info.normal + vec3{ 1.0, 1.0, 1.0}); + if (world.hit(r, 0.001, infinity, info)) { + // point3 target = info.point + info.normal + random_in_unit_sphere(); + // point3 target = info.point + info.normal + random_unit_vector(); + point3 target = info.point + info.normal + random_in_hemisphere(info.normal); + ray reflect { info.point, target - info.point }; + c = 0.5 * ray_color(reflect, world, depth - 1); + // c = 0.5 * (target - info.point + vec3{ 1.0, 1.0, 1.0 }); } return c; @@ -25,9 +33,10 @@ color ray_color(ray& r, const hittable& world) { int main() { // Image dimensions const double aspect_ratio = 16.0 / 9.0; - const size_t width = 400; + const size_t width = 1920; const size_t height = width / aspect_ratio; const uint32_t samples_per_pixel = 100; + const uint32_t max_depth = 100; camera camera { {}, aspect_ratio, 1.0 }; @@ -51,7 +60,7 @@ int main() { auto v = double(row + randd()) / (height - 1.0); auto ray = camera.get_ray(u, v); - pixel_color += ray_color(ray, world); + pixel_color += ray_color(ray, world, max_depth); } write_color(std::cout, pixel_color, samples_per_pixel); |
