diff --git a/src/gl/shaders/gl_shader.cpp b/src/gl/shaders/gl_shader.cpp index e0d656038..564365341 100644 --- a/src/gl/shaders/gl_shader.cpp +++ b/src/gl/shaders/gl_shader.cpp @@ -68,6 +68,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char * int uViewHeight; // Software fuzz scaling float uClipHeight; float uClipHeightDirection; + int uShadowmapFilter; }; )"; diff --git a/src/hwrenderer/scene/hw_drawinfo.cpp b/src/hwrenderer/scene/hw_drawinfo.cpp index b5dce2247..c72f510ae 100644 --- a/src/hwrenderer/scene/hw_drawinfo.cpp +++ b/src/hwrenderer/scene/hw_drawinfo.cpp @@ -280,5 +280,6 @@ void HWViewpointUniforms::SetDefaults() mGlobVis = (float)R_GetGlobVis(r_viewwindow, r_visibility) / 32.f; mPalLightLevels = static_cast(gl_bandedswlight) | (static_cast(gl_fogmode) << 8); mClipLine.X = -10000000.0f; + mShadowmapFilter = gl_shadowmap_filter; } diff --git a/src/hwrenderer/scene/hw_viewpointuniforms.h b/src/hwrenderer/scene/hw_viewpointuniforms.h index 27a78aef4..1bd57faa0 100644 --- a/src/hwrenderer/scene/hw_viewpointuniforms.h +++ b/src/hwrenderer/scene/hw_viewpointuniforms.h @@ -16,6 +16,7 @@ struct HWViewpointUniforms int mViewHeight = 0; float mClipHeight = 0.f; float mClipHeightDirection = 0.f; + int mShadowmapFilter = 1; void CalcDependencies() { diff --git a/src/hwrenderer/utility/hw_cvars.cpp b/src/hwrenderer/utility/hw_cvars.cpp index c849e62d5..563bdd9f8 100644 --- a/src/hwrenderer/utility/hw_cvars.cpp +++ b/src/hwrenderer/utility/hw_cvars.cpp @@ -132,3 +132,5 @@ 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 diff --git a/src/hwrenderer/utility/hw_cvars.h b/src/hwrenderer/utility/hw_cvars.h index 440265930..eb1aafe44 100644 --- a/src/hwrenderer/utility/hw_cvars.h +++ b/src/hwrenderer/utility/hw_cvars.h @@ -69,3 +69,5 @@ EXTERN_CVAR(Bool, gl_billboard_faces_camera) 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 diff --git a/wadsrc/static/shaders/glsl/main.fp b/wadsrc/static/shaders/glsl/main.fp index 7a6c98436..714f63ed2 100644 --- a/wadsrc/static/shaders/glsl/main.fp +++ b/wadsrc/static/shaders/glsl/main.fp @@ -218,9 +218,6 @@ float sampleShadowmapLinear(vec2 dir, float v) #define PCF_FILTER_STEP_COUNT 3 #define PCF_COUNT (PCF_FILTER_STEP_COUNT * 2 + 1) -// #define USE_LINEAR_SHADOW_FILTER -#define USE_PCF_SHADOW_FILTER 1 - float shadowmapAttenuation(vec4 lightpos, float shadowIndex) { if (shadowIndex >= 1024.0) @@ -235,23 +232,27 @@ float shadowmapAttenuation(vec4 lightpos, float shadowIndex) vec2 dir = ray / length; -#if defined(USE_LINEAR_SHADOW_FILTER) - ray -= dir * 6.0; // Shadow acne margin - return sampleShadowmapLinear(ray, v); -#elif defined(USE_PCF_SHADOW_FILTER) - ray -= dir * 2.0; // Shadow acne margin - dir = dir * min(length / 50.0, 1.0); // avoid sampling behind light - - vec2 normal = vec2(-dir.y, dir.x); - vec2 bias = dir * 10.0; - - float sum = 0.0; - for (float x = -PCF_FILTER_STEP_COUNT; x <= PCF_FILTER_STEP_COUNT; x++) + if (uShadowmapFilter == 0) { - sum += sampleShadowmap(ray + normal * x - bias * abs(x), v); + ray -= dir * 2.0; // Shadow acne margin + return sampleShadowmapLinear(ray, v); } - return sum / PCF_COUNT; -#else // nearest shadow filter + else + { + ray -= dir * 2.0; // Shadow acne margin + dir = dir * min(length / 50.0, 1.0); // avoid sampling behind light + + vec2 normal = vec2(-dir.y, dir.x); + vec2 bias = dir * 10.0; + + float sum = 0.0; + for (float x = -PCF_FILTER_STEP_COUNT; x <= PCF_FILTER_STEP_COUNT; x++) + { + sum += sampleShadowmap(ray + normal * x - bias * abs(x), v); + } + return sum / PCF_COUNT; + } +#if 0 // nearest shadow filter (not used) ray -= dir * 6.0; // Shadow acne margin return sampleShadowmap(ray, v); #endif