Skip to content

Commit

Permalink
Use fixed kernel & tune shadow height & remove translation string
Browse files Browse the repository at this point in the history
  • Loading branch information
CodingJellyfish committed Feb 5, 2025
1 parent 7d8a4bb commit 33cf0a3
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 57 deletions.
8 changes: 0 additions & 8 deletions data/gui/dialogs/custom_video_settings.stkgui
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,6 @@
<spacer width="10" height="10"/>
<label text="Ambient occlusion" I18N="Video settings"/>
</div>

<spacer height="4" width="10" />

<div layout="horizontal-row" proportion="1" height="fit">
<checkbox id="pcss"/>
<spacer width="10" height="10"/>
<label text="Soft shadows" I18N="Video settings"/>
</div>
</div>

<spacer height="4" width="10" />
Expand Down
42 changes: 24 additions & 18 deletions data/shaders/sunlightshadowpcss.frag
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Implementation from https://github.com/google/filament/blob/main/shaders/src/surface_shadowing.fs
uniform sampler2D ntex;
#if defined(GL_ES) && defined(GL_FRAGMENT_PRECISION_HIGH)
uniform highp sampler2D dtex;
Expand Down Expand Up @@ -58,11 +59,16 @@ vec2 vogel_disk_16[16] = vec2[](
vec2(-0.1133270115046468, -0.9490025827627441)
);

