From fd3052ea4a9378666f9472d9b49bc2d4831330ca Mon Sep 17 00:00:00 2001 From: Morozov-5F Date: Mon, 29 Nov 2021 00:52:15 +0300 Subject: [PATCH 1/5] [#4] Fix the rotation bug due to incorrect front face setting. --- hittables/rt_instance.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hittables/rt_instance.c b/hittables/rt_instance.c index e814de7..ef566da 100644 --- a/hittables/rt_instance.c +++ b/hittables/rt_instance.c @@ -86,7 +86,7 @@ static bool rt_instance_hit(const rt_hittable_t *hittable, const ray_t *ray, dou vec3_add(&record->p, instance->offset); vec3_t new_normal = rt_mat3_mul_vec3(&instance->transform_matrix_bb, &record->normal); - rt_hit_record_set_front_face(record, &transformed_ray, &new_normal); + rt_hit_record_set_front_face(record, &ray, &new_normal); return true; } From 203f0b5f47417608a66b541882e424c51c4c8559 Mon Sep 17 00:00:00 2001 From: Morozov-5F Date: Mon, 29 Nov 2021 01:10:49 +0300 Subject: [PATCH 2/5] [#4] Fix error from previous commit when I passed ray reference by reference. --- hittables/rt_instance.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hittables/rt_instance.c b/hittables/rt_instance.c index ef566da..31d7e23 100644 --- a/hittables/rt_instance.c +++ b/hittables/rt_instance.c @@ -86,7 +86,7 @@ static bool rt_instance_hit(const rt_hittable_t *hittable, const ray_t *ray, dou vec3_add(&record->p, instance->offset); vec3_t new_normal = rt_mat3_mul_vec3(&instance->transform_matrix_bb, &record->normal); - rt_hit_record_set_front_face(record, &ray, &new_normal); + rt_hit_record_set_front_face(record, ray, &new_normal); return true; } From cae29a66807bab5b5fea4a2343bf7932b45ceaf6 Mon Sep 17 00:00:00 2001 From: Morozov-5F Date: Mon, 29 Nov 2021 01:11:23 +0300 Subject: [PATCH 3/5] [#4] Fix issue when instance bounding box was calculated incorrectly. --- hittables/rt_instance.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/hittables/rt_instance.c b/hittables/rt_instance.c index 31d7e23..debc017 100644 --- a/hittables/rt_instance.c +++ b/hittables/rt_instance.c @@ -105,8 +105,6 @@ static bool rt_instance_bb(const rt_hittable_t *hittable, double time0, double t return false; } - hittable_bb = rt_aabb(vec3_sum(hittable_bb.min, instance->offset), vec3_sum(hittable_bb.max, instance->offset)); - vec3_t min = hittable_bb.min, max = hittable_bb.max; for (int i = 0; i < 2; i++) { @@ -119,7 +117,6 @@ static bool rt_instance_bb(const rt_hittable_t *hittable, double time0, double t k * hittable_bb.max.z + (1 - k) * hittable_bb.min.z); vec3_t tester = rt_mat3_mul_vec3(&instance->transform_matrix_bb, &point); - for (int c = 0; c < 3; c++) { min.components[c] = fmin(min.components[c], tester.components[c]); @@ -128,8 +125,7 @@ static bool rt_instance_bb(const rt_hittable_t *hittable, double time0, double t } } } - - *out_bb = rt_aabb(min, max); + *out_bb = rt_aabb(vec3_sum(min, instance->offset), vec3_sum(max, instance->offset)); return true; } From b2969da6220ae0d037c89270ed953b3803a79588 Mon Sep 17 00:00:00 2001 From: Morozov-5F Date: Mon, 29 Nov 2021 01:14:31 +0300 Subject: [PATCH 4/5] [#4] Adjust the instance scene. --- scenes/rt_scenes.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scenes/rt_scenes.c b/scenes/rt_scenes.c index 64f85e0..8a199b9 100644 --- a/scenes/rt_scenes.c +++ b/scenes/rt_scenes.c @@ -179,8 +179,8 @@ rt_hittable_list_t *rt_scene_instance_test(void) rt_hittable_t *box = rt_box_new(point3(-1, -1, -1), point3(1, 1, 1), green); rt_hittable_t *instance = rt_instance_new(box); - rt_instance_rotate_y(instance, 0); - rt_instance_translate(instance, point3(1, 0, 0)); + rt_instance_rotate_y(instance, 45); + rt_instance_translate(instance, point3(1, 0, 0.1)); rt_hittable_list_add(objects, instance); rt_hittable_list_add(objects, rt_box_new(point3(-0.25, -0.25, -0.25), point3(0.25, 0.25, 0.25), red)); From a2b5452339365f85a8728963893eefb43bd8bdcc Mon Sep 17 00:00:00 2001 From: Morozov-5F Date: Mon, 29 Nov 2021 01:19:20 +0300 Subject: [PATCH 5/5] [#4] Use proper transform for the cube in the metal showcase scene. --- scenes/rt_scenes.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scenes/rt_scenes.c b/scenes/rt_scenes.c index 8a199b9..3217ba2 100644 --- a/scenes/rt_scenes.c +++ b/scenes/rt_scenes.c @@ -332,8 +332,9 @@ rt_hittable_list_t *rt_scene_metal_test(void) rt_hittable_list_add(objects, rt_sphere_new(point3(2, 2, 0), 1, rt_mt_metal_new(colour(0.8, 0.8, 0.9), 1.0))); rt_hittable_t *box_instance = - rt_instance_new(rt_box_new(point3(-1, 0, 10), point3(1, 2, 12), rt_mt_metal_new(colour(0.8, 0.8, 0.9), 0.0))); - rt_instance_rotate_y(box_instance, 10); + rt_instance_new(rt_box_new(point3(-1, -1, -1), point3(1, 1, 1), rt_mt_metal_new(colour(0.8, 0.8, 0.9), 0.0))); + rt_instance_rotate_y(box_instance, 45); + rt_instance_translate(box_instance, vec3(2, 1, 11)); rt_hittable_list_add(objects, box_instance); return objects;