]> git.lizzy.rs Git - minetest.git/blob - src/client/shadows/dynamicshadows.h
Add keybind to swap items between hands
[minetest.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 #include "constants.h"
26
27 class Camera;
28 class Client;
29
30 struct shadowFrustum
31 {
32         f32 zNear{0.0f};
33         f32 zFar{0.0f};
34         f32 length{0.0f};
35         f32 radius{0.0f};
36         core::matrix4 ProjOrthMat;
37         core::matrix4 ViewMat;
38         v3f position;
39         v3f player;
40         v3s16 camera_offset;
41 };
42
43 class DirectionalLight
44 {
45 public:
46         DirectionalLight(const u32 shadowMapResolution,
47                         const v3f &position,
48                         video::SColorf lightColor = video::SColor(0xffffffff),
49                         f32 farValue = 100.0f);
50         ~DirectionalLight() = default;
51
52         //DISABLE_CLASS_COPY(DirectionalLight)
53
54         void update_frustum(const Camera *cam, Client *client, bool force = false);
55
56         // when set direction is updated to negative normalized(direction)
57         void setDirection(v3f dir);
58         v3f getDirection() const{
59                 return direction;
60         };
61         v3f getPosition() const;
62         v3f getPlayerPos() const;
63         v3f getFuturePlayerPos() const;
64
65         /// Gets the light's matrices.
66         const core::matrix4 &getViewMatrix() const;
67         const core::matrix4 &getProjectionMatrix() const;
68         const core::matrix4 &getFutureViewMatrix() const;
69         const core::matrix4 &getFutureProjectionMatrix() const;
70         core::matrix4 getViewProjMatrix();
71
72         /// Gets the light's maximum far value, i.e. the shadow boundary
73         f32 getMaxFarValue() const
74         {
75                 return farPlane * BS;
76         }
77
78         /// Gets the current far value of the light
79         f32 getFarValue() const
80         {
81                 return shadow_frustum.zFar;
82         }
83
84
85         /// Gets the light's color.
86         const video::SColorf &getLightColor() const
87         {
88                 return diffuseColor;
89         }
90
91         /// Sets the light's color.
92         void setLightColor(const video::SColorf &lightColor)
93         {
94                 diffuseColor = lightColor;
95         }
96
97         /// Gets the shadow map resolution for this light.
98         u32 getMapResolution() const
99         {
100                 return mapRes;
101         }
102
103         bool should_update_map_shadow{true};
104
105         void commitFrustum();
106
107 private:
108         void createSplitMatrices(const Camera *cam);
109
110         video::SColorf diffuseColor;
111
112         f32 farPlane;
113         u32 mapRes;
114
115         v3f pos;
116         v3f direction{0};
117
118         v3f last_cam_pos_world{0,0,0};
119         v3f last_look{0,1,0};
120
121         shadowFrustum shadow_frustum;
122         shadowFrustum future_frustum;
123         bool dirty{false};
124 };