-
Notifications
You must be signed in to change notification settings - Fork 0
/
shading_1.c
57 lines (52 loc) · 1.73 KB
/
shading_1.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* shading_1.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvarussa <vvarussa@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/25 15:02:34 by vvarussa #+# #+# */
/* Updated: 2021/09/24 18:37:26 by vvarussa ### ########.fr */
/* */
/* ************************************************************************** */
#include "rt.h"
#include <stdio.h>
t_lighting check_shadow(t_world w, t_lighting l)
{
t_dunit v;
t_dunit direction;
t_inter_list il;
t_intersection i;
double distance;
v = sub(l.light.position, l.over_point);
distance = magnitude(v);
direction = normalize(v);
il = intersect_world(ray(l.over_point, direction), w);
i = hit(il);
if (i.inter >= 0 && i.inter < distance)
l.is_shaded = true;
else
l.is_shaded = false;
return (l);
}
t_dunit lighting(t_intersection i, t_ray r, t_world w)
{
t_dunit b;
t_lighting l;
int n;
n = 0;
if (i.inter < 0)
return (color(0, 0, 0));
l = prep_lighting(i, r, l);
b = color(0, 0, 0);
while (n < w.pl_list.count)
{
l.light = w.pl_list.list[n];
l = check_shadow(w, l);
l = calc_lighting(i.obj.mat, l);
n++;
if (!l.is_shaded)
b = add(b, add(l.diffuse, l.specular));
}
return (add(b, l.ambient));
}