]> git.lizzy.rs Git - dragonfireclient.git/blob - src/client/shadows/dynamicshadows.h
Remove unused ITextSceneNode header (#11476)
[dragonfireclient.git] / src / client / shadows / dynamicshadows.h
1 /*
2 Minetest
3 Copyright (C) 2021 Liso <anlismon@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #pragma once
21
22 #include "irrlichttypes_bloated.h"
23 #include <matrix4.h>
24 #include "util/basic_macros.h"
25
26 class Camera;
27 class Client;
28
29 struct shadowFrustum
30 {
31         float zNear{0.0f};
32         float zFar{0.0f};
33         float length{0.0f};
34         core::matrix4 ProjOrthMat;
35         core::matrix4 ViewMat;
36         v3f position;
37 };
38
39 class DirectionalLight
40 {
41 public:
42         DirectionalLight(const u32 shadowMapResolution,
43                         const v3f &position,
44                         video::SColorf lightColor = video::SColor(0xffffffff),
45                         f32 farValue = 100.0f);
46         ~DirectionalLight() = default;
47
48         //DISABLE_CLASS_COPY(DirectionalLight)
49
50         void update_frustum(const Camera *cam, Client *client);
51
52         // when set direction is updated to negative normalized(direction)
53         void setDirection(v3f dir);
54         v3f getDirection() const{
55                 return direction;
56         };
57         v3f getPosition() const;
58
59         /// Gets the light's matrices.
60         const core::matrix4 &getViewMatrix() const;
61         const core::matrix4 &getProjectionMatrix() const;
62         core::matrix4 getViewProjMatrix();
63
64         /// Gets the light's far value.
65         f32 getMaxFarValue() const
66         {
67                 return farPlane;
68         }
69
70
71         /// Gets the light's color.
72         const video::SColorf &getLightColor() const
73         {
74                 return diffuseColor;
75         }
76
77         /// Sets the light's color.
78         void setLightColor(const video::SColorf &lightColor)
79         {
80                 diffuseColor = lightColor;
81         }
82
83         /// Gets the shadow map resolution for this light.
84         u32 getMapResolution() const
85         {
86                 return mapRes;
87         }
88
89         bool should_update_map_shadow{true};
90
91 private:
92         void createSplitMatrices(const Camera *cam);
93
94         video::SColorf diffuseColor;
95
96         f32 farPlane;
97         u32 mapRes;
98
99         v3f pos;
100         v3f direction{0};
101         shadowFrustum shadow_frustum;
102 };