-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMaterialCheckered.c
66 lines (43 loc) · 1.68 KB
/
MaterialCheckered.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
58
59
60
61
62
63
64
65
66
#include "MaterialCheckered.h"
#include "randf.h"
#include "pi.h"
#include <math.h>
const MaterialVTable materialCheckeredVTable = (MaterialVTable) {
&materialCheckeredSampleBRDF,
&materialCheckeredBRDF,
&materialCheckeredIrradience
};
MaterialCheckered makeMaterialCheckered(const Material *a, const Material *b) {
return (MaterialCheckered) {makeMaterial(&materialCheckeredVTable), a, b};
}
defineAllocator(MaterialCheckered)
bool materialCheckeredFIsEven(float f) {
return 0 != ((int)floor(f)) % 2;
}
bool materialCheckeredVIsInA(Vector v) {
return
materialCheckeredFIsEven(v.x) !=
materialCheckeredFIsEven(v.y) !=
materialCheckeredFIsEven(v.z)
;
}
Photon materialCheckeredSampleBRDF(const Material *superObject, const Intersection intersection, const Photon incoming) {
MaterialCheckered *material = (MaterialCheckered *) superObject;
if(materialCheckeredVIsInA(intersection.position)){
return materialSampleBRDF(material->a, intersection, incoming);
}else{
return materialSampleBRDF(material->b, intersection, incoming);
}
}
Color materialCheckeredBRDF(const Material *superObject, const Intersection intersection, const Vector incoming, const Vector outgoing) {
MaterialCheckered *material = (MaterialCheckered *) superObject;
if(materialCheckeredVIsInA(intersection.position)){
return materialBRDF(material->a, intersection, incoming, outgoing);
}else{
return materialBRDF(material->b, intersection, incoming, outgoing);
}
}
Color materialCheckeredIrradience(const Material *superObject) {
MaterialCheckered *material = (MaterialCheckered *) superObject;
return csMul(cAdd(materialIrradience(material->a), materialIrradience(material->b)), 0.5);
}