forked from Mirrorlandia_minetest/minetest
Move updating shadows outside of RenderingCore::drawAll. (#11491)
Fixes indirect rendering modes such as some 3D modes mentioned in #11437 and undersampled rendering. Does not fully fix anaglyph 3d mode.
This commit is contained in:
parent
0709946c75
commit
442e48b84f
@ -76,19 +76,18 @@ void RenderingCore::draw(video::SColor _skycolor, bool _show_hud, bool _show_min
|
|||||||
draw_wield_tool = _draw_wield_tool;
|
draw_wield_tool = _draw_wield_tool;
|
||||||
draw_crosshair = _draw_crosshair;
|
draw_crosshair = _draw_crosshair;
|
||||||
|
|
||||||
|
if (shadow_renderer)
|
||||||
|
shadow_renderer->update();
|
||||||
|
|
||||||
beforeDraw();
|
beforeDraw();
|
||||||
drawAll();
|
drawAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderingCore::draw3D()
|
void RenderingCore::draw3D()
|
||||||
{
|
{
|
||||||
if (shadow_renderer) {
|
smgr->drawAll();
|
||||||
// Shadow renderer will handle the draw stage
|
if (shadow_renderer)
|
||||||
shadow_renderer->setClearColor(skycolor);
|
shadow_renderer->drawDebug();
|
||||||
shadow_renderer->update();
|
|
||||||
} else {
|
|
||||||
smgr->drawAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
|
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
|
||||||
if (!show_hud)
|
if (!show_hud)
|
||||||
|
@ -146,11 +146,6 @@ void ShadowRenderer::removeNodeFromShadowList(scene::ISceneNode *node)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShadowRenderer::setClearColor(video::SColor ClearColor)
|
|
||||||
{
|
|
||||||
m_clear_color = ClearColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ShadowRenderer::updateSMTextures()
|
void ShadowRenderer::updateSMTextures()
|
||||||
{
|
{
|
||||||
if (!m_shadows_enabled || m_smgr->getActiveCamera() == nullptr) {
|
if (!m_shadows_enabled || m_smgr->getActiveCamera() == nullptr) {
|
||||||
@ -242,6 +237,7 @@ void ShadowRenderer::updateSMTextures()
|
|||||||
// This is also handled in ClientMap.
|
// This is also handled in ClientMap.
|
||||||
if (m_current_frame == m_map_shadow_update_frames - 1) {
|
if (m_current_frame == m_map_shadow_update_frames - 1) {
|
||||||
if (m_shadow_map_colored) {
|
if (m_shadow_map_colored) {
|
||||||
|
m_driver->setRenderTarget(0, false, false);
|
||||||
m_driver->setRenderTarget(shadowMapTextureColors,
|
m_driver->setRenderTarget(shadowMapTextureColors,
|
||||||
true, false, video::SColor(255, 255, 255, 255));
|
true, false, video::SColor(255, 255, 255, 255));
|
||||||
}
|
}
|
||||||
@ -273,7 +269,6 @@ void ShadowRenderer::updateSMTextures()
|
|||||||
void ShadowRenderer::update(video::ITexture *outputTarget)
|
void ShadowRenderer::update(video::ITexture *outputTarget)
|
||||||
{
|
{
|
||||||
if (!m_shadows_enabled || m_smgr->getActiveCamera() == nullptr) {
|
if (!m_shadows_enabled || m_smgr->getActiveCamera() == nullptr) {
|
||||||
m_smgr->drawAll();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -308,38 +303,36 @@ void ShadowRenderer::update(video::ITexture *outputTarget)
|
|||||||
m_driver->setRenderTarget(0, false, false);
|
m_driver->setRenderTarget(0, false, false);
|
||||||
|
|
||||||
} // end for lights
|
} // end for lights
|
||||||
|
|
||||||
// now render the actual MT render pass
|
|
||||||
m_driver->setRenderTarget(outputTarget, true, true, m_clear_color);
|
|
||||||
m_smgr->drawAll();
|
|
||||||
|
|
||||||
/* this code just shows shadows textures in screen and in ONLY for debugging*/
|
|
||||||
#if 0
|
|
||||||
// this is debug, ignore for now.
|
|
||||||
m_driver->draw2DImage(shadowMapTextureFinal,
|
|
||||||
core::rect<s32>(0, 50, 128, 128 + 50),
|
|
||||||
core::rect<s32>({0, 0}, shadowMapTextureFinal->getSize()));
|
|
||||||
|
|
||||||
m_driver->draw2DImage(shadowMapClientMap,
|
|
||||||
core::rect<s32>(0, 50 + 128, 128, 128 + 50 + 128),
|
|
||||||
core::rect<s32>({0, 0}, shadowMapTextureFinal->getSize()));
|
|
||||||
m_driver->draw2DImage(shadowMapTextureDynamicObjects,
|
|
||||||
core::rect<s32>(0, 128 + 50 + 128, 128,
|
|
||||||
128 + 50 + 128 + 128),
|
|
||||||
core::rect<s32>({0, 0}, shadowMapTextureDynamicObjects->getSize()));
|
|
||||||
|
|
||||||
if (m_shadow_map_colored) {
|
|
||||||
|
|
||||||
m_driver->draw2DImage(shadowMapTextureColors,
|
|
||||||
core::rect<s32>(128,128 + 50 + 128 + 128,
|
|
||||||
128 + 128, 128 + 50 + 128 + 128 + 128),
|
|
||||||
core::rect<s32>({0, 0}, shadowMapTextureColors->getSize()));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
m_driver->setRenderTarget(0, false, false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ShadowRenderer::drawDebug()
|
||||||
|
{
|
||||||
|
/* this code just shows shadows textures in screen and in ONLY for debugging*/
|
||||||
|
#if 0
|
||||||
|
// this is debug, ignore for now.
|
||||||
|
m_driver->draw2DImage(shadowMapTextureFinal,
|
||||||
|
core::rect<s32>(0, 50, 128, 128 + 50),
|
||||||
|
core::rect<s32>({0, 0}, shadowMapTextureFinal->getSize()));
|
||||||
|
|
||||||
|
m_driver->draw2DImage(shadowMapClientMap,
|
||||||
|
core::rect<s32>(0, 50 + 128, 128, 128 + 50 + 128),
|
||||||
|
core::rect<s32>({0, 0}, shadowMapTextureFinal->getSize()));
|
||||||
|
m_driver->draw2DImage(shadowMapTextureDynamicObjects,
|
||||||
|
core::rect<s32>(0, 128 + 50 + 128, 128,
|
||||||
|
128 + 50 + 128 + 128),
|
||||||
|
core::rect<s32>({0, 0}, shadowMapTextureDynamicObjects->getSize()));
|
||||||
|
|
||||||
|
if (m_shadow_map_colored) {
|
||||||
|
|
||||||
|
m_driver->draw2DImage(shadowMapTextureColors,
|
||||||
|
core::rect<s32>(128,128 + 50 + 128 + 128,
|
||||||
|
128 + 128, 128 + 50 + 128 + 128 + 128),
|
||||||
|
core::rect<s32>({0, 0}, shadowMapTextureColors->getSize()));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
video::ITexture *ShadowRenderer::getSMTexture(const std::string &shadow_map_name,
|
video::ITexture *ShadowRenderer::getSMTexture(const std::string &shadow_map_name,
|
||||||
video::ECOLOR_FORMAT texture_format, bool force_creation)
|
video::ECOLOR_FORMAT texture_format, bool force_creation)
|
||||||
|
@ -73,9 +73,8 @@ public:
|
|||||||
E_SHADOW_MODE shadowMode = ESM_BOTH);
|
E_SHADOW_MODE shadowMode = ESM_BOTH);
|
||||||
void removeNodeFromShadowList(scene::ISceneNode *node);
|
void removeNodeFromShadowList(scene::ISceneNode *node);
|
||||||
|
|
||||||
void setClearColor(video::SColor ClearColor);
|
|
||||||
|
|
||||||
void update(video::ITexture *outputTarget = nullptr);
|
void update(video::ITexture *outputTarget = nullptr);
|
||||||
|
void drawDebug();
|
||||||
|
|
||||||
video::ITexture *get_texture()
|
video::ITexture *get_texture()
|
||||||
{
|
{
|
||||||
@ -112,7 +111,6 @@ private:
|
|||||||
video::ITexture *shadowMapTextureFinal{nullptr};
|
video::ITexture *shadowMapTextureFinal{nullptr};
|
||||||
video::ITexture *shadowMapTextureDynamicObjects{nullptr};
|
video::ITexture *shadowMapTextureDynamicObjects{nullptr};
|
||||||
video::ITexture *shadowMapTextureColors{nullptr};
|
video::ITexture *shadowMapTextureColors{nullptr};
|
||||||
video::SColor m_clear_color{0x0};
|
|
||||||
|
|
||||||
std::vector<DirectionalLight> m_light_list;
|
std::vector<DirectionalLight> m_light_list;
|
||||||
std::vector<NodeToApply> m_shadow_node_array;
|
std::vector<NodeToApply> m_shadow_node_array;
|
||||||
|
@ -51,17 +51,11 @@ void shadowScreenQuadCB::OnSetConstants(
|
|||||||
video::IMaterialRendererServices *services, s32 userData)
|
video::IMaterialRendererServices *services, s32 userData)
|
||||||
{
|
{
|
||||||
s32 TextureId = 0;
|
s32 TextureId = 0;
|
||||||
services->setPixelShaderConstant(
|
m_sm_client_map_setting.set(&TextureId, services);
|
||||||
services->getPixelShaderConstantID("ShadowMapClientMap"),
|
|
||||||
&TextureId, 1);
|
|
||||||
|
|
||||||
TextureId = 1;
|
TextureId = 1;
|
||||||
services->setPixelShaderConstant(
|
m_sm_client_map_trans_setting.set(&TextureId, services);
|
||||||
services->getPixelShaderConstantID("ShadowMapClientMapTraslucent"),
|
|
||||||
&TextureId, 1);
|
|
||||||
|
|
||||||
TextureId = 2;
|
TextureId = 2;
|
||||||
services->setPixelShaderConstant(
|
m_sm_dynamic_sampler_setting.set(&TextureId, services);
|
||||||
services->getPixelShaderConstantID("ShadowMapSamplerdynamic"),
|
|
||||||
&TextureId, 1);
|
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "irrlichttypes_extrabloated.h"
|
#include "irrlichttypes_extrabloated.h"
|
||||||
#include <IMaterialRendererServices.h>
|
#include <IMaterialRendererServices.h>
|
||||||
#include <IShaderConstantSetCallBack.h>
|
#include <IShaderConstantSetCallBack.h>
|
||||||
|
#include "client/shader.h"
|
||||||
|
|
||||||
class shadowScreenQuad
|
class shadowScreenQuad
|
||||||
{
|
{
|
||||||
@ -38,8 +39,16 @@ private:
|
|||||||
class shadowScreenQuadCB : public video::IShaderConstantSetCallBack
|
class shadowScreenQuadCB : public video::IShaderConstantSetCallBack
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
shadowScreenQuadCB(){};
|
shadowScreenQuadCB() :
|
||||||
|
m_sm_client_map_setting("ShadowMapClientMap"),
|
||||||
|
m_sm_client_map_trans_setting("ShadowMapClientMapTraslucent"),
|
||||||
|
m_sm_dynamic_sampler_setting("ShadowMapSamplerdynamic")
|
||||||
|
{}
|
||||||
|
|
||||||
virtual void OnSetConstants(video::IMaterialRendererServices *services,
|
virtual void OnSetConstants(video::IMaterialRendererServices *services,
|
||||||
s32 userData);
|
s32 userData);
|
||||||
|
private:
|
||||||
|
CachedPixelShaderSetting<s32> m_sm_client_map_setting;
|
||||||
|
CachedPixelShaderSetting<s32> m_sm_client_map_trans_setting;
|
||||||
|
CachedPixelShaderSetting<s32> m_sm_dynamic_sampler_setting;
|
||||||
};
|
};
|
||||||
|
@ -28,17 +28,9 @@ void ShadowDepthShaderCB::OnSetConstants(
|
|||||||
lightMVP *= driver->getTransform(video::ETS_VIEW);
|
lightMVP *= driver->getTransform(video::ETS_VIEW);
|
||||||
lightMVP *= driver->getTransform(video::ETS_WORLD);
|
lightMVP *= driver->getTransform(video::ETS_WORLD);
|
||||||
|
|
||||||
services->setVertexShaderConstant(
|
m_light_mvp_setting.set(lightMVP.pointer(), services);
|
||||||
services->getPixelShaderConstantID("LightMVP"),
|
m_map_resolution_setting.set(&MapRes, services);
|
||||||
lightMVP.pointer(), 16);
|
m_max_far_setting.set(&MaxFar, services);
|
||||||
|
|
||||||
services->setVertexShaderConstant(
|
|
||||||
services->getPixelShaderConstantID("MapResolution"), &MapRes, 1);
|
|
||||||
services->setVertexShaderConstant(
|
|
||||||
services->getPixelShaderConstantID("MaxFar"), &MaxFar, 1);
|
|
||||||
|
|
||||||
s32 TextureId = 0;
|
s32 TextureId = 0;
|
||||||
services->setPixelShaderConstant(
|
m_color_map_sampler_setting.set(&TextureId, services);
|
||||||
services->getPixelShaderConstantID("ColorMapSampler"), &TextureId,
|
|
||||||
1);
|
|
||||||
}
|
}
|
||||||
|
@ -21,14 +21,28 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "irrlichttypes_extrabloated.h"
|
#include "irrlichttypes_extrabloated.h"
|
||||||
#include <IMaterialRendererServices.h>
|
#include <IMaterialRendererServices.h>
|
||||||
#include <IShaderConstantSetCallBack.h>
|
#include <IShaderConstantSetCallBack.h>
|
||||||
|
#include "client/shader.h"
|
||||||
|
|
||||||
class ShadowDepthShaderCB : public video::IShaderConstantSetCallBack
|
class ShadowDepthShaderCB : public video::IShaderConstantSetCallBack
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
ShadowDepthShaderCB() :
|
||||||
|
m_light_mvp_setting("LightMVP"),
|
||||||
|
m_map_resolution_setting("MapResolution"),
|
||||||
|
m_max_far_setting("MaxFar"),
|
||||||
|
m_color_map_sampler_setting("ColorMapSampler")
|
||||||
|
{}
|
||||||
|
|
||||||
void OnSetMaterial(const video::SMaterial &material) override {}
|
void OnSetMaterial(const video::SMaterial &material) override {}
|
||||||
|
|
||||||
void OnSetConstants(video::IMaterialRendererServices *services,
|
void OnSetConstants(video::IMaterialRendererServices *services,
|
||||||
s32 userData) override;
|
s32 userData) override;
|
||||||
|
|
||||||
f32 MaxFar{2048.0f}, MapRes{1024.0f};
|
f32 MaxFar{2048.0f}, MapRes{1024.0f};
|
||||||
|
|
||||||
|
private:
|
||||||
|
CachedVertexShaderSetting<f32, 16> m_light_mvp_setting;
|
||||||
|
CachedVertexShaderSetting<f32> m_map_resolution_setting;
|
||||||
|
CachedVertexShaderSetting<f32> m_max_far_setting;
|
||||||
|
CachedPixelShaderSetting<s32> m_color_map_sampler_setting;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user