diff --git a/README.md b/README.md index 2518a3c..7ca9601 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,6 @@ The Web Site of the book: http://raytracerchallenge.com/ |:------------------------: | :------------------------: | :----------------------------: | |![07](data/chapter_07.png) | ![08](data/chapter_08.png) | ![09](data/chapter_09.png) | -| Chapiter 10 | Chapiter 11 | Chapiter 12 | -|:------------------------: | :------------------------: | :----------------------------: | -|![10](data/chapter_10.png) | | | \ No newline at end of file +| Chapiter 10 | Chapiter 11 partie 01 | Chapiter 11 partie 02 | +|:------------------------: | :---------------------------: | :----------------------------: | +|![10](data/chapter_10.png) | ![11](data/chapter_11_p1.png) | | diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt index ad46a47..41e7620 100644 --- a/apps/CMakeLists.txt +++ b/apps/CMakeLists.txt @@ -22,5 +22,8 @@ target_link_libraries(chapter_09 PRIVATE raytracing gcov OpenMP::OpenMP_CXX) add_executable(chapter_10 chapter_10.cpp) target_link_libraries(chapter_10 PRIVATE raytracing gcov OpenMP::OpenMP_CXX) -add_executable(chapter_11 chapter_11.cpp) -target_link_libraries(chapter_11 PRIVATE raytracing gcov OpenMP::OpenMP_CXX) +add_executable(chapter_11_p1 chapter_11_p1.cpp) +target_link_libraries(chapter_11_p1 PRIVATE raytracing gcov OpenMP::OpenMP_CXX) + +add_executable(chapter_11_p2 chapter_11_p2.cpp) +target_link_libraries(chapter_11_p2 PRIVATE raytracing gcov OpenMP::OpenMP_CXX) diff --git a/apps/chapter_11.cpp b/apps/chapter_11_p1.cpp similarity index 97% rename from apps/chapter_11.cpp rename to apps/chapter_11_p1.cpp index 193dab0..a912c7c 100644 --- a/apps/chapter_11.cpp +++ b/apps/chapter_11_p1.cpp @@ -1,5 +1,5 @@ /*! - * chapter_11.cpp + * chapter_11_p1.cpp * * Copyright (c) 2024, NADAL Jean-Baptiste. All rights reserved. * @@ -47,7 +47,7 @@ int main(void) Sphere *the_middle, *the_right, *the_left; chrono::time_point the_start, the_end; - printf("Chapter 11 example.\n"); + printf("Chapter 11 part1 example.\n"); // Floor is an extremely flattened sphere with a matte texture. the_floor = new Plane(); @@ -106,7 +106,7 @@ int main(void) the_canvas = the_camera.render(the_world); the_end = chrono::high_resolution_clock::now(); - the_canvas.save_to_file("chapter11.ppm"); + the_canvas.save_to_file("chapter_11_p1.ppm"); chrono::duration the_elapsed_time = the_end - the_start; printf("Execution Time: %f secondes\n", the_elapsed_time.count()); diff --git a/apps/chapter_11_p2.cpp b/apps/chapter_11_p2.cpp new file mode 100644 index 0000000..451d7bf --- /dev/null +++ b/apps/chapter_11_p2.cpp @@ -0,0 +1,122 @@ +/*! + * chapter_11_p2.cpp + * + * Copyright (c) 2024, NADAL Jean-Baptiste. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + * + * @Author: NADAL Jean-Baptiste + * @Date: 12/03/2024 + * + */ + +// This is an independent project of an individual developer. Dear PVS-Studio, please check it. +// PVS-Studio Static Code Analyzer for C, C++, C#, and Java: http://www.viva64.com + +#include +#include + +#include + +/* ------------------------------------------------------------------------- */ + +using namespace Raytracer; +using namespace std; + +/* ------------------------------------------------------------------------- */ + +int main(void) +{ + World the_world; + Camera the_camera; + Canvas the_canvas; + Plane *the_floor, *the_left_wall, *the_right_wall; + Sphere *the_middle, *the_right, *the_left; + chrono::time_point the_start, the_end; + + printf("Chapter 11 part2 example.\n"); + + // Floor is an extremely flattened sphere with a matte texture. + the_floor = new Plane(); + Material &the_floor_material = the_floor->material(); + the_floor_material.set_specular(0.0); + the_floor_material.set_reflective(0.4); + the_floor_material.set_pattern(new CheckersPattern(Color(0.35, 0.35, 0.35), Color(0.65, 0.65, 0.65))); + the_world.add_object(the_floor); + + // Left Wall + the_left_wall = new Plane(); + the_left_wall->set_transform(Matrix::translation(0, 0, 10) * + Matrix::rotation_y(-std::numbers::pi / 4) * + Matrix::rotation_x(std::numbers::pi / 2)); + Material &the_left_wall_material = the_left_wall->material(); + the_left_wall_material.set_specular(0); + the_left_wall_material.set_pattern(new StripePattern(Color(0.52, 0.52, 0.52), Color::Black())); + the_left_wall_material.pattern()->set_transform(Matrix::rotation_y(std::numbers::pi / 2)); + the_world.add_object(the_left_wall); + + // Right Wall + the_right_wall = new Plane(); + the_right_wall->set_transform(Matrix::translation(0, 5, 10) * + Matrix::rotation_y(std::numbers::pi / 4) * + Matrix::rotation_x(std::numbers::pi / 2)); + Material &the_right_wall_material = the_right_wall->material(); + the_right_wall_material.set_specular(0); + the_right_wall_material.set_pattern(new StripePattern(Color(0.52, 0.52, 0.52), Color::Black())); + the_right_wall_material.pattern()->set_transform(Matrix::rotation_y(std::numbers::pi / 2)); + the_world.add_object(the_right_wall); + + // The large sphere in the middle is a unit sphere, translated upward slightly and colored green. + the_middle = new Sphere(); + the_middle->set_transform(Matrix::translation(-0.25, 1, 1.5) * + Matrix::rotation_y(-std::numbers::pi / 1.5) * + Matrix::rotation_z(-std::numbers::pi / 6)); + + Material &the_middle_material = the_middle->material(); + the_middle_material.set_color(Color(0, 0.2, 0.)); + the_middle_material.set_ambient(0.0); + the_middle_material.set_diffuse(0.4); + the_middle_material.set_specular(0.9); + the_middle_material.set_shininess(300); + the_middle_material.set_transparency(0.9); + the_middle_material.set_reflective(0.9); + the_middle_material.set_refractive_index(1.5); + the_world.add_object(the_middle); + + // The Light source is white, shining from above and to the left + the_world.set_light(PointLight(Tuple::Point(-10, 10, -10), Color(1, 1, 1))); + + // Configure the camera. + the_camera = Camera(100, 50, std::numbers::pi / 3); + // the_camera = Camera(320, 200, std::numbers::pi / 3); + // the_camera = Camera(640, 480, std::numbers::pi / 3); + the_camera.set_transform( + Matrix::view_transform(Tuple::Point(0, 1.5, -5), Tuple::Point(0, 1, 0), Tuple::Vector(0, 1, 0))); + + the_start = chrono::high_resolution_clock::now(); + the_canvas = the_camera.render(the_world); + the_end = chrono::high_resolution_clock::now(); + + the_canvas.save_to_file("chapter_11_p2.ppm"); + + chrono::duration the_elapsed_time = the_end - the_start; + printf("Execution Time: %f secondes\n", the_elapsed_time.count()); + + return 0; +} + +// Chapter 11 example. +// Execution Time: 904.052568 secondes \ No newline at end of file diff --git a/data/chapter_11.png b/data/chapter_11.png deleted file mode 100644 index b4b9b3d..0000000 Binary files a/data/chapter_11.png and /dev/null differ diff --git a/data/chapter_11_p1.png b/data/chapter_11_p1.png new file mode 100644 index 0000000..c7d8255 Binary files /dev/null and b/data/chapter_11_p1.png differ diff --git a/raytracing/src/renderer/world.cpp b/raytracing/src/renderer/world.cpp index 6f8451d..1303dc0 100644 --- a/raytracing/src/renderer/world.cpp +++ b/raytracing/src/renderer/world.cpp @@ -267,7 +267,7 @@ Color World::color_at(const Ray &a_ray, uint32_t a_remaining) const return the_color; } - IntersectionData the_comps = the_intersec.prepare_computations(a_ray); + IntersectionData the_comps = the_intersec.prepare_computations(a_ray, &the_intersections); the_color = shade_hit(the_comps, a_remaining);