New way of handling lights and materials.

This commit is contained in:
2017-01-01 20:57:35 -04:00
parent 2b1a9ed819
commit c78a8d284f
13 changed files with 141 additions and 108 deletions

26
directional_light.cpp Normal file
View File

@@ -0,0 +1,26 @@
#include <cmath>
#include <glm/glm.hpp>
#include <glm/gtc/constants.hpp>
#include "directional_light.hpp"
using glm::pi;
using glm::reflect;
using glm::dot;
vec3 DirectionalLight::shade(vec3 normal, Ray & r, Material & m) const {
float n_dot_l, r_dot_l;
vec3 color, ref;
//color = m.m_ambient * m_ambient;
n_dot_l = max(dot(normal, m_position), 0.0);
color += (m.m_diffuse / pi<float>()) * m_diffuse * n_dot_l;
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;
}