-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmaterial.ml
73 lines (63 loc) · 1.43 KB
/
material.ml
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
open Vec
(* module representing color, with each of rgb values in range 0-1 *)
module Color =
struct
type t = {
r : float;
g : float;
b : float;
}
let make (r: float) (g: float) (b: float) = { r = r; g = g; b = b }
let get color = (color.r, color.g, color.b)
let colorToVec color = Vec3f.make color.r color.g color.b
let vecToColor(vec: Vec3f.vec3) =
let (r, g, b) = Vec3f.get vec in
make r g b
let randColor () = {
r = Random.float 1.;
g = Random.float 1.;
b = Random.float 1.;
}
end
let zeroColor = Color.make 0. 0. 0.
(*
module representing material of object,
with coefficients needed to compute lambert/phong/ambient/mirror reflection
*)
module Material =
struct
type t = {
color: Color.t;
ambient: float;
mirror: float;
lambert: float;
specular: float;
}
let make (color: Color.t) (ambient: float) ?(mirror: float = 0.) (lambert: float) (specular: float) =
if ambient = 0. then
{
color = color;
ambient = ambient;
mirror = mirror;
lambert = lambert;
specular = specular;
}
else
{
color = color;
ambient = ambient;
mirror = 0.;
lambert = lambert;
specular = specular;
}
let randMaterial () =
{
color = Color.randColor();
ambient = Random.float 1.;
mirror = 0.;
lambert = Random.float 1.;
specular = Random.float 1.;
}
let get material = material.color
let getCoefficients material = (material.ambient, material.mirror, material.lambert, material.specular)
end