Minetest 5.9.0-dev
 
Loading...
Searching...
No Matches
dynamicshadowsrender.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
22#include <string>
23#include <vector>
26
31
33{
36};
37
39{
40 NodeToApply(scene::ISceneNode *n,
41 E_SHADOW_MODE m = E_SHADOW_MODE::ESM_BOTH) :
42 node(n),
43 shadowMode(m){};
44 bool operator<(const NodeToApply &other) const { return node < other.node; };
45
46 scene::ISceneNode *node;
47
48 E_SHADOW_MODE shadowMode{E_SHADOW_MODE::ESM_BOTH};
49 bool dirty{false};
50};
51
53{
54public:
55 static const int TEXTURE_LAYER_SHADOW = 3;
56
57 ShadowRenderer(IrrlichtDevice *device, Client *client);
59
60 // Call before generating any shaders
61 // This is required because this class is initialized much later than all
62 // the shaders are dealt with.
63 static void preInit(IWritableShaderSource *shsrc);
64
65 void initialize();
66
69 size_t addDirectionalLight();
71 size_t getDirectionalLightCount() const;
72 f32 getMaxShadowFar() const;
73
79 void addNodeToShadowList(scene::ISceneNode *node,
80 E_SHADOW_MODE shadowMode = ESM_BOTH);
81 void removeNodeFromShadowList(scene::ISceneNode *node);
82
83 void update(video::ITexture *outputTarget = nullptr);
85 void drawDebug();
86
87 video::ITexture *get_texture()
88 {
90 }
91
92
93 bool is_active() const { return m_shadows_enabled && shadowMapTextureFinal != nullptr; }
94 void setTimeOfDay(float isDay) { m_time_day = isDay; };
95 void setShadowIntensity(float shadow_intensity);
96
97 s32 getShadowSamples() const { return m_shadow_samples; }
98 float getShadowStrength() const { return m_shadows_enabled ? m_shadow_strength : 0.0f; }
99 float getTimeOfDay() const { return m_time_day; }
100
103
104private:
105 video::ITexture *getSMTexture(const std::string &shadow_map_name,
106 video::ECOLOR_FORMAT texture_format,
107 bool force_creation = false);
108
109 void renderShadowMap(video::ITexture *target, DirectionalLight &light,
110 scene::E_SCENE_NODE_RENDER_PASS pass =
111 scene::ESNRP_SOLID);
112 void renderShadowObjects(video::ITexture *target, DirectionalLight &light);
113 void mixShadowsQuad();
114 void updateSMTextures();
115
116 void disable();
118
119 // a bunch of variables
120 scene::ISceneManager *m_smgr{nullptr};
121 video::IVideoDriver *m_driver{nullptr};
122 Client *m_client{nullptr};
123 video::ITexture *shadowMapClientMap{nullptr};
124 video::ITexture *shadowMapClientMapFuture{nullptr};
125 video::ITexture *shadowMapTextureFinal{nullptr};
126 video::ITexture *shadowMapTextureDynamicObjects{nullptr};
127 video::ITexture *shadowMapTextureColors{nullptr};
128
129 std::vector<DirectionalLight> m_light_list;
130 std::vector<NodeToApply> m_shadow_node_array;
131
136 float m_time_day{0.0f};
143 u8 m_map_shadow_update_frames; /* Use this number of frames to update map shaodw */
144 u8 m_current_frame{0}; /* Current frame */
147
148 video::ECOLOR_FORMAT m_texture_format{video::ECOLOR_FORMAT::ECF_R16F};
149 video::ECOLOR_FORMAT m_texture_format_color{video::ECOLOR_FORMAT::ECF_R16G16};
150
151 // Shadow Shader stuff
152
153 void createShaders();
154 std::string readShaderFile(const std::string &path);
155
160
164
167};
168
176ShadowRenderer *createShadowRenderer(IrrlichtDevice *device, Client *client);
Definition: client.h:119
Definition: dynamicshadows.h:44
Definition: shader.h:228
Definition: shadowsshadercallbacks.h:68
Definition: dynamicshadowsrender.h:53
float m_time_day
Definition: dynamicshadowsrender.h:136
int m_shadow_samples
Definition: dynamicshadowsrender.h:137
video::IVideoDriver * m_driver
Definition: dynamicshadowsrender.h:121
~ShadowRenderer()
Definition: dynamicshadowsrender.cpp:64
s32 depth_shader_trans
Definition: dynamicshadowsrender.h:158
s32 mixcsm_shader
Definition: dynamicshadowsrender.h:159
u8 m_current_frame
Definition: dynamicshadowsrender.h:144
void setTimeOfDay(float isDay)
Definition: dynamicshadowsrender.h:94
void updateSMTextures()
Definition: dynamicshadowsrender.cpp:216
void update(video::ITexture *outputTarget=nullptr)
Definition: dynamicshadowsrender.cpp:353
video::ITexture * shadowMapTextureFinal
Definition: dynamicshadowsrender.h:125
bool m_shadow_map_texture_32bit
Definition: dynamicshadowsrender.h:138
video::ITexture * shadowMapTextureColors
Definition: dynamicshadowsrender.h:127
std::string readShaderFile(const std::string &path)
Definition: dynamicshadowsrender.cpp:705
float getShadowStrength() const
Definition: dynamicshadowsrender.h:98
bool m_shadows_supported
Definition: dynamicshadowsrender.h:140
void renderShadowObjects(video::ITexture *target, DirectionalLight &light)
Definition: dynamicshadowsrender.cpp:478
u8 m_map_shadow_update_frames
Definition: dynamicshadowsrender.h:143
size_t getDirectionalLightCount() const
Definition: dynamicshadowsrender.cpp:170
float m_shadow_strength_gamma
Definition: dynamicshadowsrender.h:133
scene::ISceneManager * m_smgr
Definition: dynamicshadowsrender.h:120
float getTimeOfDay() const
Definition: dynamicshadowsrender.h:99
bool m_shadows_enabled
Definition: dynamicshadowsrender.h:139
void removeNodeFromShadowList(scene::ISceneNode *node)
Definition: dynamicshadowsrender.cpp:201
video::ECOLOR_FORMAT m_texture_format_color
Definition: dynamicshadowsrender.h:149
f32 m_perspective_bias_z
Definition: dynamicshadowsrender.h:146
float m_shadow_strength
Definition: dynamicshadowsrender.h:132
f32 getPerspectiveBiasZ()
Definition: dynamicshadowsrender.h:102
s32 getShadowSamples() const
Definition: dynamicshadowsrender.h:97
static const int TEXTURE_LAYER_SHADOW
Definition: dynamicshadowsrender.h:55
Client * m_client
Definition: dynamicshadowsrender.h:122
shadowScreenQuadCB * m_shadow_mix_cb
Definition: dynamicshadowsrender.h:166
video::ITexture * getSMTexture(const std::string &shadow_map_name, video::ECOLOR_FORMAT texture_format, bool force_creation=false)
Definition: dynamicshadowsrender.cpp:431
video::ITexture * shadowMapTextureDynamicObjects
Definition: dynamicshadowsrender.h:126
size_t addDirectionalLight()
Adds a directional light shadow map (Usually just one (the sun) except in Tattoine ).
Definition: dynamicshadowsrender.cpp:157
video::ITexture * shadowMapClientMap
Definition: dynamicshadowsrender.h:123
void setShadowIntensity(float shadow_intensity)
Definition: dynamicshadowsrender.cpp:181
ShadowDepthShaderCB * m_shadow_depth_cb
Definition: dynamicshadowsrender.h:161
bool is_active() const
Definition: dynamicshadowsrender.h:93
static void preInit(IWritableShaderSource *shsrc)
Definition: dynamicshadowsrender.cpp:121
void drawDebug()
Definition: dynamicshadowsrender.cpp:399
void mixShadowsQuad()
Definition: dynamicshadowsrender.cpp:535
f32 getMaxShadowFar() const
Definition: dynamicshadowsrender.cpp:175
bool m_shadow_map_colored
Definition: dynamicshadowsrender.h:141
bool m_force_update_shadow_map
Definition: dynamicshadowsrender.h:142
ShadowDepthShaderCB * m_shadow_depth_entity_cb
Definition: dynamicshadowsrender.h:162
shadowScreenQuad * m_screen_quad
Definition: dynamicshadowsrender.h:165
s32 depth_shader
Definition: dynamicshadowsrender.h:156
void disable()
Definition: dynamicshadowsrender.cpp:81
void enable()
Definition: dynamicshadowsrender.h:117
void renderShadowMap(video::ITexture *target, DirectionalLight &light, scene::E_SCENE_NODE_RENDER_PASS pass=scene::ESNRP_SOLID)
Definition: dynamicshadowsrender.cpp:444
void initialize()
Definition: dynamicshadowsrender.cpp:129
f32 m_perspective_bias_xy
Definition: dynamicshadowsrender.h:145
ShadowDepthShaderCB * m_shadow_depth_trans_cb
Definition: dynamicshadowsrender.h:163
float m_shadow_map_max_distance
Definition: dynamicshadowsrender.h:134
std::vector< DirectionalLight > m_light_list
Definition: dynamicshadowsrender.h:129
void setForceUpdateShadowMap()
Definition: dynamicshadowsrender.h:84
s32 depth_shader_entities
Definition: dynamicshadowsrender.h:157
video::ITexture * get_texture()
Definition: dynamicshadowsrender.h:87
float m_shadow_map_texture_size
Definition: dynamicshadowsrender.h:135
video::ECOLOR_FORMAT m_texture_format
Definition: dynamicshadowsrender.h:148
void createShaders()
Definition: dynamicshadowsrender.cpp:547
f32 getPerspectiveBiasXY()
Definition: dynamicshadowsrender.h:101
std::vector< NodeToApply > m_shadow_node_array
Definition: dynamicshadowsrender.h:130
video::ITexture * shadowMapClientMapFuture
Definition: dynamicshadowsrender.h:124
void addNodeToShadowList(scene::ISceneNode *node, E_SHADOW_MODE shadowMode=ESM_BOTH)
Adds a shadow to the scene node.
Definition: dynamicshadowsrender.cpp:190
DirectionalLight & getDirectionalLight(u32 index=0)
Definition: dynamicshadowsrender.cpp:165
Definition: shadowsScreenQuad.h:40
Definition: shadowsScreenQuad.h:27
ShadowRenderer * createShadowRenderer(IrrlichtDevice *device, Client *client)
Create a shadow renderer if settings allow this.
Definition: dynamicshadowsrender.cpp:718
E_SHADOW_MODE
Definition: dynamicshadowsrender.h:33
@ ESM_RECEIVE
Definition: dynamicshadowsrender.h:34
@ ESM_BOTH
Definition: dynamicshadowsrender.h:35
Definition: activeobjectmgr.cpp:26
Definition: dynamicshadowsrender.h:39
E_SHADOW_MODE shadowMode
Definition: dynamicshadowsrender.h:48
bool dirty
Definition: dynamicshadowsrender.h:49
bool operator<(const NodeToApply &other) const
Definition: dynamicshadowsrender.h:44
NodeToApply(scene::ISceneNode *n, E_SHADOW_MODE m=E_SHADOW_MODE::ESM_BOTH)
Definition: dynamicshadowsrender.h:40
scene::ISceneNode * node
Definition: dynamicshadowsrender.h:46