sphere and disk area lights mostly ready (I think :S).

This commit is contained in:
2017-02-09 23:37:40 -04:00
parent 944ae05db7
commit 0cdc7c46ca
30 changed files with 512 additions and 83 deletions

View File

@@ -2,12 +2,14 @@
#ifndef LIGHT_HPP
#define LIGHT_HPP
#include <glm/vec3.hpp>
#include <glm/glm.hpp>
#include "figure.hpp"
#include "material.hpp"
#include "ray.hpp"
using glm::vec3;
using glm::length;
class Light {
public:
@@ -19,53 +21,60 @@ public:
Light(): m_position(vec3(0.0f)), m_diffuse(vec3(1.0f)), m_specular(vec3(1.0f)) { }
Light(vec3 _p, vec3 _d, vec3 _s): m_position(_p), m_diffuse(_d), m_specular(_s) { }
Light(ltype_t _t): m_position(vec3(0.0f)), m_diffuse(vec3(1.0f)), m_specular(vec3(1.0f)), m_type(_t) { }
Light(vec3 _p, vec3 _d, vec3 _s, ltype_t _t): m_position(_p), m_diffuse(_d), m_specular(_s), m_type(_t) { }
virtual ~Light() { }
virtual ltype_t light_type() {
return type;
return m_type;
}
virtual vec3 direction(vec3 point) = 0;
virtual float distance(vec3 point) = 0;
virtual vec3 direction(vec3 point) const = 0;
virtual float distance(vec3 point) const = 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;
ltype_t m_type;
};
class InfinitesimalLight: public Light {
public:
InfinitesimalLight(): Light() {
type = INFINITESIMAL;
}
InfinitesimalLight(): Light(INFINITESIMAL) { }
InfinitesimalLight(vec3 _p, vec3 _d, vec3 _s): Light(_p, _d, _s) {
type = INFINITESIMAL;
}
InfinitesimalLight(vec3 _p, vec3 _d, vec3 _s): Light(_p, _d, _s, INFINITESIMAL) { }
virtual vec3 direction(vec3 point) = 0;
virtual float distance(vec3 point) = 0;
virtual vec3 direction(vec3 point) const = 0;
virtual float distance(vec3 point) const = 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;
Figure * m_figure;
AreaLight(): Light(AREA), m_figure(NULL), m_last_sample(vec3()), m_n_at_last_sample(vec3()) { }
AreaLight(Figure * _f): Light(AREA), m_figure(_f), m_last_sample(vec3()), m_n_at_last_sample(vec3()) { }
virtual vec3 direction(vec3 point) const {
return m_last_sample - point;
}
AreaLight(vec3 _p, vec3 _d, vec3 _s): Light(_p, _d, _s) {
type = AREA;
virtual float distance(vec3 point) const {
return length(m_last_sample - point);
}
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;
virtual void sample_at_surface(vec3 point) = 0;
protected:
vec3 m_last_sample;
vec3 m_n_at_last_sample;
};
#endif