Added groundwork for area lights. Added irony-mode CDB.

This commit is contained in:
Miguel Angel Astor Romero
2017-02-07 16:41:58 -04:00
parent fd1dc0febd
commit 944ae05db7
7 changed files with 76 additions and 19 deletions

5
.clang_complete Normal file
View File

@@ -0,0 +1,5 @@
-ansi
-pedantic
-Wall
-DGLM_FORCE_RADIANS
-fopenmp

View File

@@ -8,11 +8,11 @@
using glm::normalize;
class DirectionalLight: public Light {
class DirectionalLight: public InfinitesimalLight {
public:
DirectionalLight(): Light() { }
DirectionalLight(): InfinitesimalLight() { }
DirectionalLight(vec3 _p, vec3 _d, vec3 _s): Light(normalize(_p), _d, _s) { }
DirectionalLight(vec3 _p, vec3 _d, vec3 _s): InfinitesimalLight(normalize(_p), _d, _s) { }
virtual vec3 direction(vec3 point);
virtual float distance(vec3 point);

View File

@@ -11,6 +11,8 @@ using glm::vec3;
class Light {
public:
typedef enum LIGHT_TYPE { INFINITESIMAL = 0, AREA } ltype_t;
vec3 m_position;
vec3 m_diffuse;
vec3 m_specular;
@@ -21,6 +23,45 @@ public:
virtual ~Light() { }
virtual ltype_t light_type() {
return type;
}
virtual vec3 direction(vec3 point) = 0;
virtual float distance(vec3 point) = 0;
virtual vec3 diffuse(vec3 normal, Ray & r, vec3 i_pos, Material & m) const = 0;
virtual vec3 specular(vec3 normal, Ray & r, vec3 i_pos, Material & m) const = 0;
protected:
ltype_t type;
};
class InfinitesimalLight: public Light {
public:
InfinitesimalLight(): Light() {
type = INFINITESIMAL;
}
InfinitesimalLight(vec3 _p, vec3 _d, vec3 _s): Light(_p, _d, _s) {
type = INFINITESIMAL;
}
virtual vec3 direction(vec3 point) = 0;
virtual float distance(vec3 point) = 0;
virtual vec3 diffuse(vec3 normal, Ray & r, vec3 i_pos, Material & m) const = 0;
virtual vec3 specular(vec3 normal, Ray & r, vec3 i_pos, Material & m) const = 0;
};
class AreaLight: public Light {
public:
AreaLight(): Light() {
type = AREA;
}
AreaLight(vec3 _p, vec3 _d, vec3 _s): Light(_p, _d, _s) {
type = AREA;
}
virtual vec3 direction(vec3 point) = 0;
virtual float distance(vec3 point) = 0;
virtual vec3 diffuse(vec3 normal, Ray & r, vec3 i_pos, Material & m) const = 0;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 189 KiB

After

Width:  |  Height:  |  Size: 402 KiB

View File

@@ -42,6 +42,7 @@ vec3 PathTracer::trace_ray(Ray & r, Scene * s, unsigned int rec_level) const {
// For every light source
vis = true;
if (s->m_lights[l]->light_type() == Light::INFINITESIMAL) {
// Cast a shadow ray to determine visibility.
sr = Ray(s->m_lights[l]->direction(i_pos), i_pos + n * BIAS);
for (size_t f = 0; f < s->m_figures.size(); f++) {
@@ -50,6 +51,10 @@ vec3 PathTracer::trace_ray(Ray & r, Scene * s, unsigned int rec_level) const {
break;
}
}
} else if (s->m_lights[l]->light_type() == Light::AREA) {
// Area lights not supported with Whitted ray tracing.
vis = false;
}
// Evaluate the shading model accounting for visibility.
dir_diff_color += vis ? s->m_lights[l]->diffuse(n, r, i_pos, *_f->m_mat) : vec3(0.0f);

View File

@@ -4,15 +4,15 @@
#include "light.hpp"
class PointLight: public Light {
class PointLight: public InfinitesimalLight {
public:
float m_const_att;
float m_lin_att;
float m_quad_att;
PointLight(): Light(), m_const_att(1.0f), m_lin_att(0.0f), m_quad_att(0.0f) { }
PointLight(): InfinitesimalLight(), m_const_att(1.0f), m_lin_att(0.0f), m_quad_att(0.0f) { }
PointLight(vec3 _p, vec3 _d, vec3 _s, float _c, float _l, float _q): Light(_p, _d, _s), m_const_att(_c), m_lin_att(_l), m_quad_att(_q) { }
PointLight(vec3 _p, vec3 _d, vec3 _s, float _c, float _l, float _q): InfinitesimalLight(_p, _d, _s), m_const_att(_c), m_lin_att(_l), m_quad_att(_q) { }
virtual vec3 direction(vec3 point);
virtual float distance(vec3 point);

View File

@@ -36,11 +36,13 @@ vec3 WhittedTracer::trace_ray(Ray & r, Scene * s, unsigned int rec_level) const
// Check if the material is not reflective/refractive.
if (!_f->m_mat->m_refract) {
// Calculate the direct lighting.
for (size_t l = 0; l < s->m_lights.size(); l++) {
// For every light source
vis = true;
if (s->m_lights[l]->light_type() == Light::INFINITESIMAL) {
// Cast a shadow ray to determine visibility.
sr = Ray(s->m_lights[l]->direction(i_pos), i_pos + n * BIAS);
for (size_t f = 0; f < s->m_figures.size(); f++) {
@@ -49,6 +51,10 @@ vec3 WhittedTracer::trace_ray(Ray & r, Scene * s, unsigned int rec_level) const
break;
}
}
} else if (s->m_lights[l]->light_type() == Light::AREA) {
// Area lights not supported with Whitted ray tracing.
vis = false;
}
// Evaluate the shading model accounting for visibility.
dir_diff_color += vis ? s->m_lights[l]->diffuse(n, r, i_pos, *_f->m_mat) : vec3(0.0f);