vec2 vogel_disk_4[4] = vec2[](
vec2(0.21848650099008202, -0.09211370200809937),
vec2(-0.5866112654782878, 0.32153793477769893),
vec2(-0.06595078555407359, -0.879656059066481),
vec2(0.43407555004227927, 0.6502318262968816)
// https://learn.microsoft.com/en-us/windows/win32/api/d3d11/ne-d3d11-d3d11_standard_multisample_quality_levels?redirectedfrom=MSDN
vec2 sample_point_pos[8] = vec2[](
vec2( 0.125, -0.375),
vec2(-0.125, 0.375),
vec2( 0.625, 0.125),
vec2(-0.375, -0.625),
vec2(-0.625, 0.625),
vec2(-0.875, -0.125),
vec2( 0.375, 0.875),
vec2( 0.875, -0.875)
);

float interleavedGradientNoise(vec2 w)
Expand Down Expand Up @@ -95,27 +101,26 @@ mat2 getRandomRotationMatrix(vec2 fragCoord)
void blockerSearchAndFilter(out float occludedCount, out float z_occSum,
vec2 uv, float z_rec, uint layer, vec2 filterRadii, mat2 R, vec2 dz_duv)
{
occludedCount = 0.0;
z_occSum = 0.0;
for (uint i = 0u; i < 4u; i++)
// Make sure no light leaking
float z_occ = texture(shadowtexdepth, vec3(uv, float(layer))).r;
float dz = z_rec - z_occ;
float occluded = 0.01 * step(0., dz);
occludedCount = occluded;
z_occSum = z_occ * occluded;

for (uint i = 0u; i < 8u; i++)
{
vec2 duv = R * (vogel_disk_4[i] * filterRadii);
vec2 duv = R * sample_point_pos[i] * filterRadii;
vec2 tc = clamp(uv + duv, vec2(0.), vec2(1.));

float z_occ = texture(shadowtexdepth, vec3(tc, float(layer))).r;

// receiver plane depth bias
float z_bias = dot(dz_duv, duv);

float z_occ = texture(shadowtexdepth, vec3(tc, float(layer))).r;
float dz = z_rec - z_occ; // dz>0 when blocker is between receiver and light
float occluded = step(z_bias, dz);
occludedCount += occluded;
z_occSum += z_occ * occluded;
}
float z_occ = texture(shadowtexdepth, vec3(uv, float(layer))).r;
float dz = z_rec - z_occ;
float occluded = step(0., dz);
occludedCount += occluded;
z_occSum += z_occ * occluded;
}

float filterPCSS(vec2 uv, float z_rec, uint layer,
Expand Down Expand Up @@ -152,8 +157,9 @@ float getShadowFactor(vec3 position, vec3 bbox, vec2 dz_duv, uint layer)
}

float penumbraRatio = 1.0 - z_occSum / occludedCount / position.z;
vec2 radius = max(penumbra / bbox.xy * penumbraRatio, vec2(0.5 / shadow_res));

float percentageOccluded = filterPCSS(position.xy, position.z, layer, penumbra / bbox.xy * penumbraRatio, R, dz_duv);
float percentageOccluded = filterPCSS(position.xy, position.z, layer, radius, R, dz_duv);

return percentageOccluded;
}
Expand Down
8 changes: 4 additions & 4 deletions src/config/user_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1013,14 +1013,14 @@ namespace UserConfigParams
PARAM_DEFAULT(BoolUserConfigParam(true,
"light_scatter", &m_graphics_quality,
"Enable light scattering shaders") );
PARAM_PREFIX BoolUserConfigParam m_pcss
PARAM_DEFAULT(BoolUserConfigParam(false,
"pcss", &m_graphics_quality,
"Enable Percentage Closer Soft Shadows (needs high shadow resolution)") );
PARAM_PREFIX IntUserConfigParam m_shadows_resolution
PARAM_DEFAULT( IntUserConfigParam(0,
"shadows_resolution", &m_graphics_quality,
"Shadow resolution (0 = disabled") );
PARAM_PREFIX IntUserConfigParam m_pcss_threshold
PARAM_DEFAULT( IntUserConfigParam(2048,
"pcss_threshold", &m_graphics_quality,
"Enable Percentage Closer Soft Shadows when shadow resolution is higher than this value") );
PARAM_PREFIX BoolUserConfigParam m_degraded_IBL
PARAM_DEFAULT(BoolUserConfigParam(true,
"Degraded_IBL", &m_graphics_quality,
Expand Down
2 changes: 1 addition & 1 deletion src/graphics/lighting_passes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ void LightingPasses::renderLights( bool has_shadow,
glDisable(GL_DEPTH_TEST);
glBlendFunc(GL_ONE, GL_ONE);
glBlendEquation(GL_FUNC_ADD);
if (UserConfigParams::m_pcss)
if (UserConfigParams::m_pcss_threshold <= UserConfigParams::m_shadows_resolution)
{
ShadowedSunLightShaderPCSS::getInstance()->render(normal_depth_texture,
depth_stencil_texture,
Expand Down
6 changes: 4 additions & 2 deletions src/graphics/shadow_matrices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,14 @@ core::matrix4 ShadowMatrices::getTightestFitOrthoProj(const core::matrix4 &trans
// Prevent Matrix without extend
if (left == right || up == down)
return tmp_matrix;

float vnear = std::min((zmax + zmin) / 2 - 200, zmin); // 200m above karts
tmp_matrix.buildProjectionMatrixOrthoLH(left, right,
down, up,
zmin - 100, zmax);
vnear, zmax);
bounding_box_extent.X = right - left;
bounding_box_extent.Y = down - up;
bounding_box_extent.Z = zmax - zmin + 100;
bounding_box_extent.Z = zmax - vnear;
return tmp_matrix;
} // getTightestFitOrthoProj

Expand Down
10 changes: 0 additions & 10 deletions src/states_screens/dialogs/custom_video_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ void CustomVideoSettingsDialog::beforeAddingWidgets()
getWidget<CheckBoxWidget>("ssao")->setState(UserConfigParams::m_ssao);
getWidget<CheckBoxWidget>("bloom")->setState(UserConfigParams::m_bloom);
getWidget<CheckBoxWidget>("lightscattering")->setState(UserConfigParams::m_light_scatter);
getWidget<CheckBoxWidget>("pcss")->setState(UserConfigParams::m_pcss);
if (CVS->isEXTTextureCompressionS3TCUsable())
{
getWidget<CheckBoxWidget>("texture_compression")->setState(UserConfigParams::m_texture_compression);
Expand Down Expand Up @@ -190,9 +189,6 @@ GUIEngine::EventPropagation CustomVideoSettingsDialog::processEvent(const std::s
UserConfigParams::m_light_scatter =
advanced_pipeline && getWidget<CheckBoxWidget>("lightscattering")->getState();

UserConfigParams::m_pcss =
advanced_pipeline && getWidget<CheckBoxWidget>("pcss")->getState();

UserConfigParams::m_texture_compression =
getWidget<CheckBoxWidget>("texture_compression")->getState();
#ifndef SERVER_ONLY
Expand Down Expand Up @@ -235,10 +231,6 @@ GUIEngine::EventPropagation CustomVideoSettingsDialog::processEvent(const std::s
{
updateActivation();
}
else if (eventSource == "shadows")
{
updateActivation();
}
#endif
return GUIEngine::EVENT_LET;
} // processEvent
Expand All @@ -249,7 +241,6 @@ void CustomVideoSettingsDialog::updateActivation()
{
#ifndef SERVER_ONLY
bool light = getWidget<CheckBoxWidget>("dynamiclight")->getState();
bool shadows = getWidget<SpinnerWidget>("shadows")->getValue();
if (!CVS->isGLSL())
{
getWidget<CheckBoxWidget>("dynamiclight")->setActive(false);
Expand All @@ -267,6 +258,5 @@ void CustomVideoSettingsDialog::updateActivation()
getWidget<CheckBoxWidget>("glow")->setActive(light);
getWidget<CheckBoxWidget>("bloom")->setActive(light);
getWidget<CheckBoxWidget>("lightscattering")->setActive(light);
getWidget<CheckBoxWidget>("pcss")->setActive(light & shadows);
#endif
} // updateActivation
21 changes: 8 additions & 13 deletions src/states_screens/options/options_screen_video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,55 +43,55 @@ void OptionsScreenVideo::initPresets()
false /* light */, 0 /* shadow */, false /* bloom */, false /* lightshaft */,
false /* glow */, false /* mlaa */, false /* ssao */, false /* light scatter */,
false /* animatedCharacters */, 1 /* particles */, 0 /* image_quality */,
true /* degraded IBL */, 0 /* Geometry Detail */, false /* pcss */
true /* degraded IBL */, 0 /* Geometry Detail */
});

m_presets.push_back // Level 2
({
false /* light */, 0 /* shadow */, false /* bloom */, false /* lightshaft */,
false /* glow */, false /* mlaa */, false /* ssao */, false /* light scatter */,
true /* animatedCharacters */, 2 /* particles */, 1 /* image_quality */,
true /* degraded IBL */, 1 /* Geometry Detail */, false /* pcss */
true /* degraded IBL */, 1 /* Geometry Detail */
});

m_presets.push_back // Level 3
({
true /* light */, 0 /* shadow */, false /* bloom */, false /* lightshaft */,
false /* glow */, false /* mlaa */, false /* ssao */, false /* light scatter */,
true /* animatedCharacters */, 2 /* particles */, 1 /* image_quality */,
true /* degraded IBL */, 2 /* Geometry Detail */, false /* pcss */
true /* degraded IBL */, 2 /* Geometry Detail */
});

m_presets.push_back // Level 4
({
true /* light */, 0 /* shadow */, false /* bloom */, true /* lightshaft */,
true /* glow */, true /* mlaa */, false /* ssao */, true /* light scatter */,
true /* animatedCharacters */, 2 /* particles */, 2 /* image_quality */,
false /* degraded IBL */, 3 /* Geometry Detail */, false /* pcss */
false /* degraded IBL */, 3 /* Geometry Detail */
});

m_presets.push_back // Level 5
({
true /* light */, 512 /* shadow */, true /* bloom */, true /* lightshaft */,
true /* glow */, true /* mlaa */, false /* ssao */, true /* light scatter */,
true /* animatedCharacters */, 2 /* particles */, 3 /* image_quality */,
false /* degraded IBL */, 3 /* Geometry Detail */, false /* pcss */
false /* degraded IBL */, 3 /* Geometry Detail */
});

m_presets.push_back // Level 6
({
true /* light */, 1024 /* shadow */, true /* bloom */, true /* lightshaft */,
true /* glow */, true /* mlaa */, true /* ssao */, true /* light scatter */,
true /* animatedCharacters */, 2 /* particles */, 3 /* image_quality */,
false /* degraded IBL */, 4 /* Geometry Detail */, false /* pcss */
false /* degraded IBL */, 4 /* Geometry Detail */
});

m_presets.push_back // Level 7
({
true /* light */, 2048 /* shadow */, true /* bloom */, true /* lightshaft */,
true /* glow */, true /* mlaa */, true /* ssao */, true /* light scatter */,
true /* animatedCharacters */, 2 /* particles */, 3 /* image_quality */,
false /* degraded IBL */, 5 /* Geometry Detail */, true /* pcss */
false /* degraded IBL */, 5 /* Geometry Detail */
});

m_blur_presets.push_back
Expand Down Expand Up @@ -358,8 +358,7 @@ void OptionsScreenVideo::updateGfxSlider()
m_presets[l].degraded_ibl == UserConfigParams::m_degraded_IBL &&
m_presets[l].geometry_detail == (UserConfigParams::m_geometry_level == 0 ? 2 :
UserConfigParams::m_geometry_level == 2 ? 0 :
UserConfigParams::m_geometry_level) &&
m_presets[l].pcss == UserConfigParams::m_pcss)
UserConfigParams::m_geometry_level))
{
gfx->setValue(l + 1);
found = true;
Expand Down Expand Up @@ -498,9 +497,6 @@ void OptionsScreenVideo::updateTooltip()
//I18N: in graphical options
tooltip = tooltip + L"\n" + _("Ambient occlusion: %s",
UserConfigParams::m_ssao ? enabled : disabled);
//I18N: in graphical options
tooltip = tooltip + L"\n" + _("Soft shadows: %s",
UserConfigParams::m_pcss ? enabled : disabled);

//I18N: in graphical options
tooltip = tooltip + L"\n" + _("Animated Characters: %s",
Expand Down Expand Up @@ -609,7 +605,6 @@ void OptionsScreenVideo::eventCallback(Widget* widget, const std::string& name,
UserConfigParams::m_geometry_level = (m_presets[level].geometry_detail == 0 ? 2 :
m_presets[level].geometry_detail == 2 ? 0 :
m_presets[level].geometry_detail);
UserConfigParams::m_pcss = m_presets[level].pcss;

updateGfxSlider();
}
Expand Down
1 change: 0 additions & 1 deletion src/states_screens/options/options_screen_video.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ struct GFXPreset
int image_quality;
bool degraded_ibl;
int geometry_detail;
bool pcss;
};

struct BlurPreset
Expand Down

0 comments on commit 33cf0a3

Please sign in to comment.