-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathphong.cpp
More file actions
47 lines (43 loc) · 1.33 KB
/
phong.cpp
File metadata and controls
47 lines (43 loc) · 1.33 KB
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
//
// Created by kevin on 12/09/18.
//
#include "phong.h"
#include "scene.h"
#include "rayon.h"
/**
* Construct a phong material.
* @param ka Ambient coef
* @param kd Diffusion coef
* @param ks Specular coef
*/
Phong::Phong(const glm::vec3& ka, const glm::vec3& kd, float ks, float reflection) : ka(ka), kd(kd), ks(ks), reflection(reflection) {}
/**
* Construct a phong material with r-value.
* @param ka Ambient coef
* @param kd Diffusion coef
* @param ks Specular coef
*/
Phong::Phong(glm::vec3&& ka, glm::vec3&& kd, float ks, float reflection) : ka(ka), kd(kd), ks(ks), reflection(reflection) {}
/**
*
* @param I
* @param point
* @param s
* @param rayon
* @param rec
* @return
*/
glm::vec3 Phong::computeColour(const Intersection& I, const glm::vec3& point, const Scene& s, const Rayon& rayon, int rec) {
glm::vec3 diff, spec;
for (auto&& light : s.Lights) {
/*
* Diffus = max(N.L, 0) * Kd * Lc
* Speculaire= Lc * max(V.R, 0)^Ks
* R, V, N, L = direction = vecteur normé
*/
glm::vec3 L = glm::normalize(light->getPosition() - point), R = glm::normalize(glm::reflect(L, I.getNormal()));
diff = glm::max(glm::dot(I.getNormal(), L), 0.0f) * this->kd * light->getCouleur();
spec = light->getCouleur() * this->reflection * glm::pow(glm::max(glm::dot(rayon.Vect(), R), 0.0f), this->ks);
}
return ka + diff + spec;
}