From 9f20aaccfb944580655ef1e41df0e0dce0f1638c Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Thu, 25 Jan 2018 16:08:34 +0000 Subject: [PATCH] Add some more advanced settings to control shadows. --- components/sceneutil/shadow.cpp | 9 +++-- .../reference/modding/settings/shadows.rst | 37 ++++++++++++++++++- files/settings-default.cfg | 6 +++ 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/components/sceneutil/shadow.cpp b/components/sceneutil/shadow.cpp index 0d654a817a..f1943f08d5 100644 --- a/components/sceneutil/shadow.cpp +++ b/components/sceneutil/shadow.cpp @@ -64,7 +64,7 @@ namespace SceneUtil settings->setNumShadowMapsPerLight(numberOfShadowMapsPerLight); settings->setBaseShadowTextureUnit(8 - numberOfShadowMapsPerLight); - settings->setMinimumShadowMapNearFarRatio(0.25); + settings->setMinimumShadowMapNearFarRatio(Settings::Manager::getFloat("minimum lispsm near far ratio", "Shadows")); if (Settings::Manager::getBool("compute tight scene bounds", "Shadows")) settings->setComputeNearFarModeOverride(osg::CullSettings::COMPUTE_NEAR_FAR_USING_PRIMITIVES); @@ -683,7 +683,8 @@ namespace SceneUtil double f = (frustum.eye - frustum.centerFarPlane).length(); double i = double(sm_i); double m = double(numShadowMapsPerLight); - double deltaBias = 0; + double ratio = Settings::Manager::getFloat("split point uniform logarithmic ratio", "Shadows"); + double deltaBias = Settings::Manager::getFloat("split point bias", "Shadows"); if (sm_i == 0) r_start = -1.0; else @@ -691,7 +692,7 @@ namespace SceneUtil // compute the split point in main camera view double ciLog = n * pow(f / n, i / m); double ciUniform = n + (f - n) * i / m; - double ci = (ciLog + ciUniform) / 2 + deltaBias; + double ci = ratio * ciLog + (1.0 - ratio) * ciUniform + deltaBias; // work out where this is in light space osg::Vec3d worldSpacePos = frustum.eye + frustum.frustumCenterLine * ci; @@ -706,7 +707,7 @@ namespace SceneUtil // compute the split point in main camera view double ciLog = n * pow(f / n, (i + 1) / m); double ciUniform = n + (f - n) * (i + 1) / m; - double ci = (ciLog + ciUniform) / 2 + deltaBias; + double ci = ratio * ciLog + (1.0 - ratio) * ciUniform + deltaBias; // work out where this is in light space osg::Vec3d worldSpacePos = frustum.eye + frustum.frustumCenterLine * ci; diff --git a/docs/source/reference/modding/settings/shadows.rst b/docs/source/reference/modding/settings/shadows.rst index d8e8624795..334663fe8f 100644 --- a/docs/source/reference/modding/settings/shadows.rst +++ b/docs/source/reference/modding/settings/shadows.rst @@ -86,4 +86,39 @@ Potentially decreases performance. -Note: Right now, there is no setting allowing toggling of shadows for statics \ No newline at end of file +Note: Right now, there is no setting allowing toggling of shadows for statics + +Expert settings +*************** + +You probably shouldn't be changing these if you haven't read `this paper on Parallel Split Shadow Maps `_ and understood how they interact with the transformation used with Light Space Perspective Shadow Maps. +If you have, then you may get better results tuning these for your specific view distance. + +split point uniform logarithmic ratio +------------------------------------- + +:Type: float +:Range: 0.0-1.0 for sensible results. Other values may 'work' but could behave bizarrely. +:Default: 0.5 + +Controls the ratio of :math:`C_i^{log}` versus :math:`C_i^{uniform}` used to form the Practical Split Scheme as described in the linked paper. + +split point bias +---------------- + +:Type: float +:Range: Any value supported by C++ floats on your platform, although undesirable behaviour is more likely to appear the further the value is from zero. +:Default: 0.0 + +The :math:`\delta_{bias}` parameter used to form the Practical Split Scheme as described in the linked paper. + +minimum lispsm near far ratio +----------------------------- + +:Type: float +:Range: Must be greater than zero. +:Default: 0.25 + +Controls the minimum near/far ratio for the Light Space Perspective Shadow Map transformation. +Helps prevent too much detail being brought towards the camera at the expense of detail further from the camera. +Increasing this pushes detail further away by moving the frustum apex further from the near plane. \ No newline at end of file diff --git a/files/settings-default.cfg b/files/settings-default.cfg index bc18302424..49615dc68e 100644 --- a/files/settings-default.cfg +++ b/files/settings-default.cfg @@ -475,12 +475,18 @@ companion h = 0.375 enable shadows = false # How many shadow maps to use - more of these means each shadow map texel covers less area, producing better looking shadows, but may decrease performance. number of shadow maps = 1 +# Indirectly controls where to split the shadow map(s). Values closer to 1.0 bring more detail closer to the camera (potentially excessively so), and values closer to 0.0 spread it more evenly across the whole viewing distance. 0.5 is recommended for most viewing distances by the original Parallel Split Shadow Maps paper, but this does not take into account use of a Light Space Perspective transformation, so other values may be preferable. If some of the terms used here go over your head, you probably don't want to change this, especially not without reading the associated papers first. +split point uniform logarithmic ratio = 0.5 +# Indirectly controls where to split the shadow map(s). Positive values move split points away from the camera and negative values move them towards the camera. Intended to be used in conjunction with changes to 'split point uniform logarithmic ratio' to counteract side effects, but may cause additional, more serious side effects. Read the Parallel Split Shadow Maps paper by F Zhang et al before changing. +split point bias = 0.0 # Enable the debug hud to see what the shadow map(s) contain. enable debug hud = false # Attempt to better use the shadow map by making them cover a smaller area. Especially helpful when looking downwards with a high viewing distance. The performance impact of this may be very large. compute tight scene bounds = false # How large to make the shadow map(s). Higher values increase GPU load, but can produce better-looking results. Power-of-two values may turn out to be faster on some GPU/driver combinations. shadow map resolution = 1024 +# Controls the minimum near/far ratio for the Light Space Perspective Shadow Map transformation. Helps prevent too much detail being brought towards the camera at the expense of detail further from the camera. Increasing this pushes detail further away. +minimum lispsm near far ratio = 0.25 # Allow actors to cast shadows. Potentially decreases performance. actor shadows = false # Allow the player to cast shadows. Potentially decreases performance.