-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAreaLight.h
More file actions
83 lines (65 loc) · 2.41 KB
/
AreaLight.h
File metadata and controls
83 lines (65 loc) · 2.41 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// ----------------------------------------------------------------------------------------------------
//
// File name: AreaLight.h
// Created By: Haard Panchal
// Create Date: 03/16/2020
//
// Description:
// File has the definition and implementation of the AreaLight class
// The point light disperses ray from a single point p_0
//
// History:
// 03/16/19: H. Panchal Created the file
//
// Declaration:
//
// ----------------------------------------------------------------------------------------------------
#ifndef AREALIGHTH
#define AREALIGHTH
#include <curand_kernel.h>
#include "Vector3.h"
#include "Light.h"
class AreaLight : public Light {
private:
Vector3 c_0; // Position of the origin of the area
Vector3 c_c; // Position of the center of the area
Vector3 n_0, n_1; // Normal to the area
Vector3 a_n, a_up; // The up vector for the area
float w, h; // Width and height of the area
Vector3 current_position; // The position of the current sample of the area light
public:
__device__ AreaLight();
__device__ AreaLight(Vector3& position, Vector3& normal, Vector3& up, float width, float height);
__device__ ~AreaLight();
__device__ void setRandomSamplePosition(curandState& rand_state);
__device__ Vector3 getLightAtPoint(Vector3& point);
__device__ Vector3 getLightPosition() { return current_position; }
__device__ bool ifSamplingRequired() {return true; }
};
__device__ AreaLight::AreaLight() {}
__device__ AreaLight::AreaLight(Vector3& position, Vector3& normal, Vector3& up, float width, float height)
: c_c(position), a_n(normal), a_up(up), w(width), h(height) {
a_n.make_unit_vector();
a_up.make_unit_vector();
n_0 = cross(a_n, a_up);
n_0.make_unit_vector();
n_1 = cross(n_0, a_n);
n_1.make_unit_vector();
c_0 = c_c - (w / 2.0f) * n_0 - (h / 2.0f) * n_1;
current_position = c_c;
}
__device__ AreaLight::~AreaLight() {}
__device__ Vector3 AreaLight::getLightAtPoint(Vector3& point) {
Vector3 p = point - current_position;
p.make_unit_vector();
return p;
}
__device__ void AreaLight::setRandomSamplePosition(curandState& rand_state) {
float x = curand_uniform(&rand_state) * w;
float y = curand_uniform(&rand_state) * h;
#ifdef AREALIGHTDEBUG
printf("X: %f\n", x);
#endif
current_position = c_0 + x * n_0 + y * n_1;
}
#endif