-
Notifications
You must be signed in to change notification settings - Fork 0
/
PointLight.h
73 lines (61 loc) · 1.78 KB
/
PointLight.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
#pragma once
#include "Mesh.h"
#include "LightBase.h"
#include "FrameBuffer.h"
#include <memory>
/*
* for now point light shadow(omnidirectional shadow) only impl in PhongWithShadow.hpp(hard shadow)
* not in PCSS !
* but point light can still work with PCSS(and hardshadow) as a spot light
* when GetLightMVP, can use one of 6 existing vps, or change it manually for a moment
*/
class PointLight final: public LightBase
{
private:
float fov{ 3.1415926 * 0.5f };
float aspect{ 1.0f };
float size{ 2.0f };
Mesh mesh;
const glm::vec3 directions[6]{
{0.0f, 0.0f, 1.0f},//front
{0.0f, 0.0f, -1.0f},//back
{0.0f, 1.0f, 0.0f},//bottom
{0.0f, -1.0f, 0.0f},//top
{1.0f, 0.0f, 0.0f},//left
{-1.0f, 0.0f, 0.0f},//right
};
const glm::vec3 ups[6]{
{0.0f, 1.0f, 0.0f},
{0.0f, 1.0f, 0.0f},
{0.0f, 0.0f, -1.0f},
{0.0f, 0.0f, 1.0f},
{0.0f, 1.0f, 0.0f},
{0.0f, 1.0f, 0.0f},
};
glm::mat4 vps[6];
float invH;
float invW;
void UpdateVPs(void);
public:
PointLight(const glm::vec3& pos);
// change the size of the light
PointLight& WithSize(const float r);
LightBase& WithPosition(const glm::vec3& pos) override;
LightBase& WithIntensity(const glm::vec3& i) override;
LightBase& WithNearZ(const float z) override;
LightBase& WithFarZ(const float z) override;
public:
glm::vec3 GetDirection(const glm::vec3& pos) override;
glm::mat4 GetLightModelMatrix(void) override;
glm::mat4 GetLightMVP(const glm::mat4& model, int slot) override;
Mesh& GetLightMesh(void) override;
public:
const float GetLightWorldSize(void) const;
const float GetLightFrustumSize(void) const;
private:
std::unique_ptr<FrameBuffer> shadow_map[6];
public:
void EnableShadowMap(int scale) override;
float LookUpShadowMap(const glm::vec4& shadowCoord) override;
FrameBuffer* GetShadowMap(int slot) override;
};