Added groundwork for area lights. Added irony-mode CDB.
This commit is contained in:
5
.clang_complete
Normal file
5
.clang_complete
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
-ansi
|
||||||
|
-pedantic
|
||||||
|
-Wall
|
||||||
|
-DGLM_FORCE_RADIANS
|
||||||
|
-fopenmp
|
@@ -8,11 +8,11 @@
|
|||||||
|
|
||||||
using glm::normalize;
|
using glm::normalize;
|
||||||
|
|
||||||
class DirectionalLight: public Light {
|
class DirectionalLight: public InfinitesimalLight {
|
||||||
public:
|
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 vec3 direction(vec3 point);
|
||||||
virtual float distance(vec3 point);
|
virtual float distance(vec3 point);
|
||||||
|
41
light.hpp
41
light.hpp
@@ -11,6 +11,8 @@ using glm::vec3;
|
|||||||
|
|
||||||
class Light {
|
class Light {
|
||||||
public:
|
public:
|
||||||
|
typedef enum LIGHT_TYPE { INFINITESIMAL = 0, AREA } ltype_t;
|
||||||
|
|
||||||
vec3 m_position;
|
vec3 m_position;
|
||||||
vec3 m_diffuse;
|
vec3 m_diffuse;
|
||||||
vec3 m_specular;
|
vec3 m_specular;
|
||||||
@@ -21,6 +23,45 @@ public:
|
|||||||
|
|
||||||
virtual ~Light() { }
|
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 vec3 direction(vec3 point) = 0;
|
||||||
virtual float distance(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 diffuse(vec3 normal, Ray & r, vec3 i_pos, Material & m) const = 0;
|
||||||
|
BIN
output.png
BIN
output.png
Binary file not shown.
Before Width: | Height: | Size: 189 KiB After Width: | Height: | Size: 402 KiB |
@@ -42,13 +42,18 @@ vec3 PathTracer::trace_ray(Ray & r, Scene * s, unsigned int rec_level) const {
|
|||||||
// For every light source
|
// For every light source
|
||||||
vis = true;
|
vis = true;
|
||||||
|
|
||||||
// Cast a shadow ray to determine visibility.
|
if (s->m_lights[l]->light_type() == Light::INFINITESIMAL) {
|
||||||
sr = Ray(s->m_lights[l]->direction(i_pos), i_pos + n * BIAS);
|
// Cast a shadow ray to determine visibility.
|
||||||
for (size_t f = 0; f < s->m_figures.size(); f++) {
|
sr = Ray(s->m_lights[l]->direction(i_pos), i_pos + n * BIAS);
|
||||||
if (s->m_figures[f]->intersect(sr, _t) && _t < s->m_lights[l]->distance(i_pos)) {
|
for (size_t f = 0; f < s->m_figures.size(); f++) {
|
||||||
vis = false;
|
if (s->m_figures[f]->intersect(sr, _t) && _t < s->m_lights[l]->distance(i_pos)) {
|
||||||
break;
|
vis = false;
|
||||||
|
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.
|
// Evaluate the shading model accounting for visibility.
|
||||||
|
@@ -4,15 +4,15 @@
|
|||||||
|
|
||||||
#include "light.hpp"
|
#include "light.hpp"
|
||||||
|
|
||||||
class PointLight: public Light {
|
class PointLight: public InfinitesimalLight {
|
||||||
public:
|
public:
|
||||||
float m_const_att;
|
float m_const_att;
|
||||||
float m_lin_att;
|
float m_lin_att;
|
||||||
float m_quad_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 vec3 direction(vec3 point);
|
||||||
virtual float distance(vec3 point);
|
virtual float distance(vec3 point);
|
||||||
|
@@ -36,18 +36,24 @@ vec3 WhittedTracer::trace_ray(Ray & r, Scene * s, unsigned int rec_level) const
|
|||||||
|
|
||||||
// Check if the material is not reflective/refractive.
|
// Check if the material is not reflective/refractive.
|
||||||
if (!_f->m_mat->m_refract) {
|
if (!_f->m_mat->m_refract) {
|
||||||
|
|
||||||
// Calculate the direct lighting.
|
// Calculate the direct lighting.
|
||||||
for (size_t l = 0; l < s->m_lights.size(); l++) {
|
for (size_t l = 0; l < s->m_lights.size(); l++) {
|
||||||
// For every light source
|
// For every light source
|
||||||
vis = true;
|
vis = true;
|
||||||
|
|
||||||
// Cast a shadow ray to determine visibility.
|
if (s->m_lights[l]->light_type() == Light::INFINITESIMAL) {
|
||||||
sr = Ray(s->m_lights[l]->direction(i_pos), i_pos + n * BIAS);
|
// Cast a shadow ray to determine visibility.
|
||||||
for (size_t f = 0; f < s->m_figures.size(); f++) {
|
sr = Ray(s->m_lights[l]->direction(i_pos), i_pos + n * BIAS);
|
||||||
if (s->m_figures[f]->intersect(sr, _t) && _t < s->m_lights[l]->distance(i_pos)) {
|
for (size_t f = 0; f < s->m_figures.size(); f++) {
|
||||||
vis = false;
|
if (s->m_figures[f]->intersect(sr, _t) && _t < s->m_lights[l]->distance(i_pos)) {
|
||||||
break;
|
vis = false;
|
||||||
|
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.
|
// Evaluate the shading model accounting for visibility.
|
||||||
|
Reference in New Issue
Block a user