summaryrefslogtreecommitdiff
path: root/gfx/gl/shadowMapper.h
blob: bdbd39f59e42da2d84a624b8727fac26c5756528 (plain)
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
#pragma once

#include "lib/glArrays.h"
#include "program.h"
#include <glm/vec2.hpp>

class SceneProvider;
class Camera;

#include <gfx/models/texture.h>
class ShadowMapper {
public:
	explicit ShadowMapper(const glm::ivec2 & size);

	static constexpr std::size_t SHADOW_BANDS {4};
	struct Definitions {
		std::array<glm::mat4x4, SHADOW_BANDS> projections;
		std::array<glm::vec4, SHADOW_BANDS> regions;
		size_t maps {};
	};
	Definitions update(const SceneProvider &, const glm::vec3 & direction, const Camera &) const;

	class FixedPoint : public Program {
	public:
		FixedPoint();
		void setViewProjection(const glm::mat4 &) const;
		void use() const;

	private:
		RequiredUniformLocation viewProjectionLoc;
	};
	class DynamicPoint : public Program {
	public:
		DynamicPoint();
		void setViewProjection(const glm::mat4 &) const;
		void use(const Location &) const;

	private:
		RequiredUniformLocation viewProjectionLoc;
		RequiredUniformLocation modelLoc;
	};
	FixedPoint fixedPoint;
	DynamicPoint dynamicPoint;

	operator GLuint() const
	{
		return depthMap;
	}

private:
	glFrameBuffer depthMapFBO;
	glTexture depthMap;
	glm::ivec2 size;
};