-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMatte.cpp
78 lines (63 loc) · 1.66 KB
/
Matte.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
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
74
75
76
77
78
#include "Constants.h"
#include "Matte.h"
#include "Light.h"
#include "ShadeRec.h"
#include "World.h"
Matte::Matte():
Material(),
ambientBRDF(new Lambertian),
diffuseBRDF(new Lambertian){
}
Matte::~Matte() {
if(ambientBRDF != NULL) {
delete ambientBRDF;
ambientBRDF = NULL;
}
if(diffuseBRDF != NULL) {
delete diffuseBRDF;
diffuseBRDF = NULL;
}
}
void Matte::set_ka(const RTdouble &ka) {
ambientBRDF->set_kd(ka);
}
void Matte::set_kd(const RTdouble &kd) {
diffuseBRDF->set_kd(kd);
}
void Matte::set_cd(const RGBColor &cd) {
ambientBRDF->set_cd(cd);
diffuseBRDF->set_cd(cd);
}
RGBColor Matte::shade(ShadeRec &sr) {
Vector wo = -sr.ray.d;
RGBColor 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) {
L += diffuseBRDF->f(sr, wo, wi) * sr.w.lights[j]->L(sr) * n_dot_wi;
}
}
return L;
}
RGBColor Matte::areaLightShade(ShadeRec &sr) {
Vector wo = -sr.ray.d;
RGBColor 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) {
bool inShadow = false;
if(sr.w.lights[j]->castShadows()) {
Ray shadowRay(sr.hit_point, wi);
inShadow = sr.w.lights[j]->inShadow(shadowRay, sr);
}
if(inShadow) {
L += diffuseBRDF->f(sr, wo, wi) * sr.w.lights[j]->L(sr) * n_dot_wi; // G? pdf?
}
}
}
return L;
}