Change plane light diffusion
authorLukas Jiriste <ljiriste@student.42prague.com>
Tue, 26 Nov 2024 19:10:26 +0000 (20:10 +0100)
committerLukas Jiriste <ljiriste@student.42prague.com>
Tue, 26 Nov 2024 19:10:26 +0000 (20:10 +0100)
In the previous commit I noted that plane may not interact with light,
if the normal has the wrong sign. This commit changes but now a plane is
illuminated through itself - it diffuses light that is on the other side
than the camera.
This could be excused arguing that it is an infinitely thin piece so it
should emit light on both sides, but I would rather it would only
emit light on the side it is illuminated on.

src/scene.c

index 02105b55adfd6ef0208d4f2775f0f591289b5a48..2b112d9ef7adcb8d03585f325758a8c2d107752d 100644 (file)
@@ -286,6 +286,8 @@ t_color     get_light_contribution(t_vec3 point, const t_object *object, const t_lig
        normal = get_object_normal(object, point);
        angle_multiplier = vec_scalar_mul(normal, new_ray.direction)
                / (vec_norm(normal) * vec_norm(new_ray.direction));
+       if (object->type == PLANE)
+               angle_multiplier = fabs(angle_multiplier);
        if (angle_multiplier > 0 && (!obstruction
                        || 1 < get_intersection_arg(&new_ray, obstruction)
                        || get_intersection_arg(&new_ray, obstruction) < 0))