Minetest 5.10.0-dev
 
Loading...
Searching...
No Matches
dynamicshadows.h
Go to the documentation of this file.
1/*
2Minetest
3Copyright (C) 2021 Liso <anlismon@gmail.com>
4
5This program is free software; you can redistribute it and/or modify
6it under the terms of the GNU Lesser General Public License as published by
7the Free Software Foundation; either version 2.1 of the License, or
8(at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU Lesser General Public License for more details.
14
15You should have received a copy of the GNU Lesser General Public License along
16with this program; if not, write to the Free Software Foundation, Inc.,
1751 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18*/
19
20#pragma once
21
23#include <matrix4.h>
24#include "util/basic_macros.h"
25#include "constants.h"
26
27class Camera;
28class Client;
29
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;
41};
42
44{
45public:
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);
59 return direction;
60 };
61 v3f getPosition() const;
62 v3f getPlayerPos() const;
63 v3f getFuturePlayerPos() const;
64
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
73 f32 getMaxFarValue() const
74 {
75 return farPlane * BS;
76 }
77
79 f32 getFarValue() const
80 {
81 return shadow_frustum.zFar;
82 }
83
84
86 const video::SColorf &getLightColor() const
87 {
88 return diffuseColor;
89 }
90
92 void setLightColor(const video::SColorf &lightColor)
93 {
94 diffuseColor = lightColor;
95 }
96
98 u32 getMapResolution() const
99 {
100 return mapRes;
101 }
102
104
105 void commitFrustum();
106
107private:
108 void createSplitMatrices(const Camera *cam);
109
110 video::SColorf diffuseColor;
111
114
117
120
123 bool dirty{false};
124};
static v2f dir(const v2f &pos_dist)
Definition camera.cpp:205
Definition camera.h:83
Definition client.h:118
Definition dynamicshadows.h:44
v3f getPlayerPos() const
Definition dynamicshadows.cpp:168
bool should_update_map_shadow
Definition dynamicshadows.h:103
u32 getMapResolution() const
Gets the shadow map resolution for this light.
Definition dynamicshadows.h:98
DirectionalLight(const u32 shadowMapResolution, const v3f &position, video::SColorf lightColor=video::SColor(0xffffffff), f32 farValue=100.0f)
Definition dynamicshadows.cpp:107
void commitFrustum()
Definition dynamicshadows.cpp:148
core::matrix4 getViewProjMatrix()
Definition dynamicshadows.cpp:198
void setDirection(v3f dir)
Definition dynamicshadows.cpp:157
~DirectionalLight()=default
bool dirty
Definition dynamicshadows.h:123
f32 getFarValue() const
Gets the current far value of the light.
Definition dynamicshadows.h:79
f32 getMaxFarValue() const
Gets the light's maximum far value, i.e. the shadow boundary.
Definition dynamicshadows.h:73
const core::matrix4 & getFutureViewMatrix() const
Definition dynamicshadows.cpp:188
shadowFrustum shadow_frustum
Definition dynamicshadows.h:121
v3f getPosition() const
Definition dynamicshadows.cpp:163
void createSplitMatrices(const Camera *cam)
Definition dynamicshadows.cpp:43
v3f last_look
Definition dynamicshadows.h:119
void setLightColor(const video::SColorf &lightColor)
Sets the light's color.
Definition dynamicshadows.h:92
v3f direction
Definition dynamicshadows.h:116
const core::matrix4 & getViewMatrix() const
Gets the light's matrices.
Definition dynamicshadows.cpp:178
video::SColorf diffuseColor
Definition dynamicshadows.h:110
const core::matrix4 & getProjectionMatrix() const
Definition dynamicshadows.cpp:183
v3f getFuturePlayerPos() const
Definition dynamicshadows.cpp:173
void update_frustum(const Camera *cam, Client *client, bool force=false)
Definition dynamicshadows.cpp:114
v3f last_cam_pos_world
Definition dynamicshadows.h:118
v3f pos
Definition dynamicshadows.h:115
u32 mapRes
Definition dynamicshadows.h:113
v3f getDirection() const
Definition dynamicshadows.h:58
f32 farPlane
Definition dynamicshadows.h:112
const video::SColorf & getLightColor() const
Gets the light's color.
Definition dynamicshadows.h:86
const core::matrix4 & getFutureProjectionMatrix() const
Definition dynamicshadows.cpp:193
shadowFrustum future_frustum
Definition dynamicshadows.h:122
#define BS
Definition constants.h:76
core::vector3d< s16 > v3s16
Definition irr_v3d.h:28
core::vector3df v3f
Definition irr_v3d.h:26
Definition activeobjectmgr.cpp:26
Definition dynamicshadows.h:31
f32 radius
Definition dynamicshadows.h:35
v3f position
Definition dynamicshadows.h:38
f32 zFar
Definition dynamicshadows.h:33
f32 length
Definition dynamicshadows.h:34
v3f player
Definition dynamicshadows.h:39
v3s16 camera_offset
Definition dynamicshadows.h:40
f32 zNear
Definition dynamicshadows.h:32
core::matrix4 ViewMat
Definition dynamicshadows.h:37
core::matrix4 ProjOrthMat
Definition dynamicshadows.h:36