-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlastic.cpp
47 lines (38 loc) · 927 Bytes
/
Plastic.cpp
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
#include "Plastic.h"
Plastic::Plastic():
ambientBRDF(NULL),
diffuseBRDF(NULL),
specularBRDF(NULL) {
}
Plastic::~Plastic() {
}
void Plastic::setAmbientBRDF(BRDF * ambient) {
ambientBRDF = ambient;
}
void Plastic::setDiffuseBRDF(BRDF * diffuse) {
diffuseBRDF = diffuse;
}
void Plastic::setSpecularBRDF(BRDF * specular) {
specularBRDF = specular;
}
RGBColor Plastic::shade(ShadeRec &sr) {
Vector wo = -sr.ray.d;
RGBColor L = COLOR_BLACK;
if(ambientBRDF != NULL) {
L += ambientBRDF->rho(sr, wo) * sr.w.ambient->L(sr);
}
int num_lights = sr.w.lights.size();
for(int j = 0; j < num_lights; j++) {
Vector wi = sr.w.lights[j]->getDirection(sr);
RTdouble n_dot_wi = sr.normal * wi;
if(n_dot_wi > RT_ZERO) {
if(diffuseBRDF != NULL) {
L += diffuseBRDF->f(sr, wo, wi);
}
if(specularBRDF != NULL) {
L += specularBRDF->f(sr, wo, wi) * sr.w.lights[j]->L(sr) * n_dot_wi;
}
}
}
return L;
}