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