-
Notifications
You must be signed in to change notification settings - Fork 1
/
metal.c
29 lines (22 loc) · 799 Bytes
/
metal.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
#include <stdlib.h>
#include "metal.h"
static bool _scatter(const void *t, const Ray r_in, const Hit_Record rec, Vector *attenuation, Ray *scattered)
{
const Metal met = *(const Metal *) t;
/* Get diffuse reflection light and attenuation coefficient of material */
Vector reflected = reflect(unit_vector(r_in.direction(r_in)), rec.normal);
*scattered = new_ray(rec.p, reflected.add(reflected, reflected.mul_scalar(random_in_uint_sphere(), met.fuzz)));
*attenuation = met.albedo;
return (reflected.dot(scattered->direction(*scattered), rec.normal) > 0);
}
Metal new_metal(Vector v, float f)
{
int fuzz = (f < 1) ? f : 1;
return (Metal) {
.albedo = v,
.fuzz = fuzz,
.mat = (Material) {
.scatter = _scatter
},
};
}