Skip to content

Commit

Permalink
Add a default direction light for shadows
Browse files Browse the repository at this point in the history
  • Loading branch information
lhofhansl committed Apr 9, 2023
1 parent 9d736e8 commit 8982998
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
2 changes: 0 additions & 2 deletions src/client/game.cpp
Expand Up @@ -4212,8 +4212,6 @@ void Game::updateShadows()

v3f sun_pos = light * offset_constant;

if (shadow->getDirectionalLightCount() == 0)
shadow->addDirectionalLight();
shadow->getDirectionalLight().setDirection(sun_pos);
shadow->setTimeOfDay(in_timeofday);

Expand Down
14 changes: 7 additions & 7 deletions src/client/shadows/dynamicshadowsrender.cpp
Expand Up @@ -53,6 +53,9 @@ ShadowRenderer::ShadowRenderer(IrrlichtDevice *device, Client *client) :
m_shadow_map_colored = g_settings->getBool("shadow_map_color");
m_shadow_samples = g_settings->getS32("shadow_filters");
m_map_shadow_update_frames = g_settings->getS16("shadow_update_frames");

// add at least one light
addDirectionalLight();
}

ShadowRenderer::~ShadowRenderer()
Expand Down Expand Up @@ -157,11 +160,8 @@ size_t ShadowRenderer::getDirectionalLightCount() const

f32 ShadowRenderer::getMaxShadowFar() const
{
if (!m_light_list.empty()) {
float zMax = m_light_list[0].getFarValue();
return zMax;
}
return 0.0f;
float zMax = m_light_list[0].getFarValue();
return zMax;
}

void ShadowRenderer::setShadowIntensity(float shadow_intensity)
Expand Down Expand Up @@ -258,7 +258,7 @@ void ShadowRenderer::updateSMTextures()
node.node->setMaterialTexture(TEXTURE_LAYER_SHADOW, shadowMapTextureFinal);
}

if (!m_shadow_node_array.empty() && !m_light_list.empty()) {
if (!m_shadow_node_array.empty()) {
bool reset_sm_texture = false;

// detect if SM should be regenerated
Expand Down Expand Up @@ -344,7 +344,7 @@ void ShadowRenderer::update(video::ITexture *outputTarget)
}


if (!m_shadow_node_array.empty() && !m_light_list.empty()) {
if (!m_shadow_node_array.empty()) {

for (DirectionalLight &light : m_light_list) {
// Static shader values for entities are set in updateSMTextures
Expand Down

0 comments on commit 8982998

Please sign in to comment.