### C++ Main Function for Scene Setup with Sphere and Lights Source: https://raytracing.github.io/books/RayTracingTheRestOfYourLife This C++ code snippet demonstrates setting up a scene in the `main` function of a ray tracing application. It includes adding various objects to the world, such as a quad light source, a translated and rotated box, and a glass sphere. The example highlights how to instantiate and add these objects with specific materials and transformations, preparing the scene for rendering. It shows the initial setup before implementing mixture density sampling. ```cpp int main() { ... // Light world.add(make_shared(point3(213,554,227), vec3(130,0,0), vec3(0,0,105), light)); // Box shared_ptr box1 = box(point3(0,0,0), point3(165,330,165), white); box1 = make_shared(box1, 15); box1 = make_shared(box1, vec3(265,0,295)); world.add(box1); // Glass Sphere auto glass = make_shared(1.5); world.add(make_shared(point3(190,90,190), 90, glass)); // Light Sources auto empty_material = shared_ptr(); quad lights(point3(343,554,332), vec3(-130,0,0), vec3(0,0,-105), empty_material); ... } ``` -------------------------------- ### C++ Scene Setup with Metal Material Source: https://raytracing.github.io/books/RayTracingTheRestOfYourLife Demonstrates setting up a Cornell box scene in 'main.cc' using various geometric shapes and materials. Specifically includes the creation of an aluminum 'metal' material and applies it to a transformed box object. ```cpp int main() { ... // Light world.add(make_shared(point3(213,554,227), vec3(130,0,0), vec3(0,0,105), light)); // Box 1 shared_ptr aluminum = make_shared(color(0.8, 0.85, 0.88), 0.0); shared_ptr box1 = box(point3(0,0,0), point3(165,330,165), aluminum); box1 = make_shared(box1, 15); box1 = make_shared(box1, vec3(265,0,295)); world.add(box1); // Box 2 shared_ptr box2 = box(point3(0,0,0), point3(165,165,165), white); box2 = make_shared(box2, -18); box2 = make_shared(box2, vec3(130,0,65)); world.add(box2); // Light Sources auto empty_material = shared_ptr(); quad lights(point3(343,554,332), vec3(-130,0,0), vec3(0,0,-105), empty_material); ... } ``` -------------------------------- ### Running Ray Tracing Executables Source: https://raytracing.github.io/README Example commands to run the compiled Ray Tracing executables and redirect the output to a PPM image file. This demonstrates running both debug and release builds. ```shell build\Debug\inOneWeekend > image.ppm # Or, run the optimized version (if compiled with release configuration): build\Release\inOneWeekend > image.ppm ``` -------------------------------- ### C++ Main Function for Scene Setup with Mixture PDF Source: https://raytracing.github.io/books/RayTracingTheRestOfYourLife This C++ code snippet updates the `main` function to utilize the new mixture density PDF capabilities for light sources. It creates a `hittable_list` named `lights` and adds both a `quad` and a `sphere` to it, both acting as light sources with an `empty_material`. This setup allows the ray tracer to sample light from both the specific quad and the glass sphere, leading to improved lighting effects and more accurate caustics as demonstrated in the accompanying images. ```cpp int main() { ... // Light Sources auto empty_material = shared_ptr(); hittable_list lights; lights.add( make_shared(point3(343,554,332), vec3(-130,0,0), vec3(0,0,-105), empty_material)); lights.add(make_shared(point3(190, 90, 190), 90, empty_material)); ... } ``` -------------------------------- ### C++ Ray Tracing: Main function setup for Cornell Box Source: https://raytracing.github.io/books/RayTracingTheRestOfYourLife Sets up the main function in C++ for rendering a Cornell box scene. It defines geometry, materials, lights, and camera parameters, including adding a `quad` light source to the scene. ```cpp int main() { ... // Box 2 shared_ptr box2 = box(point3(0,0,0), point3(165,165,165), white); box2 = make_shared(box2, -18); box2 = make_shared(box2, vec3(130,0,65)); world.add(box2); // Light Sources auto empty_material = shared_ptr(); quad lights(point3(343,554,332), vec3(-130,0,0), vec3(0,0,-105), empty_material); camera cam; cam.aspect_ratio = 1.0; cam.image_width = 600; cam.samples_per_pixel = 10; cam.max_depth = 50; cam.background = color(0,0,0); ... cam.render(world, lights); } ``` -------------------------------- ### Main Function Setup in C++ Source: https://raytracing.github.io/books/RayTracingInOneWeekend The `main.cc` file demonstrates the new main function utilizing the refactored camera class. It sets up a scene with spheres and configures the camera's aspect ratio and image width before rendering. ```C++ #include "rtweekend.h" #include "camera.h" #include "hittable.h" #include "hittable_list.h" #include "sphere.h" color ray_color(const ray& r, const hittable& world) { ... } int main() { hittable_list world; world.add(make_shared(point3(0,0,-1), 0.5)); world.add(make_shared(point3(0,-100.5,-1), 100)); camera cam; cam.aspect_ratio = 16.0 / 9.0; cam.image_width = 400; cam.render(world); } ``` -------------------------------- ### Scene Setup with Fuzzy Metal Materials (C++) Source: https://raytracing.github.io/books/RayTracingInOneWeekend Demonstrates how to create scene elements using the metal material with varying fuzziness. It shows the instantiation of lambertian and metal materials for different spheres in the scene. ```C++ int main() { ... auto material_ground = make_shared(color(0.8, 0.8, 0.0)); auto material_center = make_shared(color(0.1, 0.2, 0.5)); auto material_left = make_shared(color(0.8, 0.8, 0.8), 0.3); auto material_right = make_shared(color(0.8, 0.6, 0.2), 1.0); ... } ``` -------------------------------- ### LaTeX and BibTeX Citation for Ray Tracing Book Source: https://raytracing.github.io/books/RayTracingTheNextWeek This example provides a LaTeX citation command and a BibTeX entry for the 'Ray Tracing: The Next Week' book, including author, year, and URL. ```latex ~\cite{Shirley2025RTW2} ``` ```bibtex @misc{Shirley2025RTW2, title = {Ray Tracing: The Next Week}, author = {Peter Shirley, Trevor David Black, Steve Hollasch}, year = {2025}, month = {April}, note = {\small \texttt{https://raytracing.github.io/books/RayTracingTheNextWeek.html}}, url = {https://raytracing.github.io/books/RayTracingTheNextWeek.html} } ``` -------------------------------- ### C++ Scene Setup for Dielectric Material Source: https://raytracing.github.io/books/RayTracingInOneWeekend Demonstrates how to instantiate and assign a dielectric material to an object in a C++ ray tracing scene. This example sets up a sphere with a refractive index of 1.5. ```cpp auto material_ground = make_shared(color(0.8, 0.8, 0.0)); auto material_center = make_shared(color(0.1, 0.2, 0.5)); auto material_left = make_shared(1.50); auto material_right = make_shared(color(0.8, 0.6, 0.2), 1.0); ``` -------------------------------- ### IEEE Citation Example Source: https://raytracing.github.io/books/RayTracingInOneWeekend Provides an example of how to format a citation for 'Ray Tracing in One Weekend' in the IEEE style. This format typically includes the title, URL, and access date. ```ieee “Ray Tracing in One Weekend.” raytracing.github.io/books/RayTracingInOneWeekend.html (accessed MMM. DD, YYYY) ``` -------------------------------- ### LaTeX and BibTeX Citation Example Source: https://raytracing.github.io/books/RayTracingInOneWeekend Demonstrates how to cite the 'Ray Tracing in One Weekend' book in LaTeX using BibTeX. It includes the \cite command and the corresponding @misc entry for the bibliography. ```latex ~\cite{Shirley2025RTW1} @misc{Shirley2025RTW1, title = {Ray Tracing in One Weekend}, author = {Peter Shirley, Trevor David Black, Steve Hollasch}, year = {2025}, month = {April}, note = {\small \texttt{https://raytracing.github.io/books/RayTracingInOneWeekend.html}}, url = {https://raytracing.github.io/books/RayTracingInOneWeekend.html} } ``` -------------------------------- ### Markdown Citation Link Source: https://raytracing.github.io/books/RayTracingTheRestOfYourLife A simple Markdown link for citing the book 'Ray Tracing: The Rest of Your Life'. It includes the title in italics and a direct URL. ```markdown [_Ray Tracing: The Rest of Your Life_](https://raytracing.github.io/books/RayTracingTheRestOfYourLife.html) ``` -------------------------------- ### Scene Setup with Metal Spheres Source: https://raytracing.github.io/books/RayTracingInOneWeekend The `main` function sets up a scene containing multiple spheres with different materials, including the newly implemented `metal` material. It configures camera properties and then renders the scene. This code is the entry point for the ray tracing application. ```cpp #include "rtweekend.h" #include "camera.h" #include "hittable.h" #include "hittable_list.h" #include "material.h" #include "sphere.h" int main() { hittable_list world; auto material_ground = make_shared(color(0.8, 0.8, 0.0)); auto material_center = make_shared(color(0.1, 0.2, 0.5)); auto material_left = make_shared(color(0.8, 0.8, 0.8)); auto material_right = make_shared(color(0.8, 0.6, 0.2)); world.add(make_shared(point3( 0.0, -100.5, -1.0), 100.0, material_ground)); world.add(make_shared(point3( 0.0, 0.0, -1.2), 0.5, material_center)); world.add(make_shared(point3(-1.0, 0.0, -1.0), 0.5, material_left)); world.add(make_shared(point3( 1.0, 0.0, -1.0), 0.5, material_right)); camera cam; cam.aspect_ratio = 16.0 / 9.0; cam.image_width = 400; cam.samples_per_pixel = 100; cam.max_depth = 50; cam.render(world); } ``` -------------------------------- ### BibLaTeX Citation Example Source: https://raytracing.github.io/books/RayTracingInOneWeekend Shows how to cite the 'Ray Tracing in One Weekend' book using the BibLaTeX package. It includes the \usepackage{biblatex} command, the \cite command, and the @online entry for the bibliography. ```biblatex \usepackage{biblatex} ~\cite{Shirley2025RTW1} @online{Shirley2025RTW1, title = {Ray Tracing in One Weekend}, author = {Peter Shirley, Trevor David Black, Steve Hollasch}, year = {2025}, month = {April}, url = {https://raytracing.github.io/books/RayTracingInOneWeekend.html} } ``` -------------------------------- ### MLA Citation for Ray Tracing Book Source: https://raytracing.github.io/books/RayTracingTheNextWeek This example demonstrates the MLA style for citing the 'Ray Tracing: The Next Week' book, providing the title, URL, and access date. ```text Ray Tracing: The Next Week. raytracing.github.io/books/RayTracingTheNextWeek.html Accessed DD MMM. YYYY. ``` -------------------------------- ### MLA Citation Example Source: https://raytracing.github.io/books/RayTracingInOneWeekend Illustrates the MLA citation format for 'Ray Tracing in One Weekend'. This style emphasizes the title, URL, and access date. ```mla Ray Tracing in One Weekend. raytracing.github.io/books/RayTracingInOneWeekend.html Accessed DD MMM. YYYY. ``` -------------------------------- ### C++ Scene Setup with Quad Primitive Source: https://raytracing.github.io/books/RayTracingTheNextWeek Demonstrates how to set up a scene in a ray tracer using the `quad` primitive. This snippet includes necessary headers, defines materials, adds multiple `quad` objects with different positions and colors to a `hittable_list`, and configures the camera for rendering. ```cpp #include "rtweekend.h" #include "bvh.h" #include "camera.h" #include "hittable.h" #include "hittable_list.h" #include "material.h" #include "quad.h" #include "sphere.h" #include "texture.h" ... void quads() { hittable_list world; // Materials auto left_red = make_shared(color(1.0, 0.2, 0.2)); auto back_green = make_shared(color(0.2, 1.0, 0.2)); auto right_blue = make_shared(color(0.2, 0.2, 1.0)); auto upper_orange = make_shared(color(1.0, 0.5, 0.0)); auto lower_teal = make_shared(color(0.2, 0.8, 0.8)); // Quads world.add(make_shared(point3(-3,-2, 5), vec3(0, 0,-4), vec3(0, 4, 0), left_red)); world.add(make_shared(point3(-2,-2, 0), vec3(4, 0, 0), vec3(0, 4, 0), back_green)); world.add(make_shared(point3( 3,-2, 1), vec3(0, 0, 4), vec3(0, 4, 0), right_blue)); world.add(make_shared(point3(-2, 3, 1), vec3(4, 0, 0), vec3(0, 0, 4), upper_orange)); world.add(make_shared(point3(-2,-3, 5), vec3(4, 0, 0), vec3(0, 0,-4), lower_teal)); camera cam; cam.aspect_ratio = 1.0; cam.image_width = 400; cam.samples_per_pixel = 100; cam.max_depth = 50; cam.vfov = 80; cam.lookfrom = point3(0,0,9); cam.lookat = point3(0,0,0); cam.vup = vec3(0,1,0); cam.defocus_angle = 0; cam.render(world); } int main() { switch (5) { case 1: bouncing_spheres(); break; case 2: checkered_spheres(); break; case 3: earth(); break; case 4: perlin_spheres(); break; case 5: quads(); break; } } ``` -------------------------------- ### Perlin Textured Scene Setup in C++ Source: https://raytracing.github.io/books/RayTracingTheNextWeek Sets up a scene with Perlin-textured spheres using the previously defined noise texture. This function configures a camera, creates spheres with Perlin textures, and adds them to a hittable list. The `main` function demonstrates how to select this scene configuration. ```cpp void perlin_spheres() { hittable_list world; auto pertext = make_shared(); world.add(make_shared(point3(0,-1000,0), 1000, make_shared(pertext))); world.add(make_shared(point3(0,2,0), 2, make_shared(pertext))); camera cam; cam.aspect_ratio = 16.0 / 9.0; cam.image_width = 400; cam.samples_per_pixel = 100; cam.max_depth = 50; cam.vfov = 20; cam.lookfrom = point3(13,2,3); cam.lookat = point3(0,0,0); cam.vup = vec3(0,1,0); cam.defocus_angle = 0; cam.render(world); } int main() { switch (4) { case 1: bouncing_spheres(); break; case 2: checkered_spheres(); break; case 3: earth(); break; case 4: perlin_spheres(); break; } } ``` -------------------------------- ### Scene Setup with Earth Texture Map (C++) Source: https://raytracing.github.io/books/RayTracingTheNextWeek This function demonstrates how to use the image_texture class to apply an earth map to a sphere. It sets up the camera and scene, then renders the textured globe. This showcases the practical application of image textures in scene creation. ```cpp void earth() { // Create a shared pointer to an image_texture using the 'earthmap.jpg' file auto earth_texture = make_shared("earthmap.jpg"); // Create a lambertian material with the earth texture auto earth_surface = make_shared(earth_texture); // Create a sphere at the origin with radius 2 and the earth surface material auto globe = make_shared(point3(0,0,0), 2, earth_surface); // Configure the camera settings camera cam; cam.aspect_ratio = 16.0 / 9.0; cam.image_width = 400; cam.samples_per_pixel = 100; cam.max_depth = 50; cam.vfov = 20; cam.lookfrom = point3(0,0,12); cam.lookat = point3(0,0,0); cam.vup = vec3(0,1,0); cam.defocus_angle = 0; // Render the scene containing the globe cam.render(hittable_list(globe)); } int main() { switch (3) { case 1: bouncing_spheres(); break; case 2: checkered_spheres(); break; case 3: earth(); break; } } ``` -------------------------------- ### IEEE Citation Format Source: https://raytracing.github.io/books/RayTracingTheRestOfYourLife Presents the citation format for the book 'Ray Tracing: The Rest of Your Life' according to IEEE standards. It includes the title, URL, and a placeholder for the access date. ```text “Ray Tracing: The Rest of Your Life.” raytracing.github.io/books/RayTracingTheRestOfYourLife.html (accessed MMM. DD, YYYY) ``` -------------------------------- ### C++ Ray Tracing Scene Setup Source: https://raytracing.github.io/books/RayTracingInOneWeekend Initializes a scene with various geometric objects (spheres) and materials. This snippet demonstrates how to add objects to a hittable_list and assign different material properties like lambertian, dielectric, and metal. ```C++ int main() { hittable_list world; auto material_ground = make_shared(color(0.8, 0.8, 0.0)); auto material_center = make_shared(color(0.1, 0.2, 0.5)); auto material_left = make_shared(1.50); auto material_bubble = make_shared(1.00 / 1.50); auto material_right = make_shared(color(0.8, 0.6, 0.2), 1.0); world.add(make_shared(point3( 0.0, -100.5, -1.0), 100.0, material_ground)); world.add(make_shared(point3( 0.0, 0.0, -1.2), 0.5, material_center)); world.add(make_shared(point3(-1.0, 0.0, -1.0), 0.5, material_left)); ``` -------------------------------- ### Implement Isotropic Material for Ray Tracing in C++ Source: https://raytracing.github.io/books/RayTracingTheRestOfYourLife Implements the `isotropic` material, which scatters light uniformly in all directions. It sets a `sphere_pdf` for the scattering distribution and returns a constant PDF value. The `scatter` method handles attenuation and PDF setup. ```C++ class isotropic : public material { public: isotropic(const color& albedo) : tex(make_shared(albedo)) {} isotropic(shared_ptr tex) : tex(tex) {} bool scatter(const ray& r_in, const hit_record& rec, scatter_record& srec) const override { srec.attenuation = tex->value(rec.u, rec.v, rec.p); srec.pdf_ptr = make_shared(); srec.skip_pdf = false; return true; } double scattering_pdf(const ray& r_in, const hit_record& rec, const ray& scattered) const override { return 1 / (4 * pi); } private: shared_ptr tex; }; ``` -------------------------------- ### Main Program Setup and Rendering Loop in C++ Source: https://raytracing.github.io/books/RayTracingInOneWeekend This C++ `main.cc` file orchestrates the ray tracing process. It includes all necessary custom headers, sets up image and camera parameters, defines a scene with spheres, and iterates through pixels to render the image by calling `ray_color` and `write_color` functions. It also includes progress logging to `std::clog`. ```cpp #include "rtweekend.h" #include "color.h" #include "ray.h" #include "vec3.h" #include "hittable.h" #include "hittable_list.h" #include "sphere.h" #include double hit_sphere(const point3& center, double radius, const ray& r) { ... // Placeholder for sphere intersection logic } color ray_color(const ray& r, const hittable& world) { hit_record rec; if (world.hit(r, 0, infinity, rec)) { return 0.5 * (rec.normal + color(1,1,1)); } vec3 unit_direction = unit_vector(r.direction()); auto a = 0.5*(unit_direction.y() + 1.0); return (1.0-a)*color(1.0, 1.0, 1.0) + a*color(0.5, 0.7, 1.0); } int main() { // Image auto aspect_ratio = 16.0 / 9.0; int image_width = 400; // Calculate the image height, and ensure that it's at least 1. int image_height = int(image_width / aspect_ratio); image_height = (image_height < 1) ? 1 : image_height; // World hittable_list world; world.add(make_shared(point3(0,0,-1), 0.5)); world.add(make_shared(point3(0,-100.5,-1), 100)); // Camera auto focal_length = 1.0; auto viewport_height = 2.0; auto viewport_width = viewport_height * (double(image_width)/image_height); auto camera_center = point3(0, 0, 0); // Calculate the vectors across the horizontal and down the vertical viewport edges. auto viewport_u = vec3(viewport_width, 0, 0); auto viewport_v = vec3(0, -viewport_height, 0); // Calculate the horizontal and vertical delta vectors from pixel to pixel. auto pixel_delta_u = viewport_u / image_width; auto pixel_delta_v = viewport_v / image_height; // Calculate the location of the upper left pixel. auto viewport_upper_left = camera_center - vec3(0, 0, focal_length) - viewport_u/2 - viewport_v/2; auto pixel00_loc = viewport_upper_left + 0.5 * (pixel_delta_u + pixel_delta_v); // Render std::cout << "P3\n" << image_width << ' ' << image_height << "\n255\n"; for (int j = 0; j < image_height; j++) { std::clog << "\rScanlines remaining: " << (image_height - j) << ' ' << std::flush; for (int i = 0; i < image_width; i++) { auto pixel_center = pixel00_loc + (i * pixel_delta_u) + (j * pixel_delta_v); auto ray_direction = pixel_center - camera_center; ray r(camera_center, ray_direction); color pixel_color = ray_color(r, world); write_color(std::cout, pixel_color); } } std::clog << "\rDone. \n"; } ``` -------------------------------- ### Scene Setup with Scaled Perlin Texture (C++) Source: https://raytracing.github.io/books/RayTracingTheNextWeek This C++ function, `perlin_spheres()`, demonstrates how to use the `noise_texture` with a specified scale to create Perlin-textured spheres in a ray tracing scene. It adds two spheres to the `world` object, applying the scaled Perlin texture to their material. The camera setup is also included. ```cpp void perlin_spheres() { ... auto pertext = make_shared(4); world.add(make_shared(point3(0,-1000,0), 1000, make_shared(pertext))); world.add(make_shared(point3(0, 2, 0), 2, make_shared(pertext))); camera cam; ... } ``` -------------------------------- ### Scene Setup with Spheres Source: https://raytracing.github.io/books/RayTracingInOneWeekend Adds spheres with specified positions, radii, and materials to a scene. Assumes 'point3' for position and 'material' types are defined. ```C++ world.add(make_shared(point3(-1.0, 0.0, -1.0), 0.4, material_bubble)); world.add(make_shared(point3( 1.0, 0.0, -1.0), 0.5, material_right)); ``` -------------------------------- ### Camera Class Render Method and Initialization Logic Source: https://raytracing.github.io/books/RayTracingInOneWeekend Provides the full implementation for the 'camera' class's 'render' method and its associated private members. This includes setting up image dimensions, viewport calculations, and the main rendering loop that generates rays and writes pixel colors. ```cpp class camera { public: double aspect_ratio = 1.0; // Ratio of image width over height int image_width = 100; // Rendered image width in pixel count void render(const hittable& world) { initialize(); std::cout << "P3\n" << image_width << ' ' << image_height << "\n255\n"; for (int j = 0; j < image_height; j++) { std::clog << "\rScanlines remaining: " << (image_height - j) << ' ' << std::flush; for (int i = 0; i < image_width; i++) { auto pixel_center = pixel00_loc + (i * pixel_delta_u) + (j * pixel_delta_v); auto ray_direction = pixel_center - center; ray r(center, ray_direction); color pixel_color = ray_color(r, world); write_color(std::cout, pixel_color); } } std::clog << "\rDone. \n"; } private: int image_height; point3 center; point3 pixel00_loc; vec3 pixel_delta_u; vec3 pixel_delta_v; void initialize() { image_height = int(image_width / aspect_ratio); image_height = (image_height < 1) ? 1 : image_height; center = point3(0, 0, 0); auto focal_length = 1.0; auto viewport_height = 2.0; auto viewport_width = viewport_height * (double(image_width)/image_height); auto viewport_u = vec3(viewport_width, 0, 0); auto viewport_v = vec3(0, -viewport_height, 0); pixel_delta_u = viewport_u / image_width; pixel_delta_v = viewport_v / image_height; auto viewport_upper_left = center - vec3(0, 0, focal_length) - viewport_u/2 - viewport_v/2; ``` -------------------------------- ### Show Pi Estimation Convergence (C++) Source: https://raytracing.github.io/books/RayTracingTheRestOfYourLife An extension of the Pi estimation Monte Carlo algorithm that runs indefinitely, continuously updating and printing the estimated value of Pi. This demonstrates the convergence of the Monte Carlo method as more samples are taken. It uses iostream and iomanip for output. ```C++ #include "rtweekend.h" #include #include int main() { std::cout << std::fixed << std::setprecision(12); int inside_circle = 0; int runs = 0; while (true) { runs++; auto x = random_double(-1,1); auto y = random_double(-1,1); if (x*x + y*y < 1) inside_circle++; if (runs % 100000 == 0) std::cout << "\rEstimate of Pi = " << (4.0 * inside_circle) / runs; } std::cout << "Estimate of Pi = " << (4.0 * inside_circle) / N << '\n'; } ``` -------------------------------- ### C++ Scene Setup with Hollow Glass Sphere Source: https://raytracing.github.io/books/RayTracingInOneWeekend Demonstrates setting up a scene in C++ for ray tracing, featuring a hollow glass sphere. This involves creating dielectric materials with appropriate refractive indices to simulate the glass and the inner air bubble, and then adding spheres with these materials to the scene. ```cpp auto material_ground = make_shared(color(0.8, 0.8, 0.0)); auto material_center = make_shared(color(0.1, 0.2, 0.5)); auto material_left = make_shared(1.50); auto material_bubble = make_shared(1.00 / 1.50); auto material_right = make_shared(color(0.8, 0.6, 0.2), 0.0); world.add(make_shared(point3( 0.0, -100.5, -1.0), 100.0, material_ground)); world.add(make_shared(point3( 0.0, 0.0, -1.2), 0.5, material_center)); world.add(make_shared(point3(-1.0, 0.0, -1.0), 0.5, material_left)); world.add(make_shared(point3(-1.0, 0.0, -1.0), 0.4, material_bubble)); world.add(make_shared(point3( 1.0, 0.0, -1.0), 0.5, material_right)); ``` -------------------------------- ### MLA Citation Format Source: https://raytracing.github.io/books/RayTracingTheRestOfYourLife Provides the citation format for 'Ray Tracing: The Rest of Your Life' in MLA style. It includes the title, URL, and a placeholder for the access date. ```text Ray Tracing: The Rest of Your Life. raytracing.github.io/books/RayTracingTheRestOfYourLife.html Accessed DD MMM. YYYY. ``` -------------------------------- ### Configure Cornell Box Parameters in Main Source: https://raytracing.github.io/books/RayTracingTheRestOfYourLife Sets the `samples_per_pixel` for the Cornell box scene. This is a common parameter to adjust for noise reduction and rendering quality in ray tracing. ```C++ int main() { ... cam.samples_per_pixel = 1000; ... } ``` -------------------------------- ### Camera Initialization for Ray Tracing Source: https://raytracing.github.io/books/RayTracingTheRestOfYourLife Initializes camera parameters for ray tracing, calculating image height based on aspect ratio and determining sampling scales (sqrt_spp, pixel_samples_scale, recip_sqrt_spp). Sets the camera's center position. ```cpp void initialize() { image_height = int(image_width / aspect_ratio); image_height = (image_height < 1) ? 1 : image_height; sqrt_spp = int(std::sqrt(samples_per_pixel)); pixel_samples_scale = 1.0 / (sqrt_spp * sqrt_spp); recip_sqrt_spp = 1.0 / sqrt_spp; center = lookfrom; ... } ``` -------------------------------- ### Ray Tracing Scene Setup with BVH in C++ Source: https://raytracing.github.io/books/RayTracingTheNextWeek Demonstrates how to integrate the BVH acceleration structure into a ray tracing scene. It involves including necessary headers, creating hittable objects, and then constructing a hittable_list that is wrapped by a bvh_node for faster rendering. This code is part of the main application logic. ```cpp #include "rtweekend.h" #include "bvh.h" #include "camera.h" #include "hittable.h" #include "hittable_list.h" #include "material.h" #include "sphere.h" int main() { ... auto material2 = make_shared(color(0.4, 0.2, 0.1)); world.add(make_shared(point3(-4, 1, 0), 1.0, material2)); auto material3 = make_shared(color(0.7, 0.6, 0.5), 0.0); world.add(make_shared(point3(4, 1, 0), 1.0, material3)); world = hittable_list(make_shared(world)); camera cam; ... } ``` -------------------------------- ### HTML Citation Link Source: https://raytracing.github.io/books/RayTracingTheRestOfYourLife An HTML anchor tag used for citing the book 'Ray Tracing: The Rest of Your Life'. It uses the `` element for semantic correctness and includes a direct URL. ```html Ray Tracing: The Rest of Your Life ``` -------------------------------- ### C++ Ray Tracer Scene Setup with Moving Spheres Source: https://raytracing.github.io/books/RayTracingTheNextWeek This C++ code sets up a scene for a ray tracer, including a ground plane and multiple spheres. It demonstrates how to create moving spheres by defining their initial and final positions, enabling animation during the rendering process. The code also configures camera parameters and initiates the rendering. ```cpp int main() { hittable_list world; auto ground_material = make_shared(color(0.5, 0.5, 0.5)); world.add(make_shared(point3(0,-1000,0), 1000, ground_material)); for (int a = -11; a < 11; a++) { for (int b = -11; b < 11; b++) { auto choose_mat = random_double(); point3 center(a + 0.9*random_double(), 0.2, b + 0.9*random_double()); if ((center - point3(4, 0.2, 0)).length() > 0.9) { shared_ptr sphere_material; if (choose_mat < 0.8) { // diffuse auto albedo = color::random() * color::random(); sphere_material = make_shared(albedo); auto center2 = center + vec3(0, random_double(0,.5), 0); world.add(make_shared(center, center2, 0.2, sphere_material)); } else if (choose_mat < 0.95) { ... } ... camera cam; cam.aspect_ratio = 16.0 / 9.0; cam.image_width = 400; cam.samples_per_pixel = 100; cam.max_depth = 50; cam.vfov = 20; cam.lookfrom = point3(13,2,3); cam.lookat = point3(0,0,0); cam.vup = vec3(0,1,0); cam.defocus_angle = 0.6; cam.focus_dist = 10.0; cam.render(world); } ``` -------------------------------- ### Ray Color Calculation Loop Source: https://raytracing.github.io/books/RayTracingTheRestOfYourLife Calculates the final pixel color by accumulating the results of ray tracing for multiple samples within each pixel. It iterates over samples, generates rays, and sums their colors. ```cpp color pixel_color(0,0,0); for (int s_j = 0; s_j < sqrt_spp; s_j++) { for (int s_i = 0; s_i < sqrt_spp; s_i++) { ray r = get_ray(i, j, s_i, s_j); pixel_color += ray_color(r, max_depth, world); } } write_color(std::cout, pixel_samples_scale * pixel_color); } } std::clog << "\rDone. \n"; } ``` -------------------------------- ### C++ Main Scene Setup with Checker Texture Source: https://raytracing.github.io/books/RayTracingTheNextWeek Demonstrates how to instantiate and use the `checker_texture` within a main rendering scene. A large sphere is created with a `lambertian` material that uses a `checker_texture` for its albedo, effectively creating a checkered ground plane. ```C++ #include "rtweekend.h" #include "bvh.h" #include "camera.h" #include "hittable.h" #include "hittable_list.h" #include "material.h" #include "sphere.h" #include "texture.h" int main() { hittable_list world; auto checker = make_shared(0.32, color(.2, .3, .1), color(.9, .9, .9)); world.add(make_shared(point3(0,-1000,0), 1000, make_shared(checker))); for (int a = -11; a < 11; a++) { ... ```