From 797f88a6c8e81a38238158cb5e1509265cd7b198 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 3 Oct 2018 13:45:54 +0200 Subject: [PATCH] - some tweaking of shadowmap filter setting to allow changing the PCF filter's number of samplings. --- src/hwrenderer/utility/hw_cvars.cpp | 4 +++- src/hwrenderer/utility/hw_cvars.h | 2 +- wadsrc/static/shaders/glsl/main.fp | 13 ++++++------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/hwrenderer/utility/hw_cvars.cpp b/src/hwrenderer/utility/hw_cvars.cpp index 563bdd9f8..7188a96b3 100644 --- a/src/hwrenderer/utility/hw_cvars.cpp +++ b/src/hwrenderer/utility/hw_cvars.cpp @@ -133,4 +133,6 @@ CUSTOM_CVAR(Int, gl_fuzztype, 0, CVAR_ARCHIVE) if (self < 0 || self > 8) self = 0; } -CVAR(Bool, gl_shadowmap_filter, 1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) \ No newline at end of file +CUSTOM_CVAR(Int, gl_shadowmap_filter, 1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) +{ + if (self < 0 || self > 8) self = 1; \ No newline at end of file diff --git a/src/hwrenderer/utility/hw_cvars.h b/src/hwrenderer/utility/hw_cvars.h index eb1aafe44..8e4ebbca8 100644 --- a/src/hwrenderer/utility/hw_cvars.h +++ b/src/hwrenderer/utility/hw_cvars.h @@ -70,4 +70,4 @@ EXTERN_CVAR(Bool, gl_billboard_particles) EXTERN_CVAR(Int, gl_enhanced_nv_stealth) EXTERN_CVAR(Int, gl_fuzztype) -EXTERN_CVAR(Bool, gl_shadowmap_filter) \ No newline at end of file +EXTERN_CVAR(Int, gl_shadowmap_filter) \ No newline at end of file diff --git a/wadsrc/static/shaders/glsl/main.fp b/wadsrc/static/shaders/glsl/main.fp index 714f63ed2..c78bb0e02 100644 --- a/wadsrc/static/shaders/glsl/main.fp +++ b/wadsrc/static/shaders/glsl/main.fp @@ -215,9 +215,6 @@ float sampleShadowmapLinear(vec2 dir, float v) // //=========================================================================== -#define PCF_FILTER_STEP_COUNT 3 -#define PCF_COUNT (PCF_FILTER_STEP_COUNT * 2 + 1) - float shadowmapAttenuation(vec4 lightpos, float shadowIndex) { if (shadowIndex >= 1024.0) @@ -232,7 +229,7 @@ float shadowmapAttenuation(vec4 lightpos, float shadowIndex) vec2 dir = ray / length; - if (uShadowmapFilter == 0) + if (uShadowmapFilter <= 0) { ray -= dir * 2.0; // Shadow acne margin return sampleShadowmapLinear(ray, v); @@ -246,11 +243,13 @@ float shadowmapAttenuation(vec4 lightpos, float shadowIndex) vec2 bias = dir * 10.0; float sum = 0.0; - for (float x = -PCF_FILTER_STEP_COUNT; x <= PCF_FILTER_STEP_COUNT; x++) + float step_count = ((uShadowmapFilter - 1) / 2.); + + for (float x = -step_count; x <= step_count; x++) { - sum += sampleShadowmap(ray + normal * x - bias * abs(x), v); + sum += sampleShadowmap(ray + normal * x /*- bias * abs(x)*/, v); } - return sum / PCF_COUNT; + return sum / uShadowmapFilter; } #if 0 // nearest shadow filter (not used) ray -= dir * 6.0; // Shadow acne margin