Files
PhotonMF/directional_light.cpp

43 lines
905 B
C++
Raw Normal View History

2017-01-02 04:23:48 -04:00
#include <limits>
#include <glm/glm.hpp>
#include <glm/gtc/constants.hpp>
#include "directional_light.hpp"
2017-01-02 04:23:48 -04:00
using std::numeric_limits;
using glm::pi;
using glm::reflect;
using glm::dot;
2017-01-02 00:23:04 -04:00
using glm::pow;
using glm::max;
2017-01-02 04:23:48 -04:00
inline vec3 DirectionalLight::direction(vec3 point) {
return m_position;
}
inline float DirectionalLight::distance(vec3 point) {
return numeric_limits<float>::max();
}
2017-01-05 06:16:14 -04:00
vec3 DirectionalLight::diffuse(vec3 normal, Ray & r, float t, Material & m) const {
float n_dot_l;
vec3 color;
2017-01-02 00:23:04 -04:00
n_dot_l = max(dot(normal, m_position), 0.0f);
2017-01-05 06:16:14 -04:00
color += m_diffuse * n_dot_l;
return color;
}
vec3 DirectionalLight::specular(vec3 normal, Ray & r, float t, Material & m) const {
float r_dot_l;
vec3 color, ref;
ref = reflect(m_position, normal);
r_dot_l = pow(max(dot(ref, r.m_direction), 0.0f), m.m_shininess);
color += m.m_specular * m_specular * r_dot_l;
return color;
}