[WIP] Add reflective parameter into material

This commit is contained in:
NADAL Jean-Baptiste
2024-03-05 17:01:38 +01:00
parent 17a75a841d
commit 41ea86d3ec
24 changed files with 184 additions and 91 deletions

View File

@@ -50,7 +50,7 @@ int shadow_sphere(uint8_t a_canvas_pixels, double a_wall_size, uint8_t a_wall_z)
Tuple the_ray_origin = Tuple::Point(0, 0, -5);
double the_pixel_size = a_wall_size / a_canvas_pixels;
double the_half = a_wall_size / 2;
double the_half = a_wall_size / 2;
double the_world_x, the_world_y;
// For each row of pixels in the canvas
@@ -70,7 +70,7 @@ int shadow_sphere(uint8_t a_canvas_pixels, double a_wall_size, uint8_t a_wall_z)
the_position -= the_ray_origin;
Ray the_ray(the_ray_origin, the_position.normalize());
auto the_xs = the_shape.intersect(the_ray);
auto the_xs = the_shape.intersect(the_ray);
auto the_intersec = the_xs.hit();
if (the_intersec.is_defined())
{
@@ -94,8 +94,8 @@ int main(void)
printf("Chapter 05 example.\n");
the_start = chrono::high_resolution_clock::now();
the_ret = shadow_sphere(kImageSize, kWallSize, kWallZ);
the_end = chrono::high_resolution_clock::now();
the_ret = shadow_sphere(kImageSize, kWallSize, kWallZ);
the_end = chrono::high_resolution_clock::now();
chrono::duration<double> the_elapsed_time = the_end - the_start;
printf("Execution Time: %f secondes\n", the_elapsed_time.count());

View File

@@ -52,7 +52,7 @@ int shadow_sphere(uint8_t a_canvas_pixels, double a_wall_size, uint8_t a_wall_z)
the_shape.material().set_color(Color(1, 0.2, 1));
double the_pixel_size = a_wall_size / a_canvas_pixels;
double the_half = a_wall_size / 2;
double the_half = a_wall_size / 2;
double the_world_x, the_world_y;
// For each row of pixels in the canvas
@@ -72,15 +72,15 @@ int shadow_sphere(uint8_t a_canvas_pixels, double a_wall_size, uint8_t a_wall_z)
the_position -= the_ray_origin;
Ray the_ray(the_ray_origin, the_position.normalize());
auto the_xs = the_shape.intersect(the_ray);
auto the_xs = the_shape.intersect(the_ray);
auto the_intersec = the_xs.hit();
if (the_intersec.is_defined())
{
Tuple the_point = the_ray.position(the_intersec.distance_t());
Tuple the_point = the_ray.position(the_intersec.distance_t());
Tuple the_normal = the_intersec.object()->normal_at(the_point);
Tuple the_eye = -the_ray.direction();
Color the_color = the_intersec.object()->material().lighting(nullptr, the_light, the_point, the_eye,
the_normal, false);
Tuple the_eye = -the_ray.direction();
Color the_color = the_intersec.object()->material().lighting(nullptr, the_light, the_point, the_eye,
the_normal, false);
the_canvas.write_pixel(x, y, the_color);
}
}
@@ -101,8 +101,8 @@ int main(void)
printf("Chapter 06 example.\n");
the_start = chrono::high_resolution_clock::now();
the_ret = shadow_sphere(kImageSize, kWallSize, kWallZ);
the_end = chrono::high_resolution_clock::now();
the_ret = shadow_sphere(kImageSize, kWallSize, kWallZ);
the_end = chrono::high_resolution_clock::now();
chrono::duration<double> the_elapsed_time = the_end - the_start;
printf("Execution Time: %f secondes\n", the_elapsed_time.count());

View File

@@ -107,9 +107,9 @@ int main(void)
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_start = chrono::high_resolution_clock::now();
the_canvas = the_camera.render(the_world);
the_end = chrono::high_resolution_clock::now();
the_end = chrono::high_resolution_clock::now();
the_canvas.save_to_file("chapter07.ppm");

View File

@@ -91,9 +91,9 @@ int main(void)
the_camera.set_transform(
Matrix::view_transform(Tuple::Point(0, 1.5, -3.5), Tuple::Point(0, 1, 0), Tuple::Vector(0, 1, 0)));
the_start = chrono::high_resolution_clock::now();
the_start = chrono::high_resolution_clock::now();
the_canvas = the_camera.render(the_world);
the_end = chrono::high_resolution_clock::now();
the_end = chrono::high_resolution_clock::now();
the_canvas.save_to_file("chapter09.ppm");