Luanti 5.15.0-dev
 
Loading...
Searching...
No Matches
dynamicshadowsrender.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2021 Liso <anlismon@gmail.com>
4
5#pragma once
6
7#include <string>
8#include <vector>
9#include <memory>
10#include <IrrlichtDevice.h>
12#include <ISceneNode.h>
13#include <ISceneManager.h>
14
19
21{
24};
25
27{
28 NodeToApply(scene::ISceneNode *n,
30 node(n),
31 shadowMode(m){};
32
33 bool operator==(scene::ISceneNode *n) const { return node == n; }
34
35 scene::ISceneNode *node;
36
38 bool dirty{false};
39};
40
42{
43public:
44 static const int TEXTURE_LAYER_SHADOW = 3;
45
46 ShadowRenderer(IrrlichtDevice *device, Client *client);
48
49 // Call before generating any shaders
50 // This is required because this class is initialized much later than all
51 // the shaders are dealt with.
52 static void preInit(IWritableShaderSource *shsrc);
53
55 bool initialize();
56
59 size_t addDirectionalLight();
61 size_t getDirectionalLightCount() const;
62 f32 getMaxShadowFar() const;
63
69 void addNodeToShadowList(scene::ISceneNode *node,
70 E_SHADOW_MODE shadowMode = ESM_BOTH);
71 void removeNodeFromShadowList(scene::ISceneNode *node);
72
73 void update(video::ITexture *outputTarget = nullptr);
76 void drawDebug();
77
78 video::ITexture *get_texture()
79 {
81 }
82
83
84 bool is_active() const { return m_shadows_enabled && shadowMapTextureFinal != nullptr; }
85 void setTimeOfDay(float isDay) { m_time_day = isDay; };
86 void setShadowIntensity(float shadow_intensity);
87 void setShadowTint(video::SColor shadow_tint) { m_shadow_tint = shadow_tint; }
88
89 float getShadowStrength() const { return m_shadows_enabled ? m_shadow_strength : 0.0f; }
90 video::SColor getShadowTint() const { return m_shadow_tint; }
91 float getTimeOfDay() const { return m_time_day; }
92
95
96 static bool isSupported(video::IVideoDriver *driver);
97
98private:
99 video::ITexture *getSMTexture(const std::string &shadow_map_name,
100 video::ECOLOR_FORMAT texture_format,
101 bool force_creation = false);
102
103 void renderShadowMap(video::ITexture *target, DirectionalLight &light,
104 scene::E_SCENE_NODE_RENDER_PASS pass =
105 scene::ESNRP_SOLID);
106 void renderShadowObjects(video::ITexture *target, DirectionalLight &light);
107 void updateSMTextures();
108
109 void disable();
111
112 // a bunch of variables
113 scene::ISceneManager *m_smgr{nullptr};
114 video::IVideoDriver *m_driver{nullptr};
115 Client *m_client{nullptr};
116 video::ITexture *shadowMapClientMap{nullptr};
117 video::ITexture *shadowMapClientMapFuture{nullptr};
118 video::ITexture *shadowMapTextureFinal{nullptr};
119 video::ITexture *shadowMapTextureDynamicObjects{nullptr};
120 video::ITexture *shadowMapTextureColors{nullptr};
121
122 std::vector<DirectionalLight> m_light_list;
123 std::vector<NodeToApply> m_shadow_node_array;
124
126 video::SColor m_shadow_tint;
136 u8 m_map_shadow_update_frames; /* Use this number of frames to update map shaodw */
137 u8 m_current_frame; /* Current frame */
140
141 video::ECOLOR_FORMAT m_texture_format{video::ECF_R16F};
142 video::ECOLOR_FORMAT m_texture_format_color{video::ECF_R16G16};
143
144 // Shadow Shader stuff
145
146 void createShaders();
147
148 // _a suffix is with support for array textures
149 video::E_MATERIAL_TYPE depth_shader{video::EMT_INVALID},
150 depth_shader_a{video::EMT_INVALID};
151 video::E_MATERIAL_TYPE depth_shader_trans{video::EMT_INVALID},
152 depth_shader_trans_a{video::EMT_INVALID};
153
154 std::vector<ShadowDepthUniformSetter*> m_shadow_depth_cb;
155
157};
158
166std::unique_ptr<ShadowRenderer> createShadowRenderer(IrrlichtDevice *device, Client *client);
Definition client.h:106
Definition dynamicshadows.h:27
Definition shader.h:293
Definition shadowsshadercallbacks.h:55
Definition dynamicshadowsrender.h:42
video::SColor getShadowTint() const
Definition dynamicshadowsrender.h:90
float m_time_day
Definition dynamicshadowsrender.h:130
u32 m_shadow_map_texture_size
Definition dynamicshadowsrender.h:129
static bool isSupported(video::IVideoDriver *driver)
Definition dynamicshadowsrender.cpp:609
video::IVideoDriver * m_driver
Definition dynamicshadowsrender.h:114
~ShadowRenderer()
Definition dynamicshadowsrender.cpp:46
u8 m_current_frame
Definition dynamicshadowsrender.h:137
void setTimeOfDay(float isDay)
Definition dynamicshadowsrender.h:85
void updateSMTextures()
Definition dynamicshadowsrender.cpp:210
void update(video::ITexture *outputTarget=nullptr)
Definition dynamicshadowsrender.cpp:344
video::ITexture * shadowMapTextureFinal
Definition dynamicshadowsrender.h:118
ShadowRenderer(IrrlichtDevice *device, Client *client)
Definition dynamicshadowsrender.cpp:18
bool m_shadow_map_texture_32bit
Definition dynamicshadowsrender.h:131
video::ITexture * shadowMapTextureColors
Definition dynamicshadowsrender.h:120
float getShadowStrength() const
Definition dynamicshadowsrender.h:89
bool m_shadows_supported
Definition dynamicshadowsrender.h:133
video::E_MATERIAL_TYPE depth_shader_trans
Definition dynamicshadowsrender.h:151
void renderShadowObjects(video::ITexture *target, DirectionalLight &light)
Definition dynamicshadowsrender.cpp:485
u8 m_map_shadow_update_frames
Definition dynamicshadowsrender.h:136
size_t getDirectionalLightCount() const
Definition dynamicshadowsrender.cpp:163
float m_shadow_strength_gamma
Definition dynamicshadowsrender.h:127
ShadowScreenQuad * m_screen_quad
Definition dynamicshadowsrender.h:156
video::SColor m_shadow_tint
Definition dynamicshadowsrender.h:126
scene::ISceneManager * m_smgr
Definition dynamicshadowsrender.h:113
float getTimeOfDay() const
Definition dynamicshadowsrender.h:91
bool initialize()
Definition dynamicshadowsrender.cpp:115
bool m_shadows_enabled
Definition dynamicshadowsrender.h:132
void removeNodeFromShadowList(scene::ISceneNode *node)
Definition dynamicshadowsrender.cpp:194
video::ECOLOR_FORMAT m_texture_format_color
Definition dynamicshadowsrender.h:142
f32 m_perspective_bias_z
Definition dynamicshadowsrender.h:139
float m_shadow_strength
Definition dynamicshadowsrender.h:125
f32 getPerspectiveBiasZ()
Definition dynamicshadowsrender.h:94
static const int TEXTURE_LAYER_SHADOW
Definition dynamicshadowsrender.h:44
Client * m_client
Definition dynamicshadowsrender.h:115
video::ITexture * getSMTexture(const std::string &shadow_map_name, video::ECOLOR_FORMAT texture_format, bool force_creation=false)
Definition dynamicshadowsrender.cpp:424
video::ITexture * shadowMapTextureDynamicObjects
Definition dynamicshadowsrender.h:119
size_t addDirectionalLight()
Adds a directional light shadow map (Usually just one (the sun) except in Tattoine ).
Definition dynamicshadowsrender.cpp:150
video::ITexture * shadowMapClientMap
Definition dynamicshadowsrender.h:116
void setShadowIntensity(float shadow_intensity)
Definition dynamicshadowsrender.cpp:174
bool is_active() const
Definition dynamicshadowsrender.h:84
void setShadowTint(video::SColor shadow_tint)
Definition dynamicshadowsrender.h:87
static void preInit(IWritableShaderSource *shsrc)
Definition dynamicshadowsrender.cpp:108
void drawDebug()
Definition dynamicshadowsrender.cpp:392
f32 getMaxShadowFar() const
Definition dynamicshadowsrender.cpp:168
video::E_MATERIAL_TYPE depth_shader
Definition dynamicshadowsrender.h:149
bool m_shadow_map_colored
Definition dynamicshadowsrender.h:134
bool m_force_update_shadow_map
Definition dynamicshadowsrender.h:135
video::E_MATERIAL_TYPE depth_shader_a
Definition dynamicshadowsrender.h:150
void disable()
Definition dynamicshadowsrender.cpp:67
void enable()
Definition dynamicshadowsrender.h:110
std::vector< ShadowDepthUniformSetter * > m_shadow_depth_cb
Definition dynamicshadowsrender.h:154
void renderShadowMap(video::ITexture *target, DirectionalLight &light, scene::E_SCENE_NODE_RENDER_PASS pass=scene::ESNRP_SOLID)
Definition dynamicshadowsrender.cpp:437
f32 m_perspective_bias_xy
Definition dynamicshadowsrender.h:138
float m_shadow_map_max_distance
Definition dynamicshadowsrender.h:128
std::vector< DirectionalLight > m_light_list
Definition dynamicshadowsrender.h:122
video::E_MATERIAL_TYPE depth_shader_trans_a
Definition dynamicshadowsrender.h:152
void setForceUpdateShadowMap()
Force shadow map to be re-drawn in one go next frame.
Definition dynamicshadowsrender.h:75
video::ITexture * get_texture()
Definition dynamicshadowsrender.h:78
video::ECOLOR_FORMAT m_texture_format
Definition dynamicshadowsrender.h:141
void createShaders()
Definition dynamicshadowsrender.cpp:545
f32 getPerspectiveBiasXY()
Definition dynamicshadowsrender.h:93
std::vector< NodeToApply > m_shadow_node_array
Definition dynamicshadowsrender.h:123
video::ITexture * shadowMapClientMapFuture
Definition dynamicshadowsrender.h:117
void addNodeToShadowList(scene::ISceneNode *node, E_SHADOW_MODE shadowMode=ESM_BOTH)
Adds a shadow to the scene node.
Definition dynamicshadowsrender.cpp:183
DirectionalLight & getDirectionalLight(u32 index=0)
Definition dynamicshadowsrender.cpp:158
Definition shadowsScreenQuad.h:25
Definition shadowsScreenQuad.h:12
std::unique_ptr< ShadowRenderer > createShadowRenderer(IrrlichtDevice *device, Client *client)
Create a shadow renderer if settings allow this.
Definition dynamicshadowsrender.cpp:596
E_SHADOW_MODE
Definition dynamicshadowsrender.h:21
@ ESM_RECEIVE
Definition dynamicshadowsrender.h:22
@ ESM_BOTH
Definition dynamicshadowsrender.h:23
Definition activeobjectmgr.cpp:11
Definition dynamicshadowsrender.h:27
E_SHADOW_MODE shadowMode
Definition dynamicshadowsrender.h:37
bool dirty
Definition dynamicshadowsrender.h:38
NodeToApply(scene::ISceneNode *n, E_SHADOW_MODE m=E_SHADOW_MODE::ESM_BOTH)
Definition dynamicshadowsrender.h:28
bool operator==(scene::ISceneNode *n) const
Definition dynamicshadowsrender.h:33
scene::ISceneNode * node
Definition dynamicshadowsrender.h:35