- enabled the linear shadowmap filter.

Although this doesn't look as good as the PCF version it is a lot less calculation intensive and therefore more suitable for weaker hardware.
It also tends to bleed through walls a lot less.
This commit is contained in:
Christoph Oelckers 2018-09-29 13:23:40 +02:00
parent 86c7e87767
commit c8852b8fea
6 changed files with 26 additions and 18 deletions

View File

@ -68,6 +68,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
int uViewHeight; // Software fuzz scaling int uViewHeight; // Software fuzz scaling
float uClipHeight; float uClipHeight;
float uClipHeightDirection; float uClipHeightDirection;
int uShadowmapFilter;
}; };
)"; )";

View File

@ -280,5 +280,6 @@ void HWViewpointUniforms::SetDefaults()
mGlobVis = (float)R_GetGlobVis(r_viewwindow, r_visibility) / 32.f; mGlobVis = (float)R_GetGlobVis(r_viewwindow, r_visibility) / 32.f;
mPalLightLevels = static_cast<int>(gl_bandedswlight) | (static_cast<int>(gl_fogmode) << 8); mPalLightLevels = static_cast<int>(gl_bandedswlight) | (static_cast<int>(gl_fogmode) << 8);
mClipLine.X = -10000000.0f; mClipLine.X = -10000000.0f;
mShadowmapFilter = gl_shadowmap_filter;
} }

View File

@ -16,6 +16,7 @@ struct HWViewpointUniforms
int mViewHeight = 0; int mViewHeight = 0;
float mClipHeight = 0.f; float mClipHeight = 0.f;
float mClipHeightDirection = 0.f; float mClipHeightDirection = 0.f;
int mShadowmapFilter = 1;
void CalcDependencies() void CalcDependencies()
{ {

View File

@ -132,3 +132,5 @@ 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)

View File

@ -69,3 +69,5 @@ EXTERN_CVAR(Bool, gl_billboard_faces_camera)
EXTERN_CVAR(Bool, gl_billboard_particles) 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)

View File

@ -218,9 +218,6 @@ float sampleShadowmapLinear(vec2 dir, float v)
#define PCF_FILTER_STEP_COUNT 3 #define PCF_FILTER_STEP_COUNT 3
#define PCF_COUNT (PCF_FILTER_STEP_COUNT * 2 + 1) #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) float shadowmapAttenuation(vec4 lightpos, float shadowIndex)
{ {
if (shadowIndex >= 1024.0) if (shadowIndex >= 1024.0)
@ -235,23 +232,27 @@ float shadowmapAttenuation(vec4 lightpos, float shadowIndex)
vec2 dir = ray / length; vec2 dir = ray / length;
#if defined(USE_LINEAR_SHADOW_FILTER) if (uShadowmapFilter == 0)
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++)
{ {
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
#else // nearest 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++)
{
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 ray -= dir * 6.0; // Shadow acne margin
return sampleShadowmap(ray, v); return sampleShadowmap(ray, v);
#endif #endif