- some tweaking of shadowmap filter setting to allow changing the PCF filter's number of samplings.

This commit is contained in:
Christoph Oelckers 2018-10-03 13:45:54 +02:00
parent 35bb2d3079
commit 797f88a6c8
3 changed files with 10 additions and 9 deletions

View file

@ -133,4 +133,6 @@ CUSTOM_CVAR(Int, gl_fuzztype, 0, CVAR_ARCHIVE)
if (self < 0 || self > 8) self = 0; if (self < 0 || self > 8) self = 0;
} }
CVAR(Bool, gl_shadowmap_filter, 1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) CUSTOM_CVAR(Int, gl_shadowmap_filter, 1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
{
if (self < 0 || self > 8) self = 1;

View file

@ -70,4 +70,4 @@ EXTERN_CVAR(Bool, gl_billboard_particles)
EXTERN_CVAR(Int, gl_enhanced_nv_stealth) EXTERN_CVAR(Int, gl_enhanced_nv_stealth)
EXTERN_CVAR(Int, gl_fuzztype) EXTERN_CVAR(Int, gl_fuzztype)
EXTERN_CVAR(Bool, gl_shadowmap_filter) EXTERN_CVAR(Int, gl_shadowmap_filter)

View file

@ -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) float shadowmapAttenuation(vec4 lightpos, float shadowIndex)
{ {
if (shadowIndex >= 1024.0) if (shadowIndex >= 1024.0)
@ -232,7 +229,7 @@ float shadowmapAttenuation(vec4 lightpos, float shadowIndex)
vec2 dir = ray / length; vec2 dir = ray / length;
if (uShadowmapFilter == 0) if (uShadowmapFilter <= 0)
{ {
ray -= dir * 2.0; // Shadow acne margin ray -= dir * 2.0; // Shadow acne margin
return sampleShadowmapLinear(ray, v); return sampleShadowmapLinear(ray, v);
@ -246,11 +243,13 @@ float shadowmapAttenuation(vec4 lightpos, float shadowIndex)
vec2 bias = dir * 10.0; vec2 bias = dir * 10.0;
float sum = 0.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) #if 0 // nearest shadow filter (not used)
ray -= dir * 6.0; // Shadow acne margin ray -= dir * 6.0; // Shadow acne margin