-
Notifications
You must be signed in to change notification settings - Fork 0
/
area_light.hpp
65 lines (54 loc) · 1.49 KB
/
area_light.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef AREA_LIGHT_H
#define AREA_LIGHT_H
#include <random>
#include "light.hpp"
#include "vec3.hpp"
#include "quad.hpp"
using namespace std;
std::random_device rd1;
std::mt19937 gen1(rd1());
std::uniform_real_distribution<float> pos_distribution(-1.0f, 1.0f);
class area_light : public light
{
public:
area_light(point3 Q, vec3 u, vec3 v, color col, double brightness, int samples)
{
this->geo = quad(Q, u, v);
this->col = col;
this->brightness = brightness;
this->samples = samples;
isArea = true;
}
vec3 get_light_direction(point3 intersect)
{
light_pos = (geo.u/samples) * (i + pos_distribution(gen1)/samples) + (geo.v/samples) * (j + pos_distribution(gen1)/samples) + geo.Q;
if (i == samples)
{
this->i = 0;
this->j++;
if (j == samples)
{
this-> j = 0;
}
}
else
{
i++;
}
return unit_vector(light_pos - intersect);
}
float intensity(point3 intersect)
{
vec3 dir = light_pos-intersect;
double dist_squared = dir.length_squared();
return brightness/dist_squared;
}
private:
quad geo;
color col;
double brightness;
point3 light_pos;
int i = 0;
int j = 0;
};
#endif