aboutsummaryrefslogtreecommitdiff
path: root/src/client/shadows
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/shadows')
-rw-r--r--src/client/shadows/dynamicshadowsrender.cpp56
-rw-r--r--src/client/shadows/dynamicshadowsrender.h2
2 files changed, 43 insertions, 15 deletions
diff --git a/src/client/shadows/dynamicshadowsrender.cpp b/src/client/shadows/dynamicshadowsrender.cpp
index b8ceeb623..944deb801 100644
--- a/src/client/shadows/dynamicshadowsrender.cpp
+++ b/src/client/shadows/dynamicshadowsrender.cpp
@@ -70,31 +70,45 @@ ShadowRenderer::~ShadowRenderer()
delete m_shadow_mix_cb;
m_shadow_node_array.clear();
m_light_list.clear();
+}
- if (shadowMapTextureDynamicObjects)
+void ShadowRenderer::disable()
+{
+ m_shadows_enabled = false;
+ if (shadowMapTextureFinal) {
+ m_driver->setRenderTarget(shadowMapTextureFinal, true, true,
+ video::SColor(255, 255, 255, 255));
+ m_driver->setRenderTarget(0, false, false);
+ }
+
+ if (shadowMapTextureDynamicObjects) {
m_driver->removeTexture(shadowMapTextureDynamicObjects);
+ shadowMapTextureDynamicObjects = nullptr;
+ }
- if (shadowMapTextureFinal)
+ if (shadowMapTextureFinal) {
m_driver->removeTexture(shadowMapTextureFinal);
+ shadowMapTextureFinal = nullptr;
+ }
- if (shadowMapTextureColors)
+ if (shadowMapTextureColors) {
m_driver->removeTexture(shadowMapTextureColors);
+ shadowMapTextureColors = nullptr;
+ }
- if (shadowMapClientMap)
+ if (shadowMapClientMap) {
m_driver->removeTexture(shadowMapClientMap);
+ shadowMapClientMap = nullptr;
+ }
- if (shadowMapClientMapFuture)
+ if (shadowMapClientMapFuture) {
m_driver->removeTexture(shadowMapClientMapFuture);
-}
-
-void ShadowRenderer::disable()
-{
- m_shadows_enabled = false;
- if (shadowMapTextureFinal) {
- m_driver->setRenderTarget(shadowMapTextureFinal, true, true,
- video::SColor(255, 255, 255, 255));
- m_driver->setRenderTarget(0, true, true);
+ shadowMapClientMapFuture = nullptr;
}
+
+ for (auto node : m_shadow_node_array)
+ if (node.shadowMode & E_SHADOW_MODE::ESM_RECEIVE)
+ node.node->setMaterialTexture(TEXTURE_LAYER_SHADOW, nullptr);
}
void ShadowRenderer::initialize()
@@ -163,11 +177,18 @@ void ShadowRenderer::setShadowIntensity(float shadow_intensity)
void ShadowRenderer::addNodeToShadowList(
scene::ISceneNode *node, E_SHADOW_MODE shadowMode)
{
- m_shadow_node_array.emplace_back(NodeToApply(node, shadowMode));
+ if (!node)
+ return;
+ m_shadow_node_array.emplace_back(node, shadowMode);
+ if (shadowMode == ESM_RECEIVE || shadowMode == ESM_BOTH)
+ node->setMaterialTexture(TEXTURE_LAYER_SHADOW, shadowMapTextureFinal);
}
void ShadowRenderer::removeNodeFromShadowList(scene::ISceneNode *node)
{
+ if (!node)
+ return;
+ node->setMaterialTexture(TEXTURE_LAYER_SHADOW, nullptr);
for (auto it = m_shadow_node_array.begin(); it != m_shadow_node_array.end();) {
if (it->node == node) {
it = m_shadow_node_array.erase(it);
@@ -235,6 +256,10 @@ void ShadowRenderer::updateSMTextures()
std::string("shadowmap_final_") + itos(m_shadow_map_texture_size),
frt, true);
assert(shadowMapTextureFinal != nullptr);
+
+ for (auto &node : m_shadow_node_array)
+ if (node.shadowMode == ESM_RECEIVE || node.shadowMode == ESM_BOTH)
+ node.node->setMaterialTexture(TEXTURE_LAYER_SHADOW, shadowMapTextureFinal);
}
if (!m_shadow_node_array.empty() && !m_light_list.empty()) {
@@ -322,6 +347,7 @@ void ShadowRenderer::update(video::ITexture *outputTarget)
return;
}
+
if (!m_shadow_node_array.empty() && !m_light_list.empty()) {
for (DirectionalLight &light : m_light_list) {
diff --git a/src/client/shadows/dynamicshadowsrender.h b/src/client/shadows/dynamicshadowsrender.h
index 2e3b58f6f..bd27f6f20 100644
--- a/src/client/shadows/dynamicshadowsrender.h
+++ b/src/client/shadows/dynamicshadowsrender.h
@@ -51,6 +51,8 @@ struct NodeToApply
class ShadowRenderer
{
public:
+ static const int TEXTURE_LAYER_SHADOW = 3;
+
ShadowRenderer(IrrlichtDevice *device, Client *client);
~ShadowRenderer();