-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLight.h
116 lines (98 loc) · 3.58 KB
/
Light.h
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#ifndef _LIGHTNODE_H
#define _LIGHTNODE_H
#include "Graphics.h"
#include "Node.h"
#include "math/common.h"
#include "Renderer.h"
#include "Indicator.h"
class Light : public Indicator
{
public:
enum Type
{
NO_TYPE = 0, // don't change this
POINT,
DIRECTIONAL,
SPOT
};
Light():
m_Type(POINT),
m_Atten(glm::vec3(1.0f, 0.0f, 0.0f)),
m_LightFlags(0)
{
// TODO: Use light cutoffs for AABB, instead of temp:
m_Box.min = glm::vec3(-0.5f);
m_Box.max = glm::vec3(0.5f);
}
virtual ~Light() {}
// bind: to be called only by Scene during a render
// id is generated at time of render and may change!
bool bind(unsigned int id)
{
if(visible() && lightType())
{
// bind this light to shader uniform here (using id given)
// determine "vec" to be position or direction based on light type
glm::vec4 vec;
Type light_type = lightType();
if(light_type == POINT || light_type == SPOT)
{
vec = glm::vec4(position(Space::WORLD), 1.0);
}
else if (light_type == DIRECTIONAL)
{
// direcitonal lights can use local
vec = glm::vec4(position(), 1.0);
}
else
return false;
Renderer::get().bindLight(vec, m_Atten, m_Diffuse, id); // use diffuse light color only right now
return true;
}
return false;
}
virtual void logicSelf(unsigned int advance) {
/*static float offset = 0.0f;*/
//static float shift = 1.0f;
//if(offset > 5.0f)
//shift = -1.0f;
//else if(offset < 5.0f)
//shift = 1.0f;
//float timestep = advance * 0.001f;
//Node::move(glm::vec3(shift*timestep*10.0f, 0.0f, 0.0f));
/*offset += shift*timestep*10.0f;*/
}
virtual void renderSelf(IPartitioner* partitioner, unsigned int flags) const;
Color ambient() const { return m_Ambient; }
Color diffuse() const { return m_Diffuse; }
Color specular() const { return m_Specular; }
glm::vec3 attenuation() const { return m_Atten; }
Type lightType() const { return m_Type; }
void ambient(const Color& c) { m_Ambient = c; }
void diffuse(const Color& c) { m_Diffuse = c; }
void specular(const Color& c) { m_Specular = c; }
void atten(const glm::vec3& atten) { m_Atten = atten; }
void lightType(Type t) { m_Type = t; }
virtual SCOPED_ENUM_TYPE(NodeType) nodeType() const { return NodeType::LIGHT; }
virtual std::string nodeTypeString() const { return "light"; }
virtual const AABB* box(unsigned int flags = 0) const { return &m_Box; }
virtual AABB* box(unsigned int flags = 0) { return &m_Box; }
void lightFlags(unsigned int flags) {
m_LightFlags = flags;
}
unsigned int lightFlags() const {
return m_LightFlags;
}
private:
Color m_Ambient;
Color m_Diffuse;
Color m_Specular;
glm::vec3 m_Atten; // c, l, q
Type m_Type;
enum eLightFlags {
F_CAST_SHADOWS = BIT(0)
};
unsigned int m_LightFlags;
AABB m_Box;
};
#endif