From 899cbb9fff3f7e77bb69f6d62d1247884d6891c0 Mon Sep 17 00:00:00 2001 From: rdb Date: Wed, 31 Aug 2022 11:37:49 +0200 Subject: [PATCH] shadow: Add shadow-cube-map-filter setting, disabled by default Enabling this will enable the `FT_shadow` filter for cube maps, which doesn't work with Cg shaders (incl. shader generator) but does with custom GLSL shaders This will be enabled by default once the shaderpipeline branch is merged Fixes #1332 --- panda/src/display/config_display.cxx | 6 ++++++ panda/src/display/config_display.h | 1 + panda/src/display/graphicsStateGuardian.cxx | 11 +++++++++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/panda/src/display/config_display.cxx b/panda/src/display/config_display.cxx index 2cb2f40c27..58caa6af2a 100644 --- a/panda/src/display/config_display.cxx +++ b/panda/src/display/config_display.cxx @@ -463,6 +463,12 @@ ConfigVariableInt shadow_depth_bits PRC_DESC("The minimum number of depth buffer bits requested when rendering " "shadow maps. Set this to 32 for more depth resolution in shadow " "maps.")); +ConfigVariableBool shadow_cube_map_filter +("shadow-cube-map-filter", false, + PRC_DESC("If true, Panda enables hardware depth map comparison mode for " + "point lights, if supported. If false, does not. Keep this set to " + "false if you want the shader generator to work correctly for point " + "light shadows.")); ConfigVariableColor background_color ("background-color", "0.41 0.41 0.41 0.0", diff --git a/panda/src/display/config_display.h b/panda/src/display/config_display.h index fb4da08b8d..a76c473c91 100644 --- a/panda/src/display/config_display.h +++ b/panda/src/display/config_display.h @@ -103,6 +103,7 @@ extern EXPCL_PANDA_DISPLAY ConfigVariableInt accum_bits; extern EXPCL_PANDA_DISPLAY ConfigVariableInt multisamples; extern EXPCL_PANDA_DISPLAY ConfigVariableInt back_buffers; extern EXPCL_PANDA_DISPLAY ConfigVariableInt shadow_depth_bits; +extern EXPCL_PANDA_DISPLAY ConfigVariableBool shadow_cube_map_filter; extern EXPCL_PANDA_DISPLAY ConfigVariableDouble pixel_zoom; diff --git a/panda/src/display/graphicsStateGuardian.cxx b/panda/src/display/graphicsStateGuardian.cxx index 9ea3ab1f90..b1f0961658 100644 --- a/panda/src/display/graphicsStateGuardian.cxx +++ b/panda/src/display/graphicsStateGuardian.cxx @@ -3580,8 +3580,15 @@ get_dummy_shadow_map(Texture::TextureType texture_type) const { dummy_cube->setup_cube_map(1, Texture::T_unsigned_byte, Texture::F_depth_component); dummy_cube->set_clear_color(1); // Note: cube map shadow filtering doesn't seem to work in Cg. - dummy_cube->set_minfilter(SamplerState::FT_linear); - dummy_cube->set_magfilter(SamplerState::FT_linear); + // That is why it is currently disabled by default, but it can be + // overridden in Config.prc for apps that have custom GLSL shaders. + if (shadow_cube_map_filter && get_supports_shadow_filter()) { + dummy_cube->set_minfilter(SamplerState::FT_shadow); + dummy_cube->set_magfilter(SamplerState::FT_shadow); + } else { + dummy_cube->set_minfilter(SamplerState::FT_linear); + dummy_cube->set_magfilter(SamplerState::FT_linear); + } } return dummy_cube; }