1
0
mirror of https://github.com/luanti-org/luanti.git synced 2025-11-21 08:55:21 +01:00

Dynamic shadows with the ogles2 driver on OpenGL ES 3.0+ (#16661)

This commit is contained in:
grorp
2025-11-17 17:55:13 +01:00
committed by GitHub
parent ac0ebf39ad
commit fcd96e9244
22 changed files with 97 additions and 70 deletions

View File

@@ -35,7 +35,6 @@ ShadowRenderer::ShadowRenderer(IrrlichtDevice *device, Client *client) :
m_shadow_map_texture_32bit = g_settings->getBool("shadow_map_texture_32bit");
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");
m_screen_quad = new ShadowScreenQuad();
@@ -525,10 +524,6 @@ void ShadowRenderer::renderShadowObjects(
} // end for caster shadow nodes
}
void ShadowRenderer::mixShadowsQuad()
{
}
void ShadowRenderer::createShaders()
{
auto *shdsrc = m_client->getShaderSource();
@@ -586,9 +581,7 @@ std::unique_ptr<ShadowRenderer> createShadowRenderer(IrrlichtDevice *device, Cli
return nullptr;
// disable if unsupported
// See also checks in builtin/mainmenu/settings/dlg_settings.lua
const video::E_DRIVER_TYPE type = device->getVideoDriver()->getDriverType();
if (type != video::EDT_OPENGL && type != video::EDT_OPENGL3) {
if (!ShadowRenderer::isSupported(device)) {
warningstream << "Shadows: disabled dynamic shadows due to being unsupported" << std::endl;
g_settings->setBool("enable_dynamic_shadows", false);
return nullptr;
@@ -598,3 +591,19 @@ std::unique_ptr<ShadowRenderer> createShadowRenderer(IrrlichtDevice *device, Cli
shadow_renderer->initialize();
return shadow_renderer;
}
bool ShadowRenderer::isSupported(IrrlichtDevice *device)
{
auto driver = device->getVideoDriver();
const video::E_DRIVER_TYPE type = driver->getDriverType();
v2s32 glver = driver->getLimits().GLVersion;
if (type != video::EDT_OPENGL && type != video::EDT_OPENGL3 &&
!(type == video::EDT_OGLES2 && glver.X >= 3))
return false;
if (!driver->queryFeature(video::EVDF_RENDER_TO_FLOAT_TEXTURE))
return false;
return true;
}

View File

@@ -85,7 +85,6 @@ public:
void setShadowIntensity(float shadow_intensity);
void setShadowTint(video::SColor shadow_tint) { m_shadow_tint = shadow_tint; }
s32 getShadowSamples() const { return m_shadow_samples; }
float getShadowStrength() const { return m_shadows_enabled ? m_shadow_strength : 0.0f; }
video::SColor getShadowTint() const { return m_shadow_tint; }
float getTimeOfDay() const { return m_time_day; }
@@ -93,6 +92,8 @@ public:
f32 getPerspectiveBiasXY() { return m_perspective_bias_xy; }
f32 getPerspectiveBiasZ() { return m_perspective_bias_z; }
static bool isSupported(IrrlichtDevice *device);
private:
video::ITexture *getSMTexture(const std::string &shadow_map_name,
video::ECOLOR_FORMAT texture_format,
@@ -102,7 +103,6 @@ private:
scene::E_SCENE_NODE_RENDER_PASS pass =
scene::ESNRP_SOLID);
void renderShadowObjects(video::ITexture *target, DirectionalLight &light);
void mixShadowsQuad();
void updateSMTextures();
void disable();
@@ -127,7 +127,6 @@ private:
float m_shadow_map_max_distance;
u32 m_shadow_map_texture_size;
float m_time_day;
int m_shadow_samples;
bool m_shadow_map_texture_32bit;
bool m_shadows_enabled;
bool m_shadows_supported;

View File

@@ -336,15 +336,24 @@ void set_default_settings()
// Effects Shadows
settings->setDefault("enable_dynamic_shadows", "false");
settings->setDefault("shadow_strength_gamma", "1.0");
settings->setDefault("shadow_map_max_distance", "140.0");
settings->setDefault("shadow_map_texture_size", "2048");
settings->setDefault("shadow_map_texture_32bit", "true");
settings->setDefault("shadow_map_color", "false");
settings->setDefault("shadow_filters", "1");
settings->setDefault("shadow_poisson_filter", "true");
settings->setDefault("shadow_update_frames", "16");
settings->setDefault("shadow_soft_radius", "5.0");
settings->setDefault("shadow_sky_body_orbit_tilt", "0.0");
#ifndef __ANDROID__
// equivalent to "Medium" preset
// see "shadows_component.lua"
settings->setDefault("shadow_map_max_distance", "140.0");
settings->setDefault("shadow_map_texture_size", "2048");
settings->setDefault("shadow_filters", "1");
#else
// equivalent to "Low" preset
settings->setDefault("shadow_map_max_distance", "93.0");
settings->setDefault("shadow_map_texture_size", "1024");
settings->setDefault("shadow_filters", "0");
#endif
settings->setDefault("shadow_map_texture_32bit", "true");
settings->setDefault("shadow_map_color", "false");
// Input
settings->setDefault("invert_mouse", "false");

View File

@@ -6,6 +6,7 @@
#include "l_menu_common.h"
#include "client/renderingengine.h"
#include "client/shadows/dynamicshadowsrender.h"
#include "gettext.h"
#include "lua_api/l_internal.h"
@@ -28,6 +29,13 @@ int ModApiMenuCommon::l_get_active_driver(lua_State *L)
}
int ModApiMenuCommon::l_driver_supports_shadows(lua_State *L)
{
lua_pushboolean(L, ShadowRenderer::isSupported(RenderingEngine::get_raw_device()));
return 1;
}
int ModApiMenuCommon::l_irrlicht_device_supports_touch(lua_State *L)
{
lua_pushboolean(L, RenderingEngine::get_raw_device()->supportsTouchEvents());
@@ -47,6 +55,7 @@ void ModApiMenuCommon::Initialize(lua_State *L, int top)
{
API_FCT(gettext);
API_FCT(get_active_driver);
API_FCT(driver_supports_shadows);
API_FCT(irrlicht_device_supports_touch);
API_FCT(normalize_keycode);
}

View File

@@ -12,6 +12,7 @@ class ModApiMenuCommon: public ModApiBase
private:
static int l_gettext(lua_State *L);
static int l_get_active_driver(lua_State *L);
static int l_driver_supports_shadows(lua_State *L);
static int l_irrlicht_device_supports_touch(lua_State *L);
static int l_normalize_keycode(lua_State *L);