Separated BRDF from light source.

This commit is contained in:
Miguel Angel Astor Romero
2017-01-11 14:51:21 -04:00
parent a9670e93f0
commit f150f8f24c
13 changed files with 94 additions and 66 deletions

19
phong_brdf.cpp Normal file
View File

@@ -0,0 +1,19 @@
#include "glm/glm.hpp"
#include "phong_brdf.hpp"
using glm::reflect;
using glm::pow;
using glm::max;
using glm::dot;
vec3 PhongBRDF::diffuse(vec3 light_dir, vec3 surface_normal, Ray & incident_ray, vec3 light_diff_color) const {
float n_dot_l = max(dot(surface_normal, light_dir), 0.0f);
return light_diff_color * n_dot_l;
}
vec3 PhongBRDF::specular(vec3 light_dir, vec3 surface_normal, Ray & incident_ray, vec3 light_spec_color, float shininess) const {
vec3 ref = reflect(light_dir, surface_normal);
float r_dot_l = pow(max(dot(ref, incident_ray.m_direction), 0.0f), shininess);
return light_spec_color * r_dot_l;
}