move gl_light_shadow_filter from HWViewpointUniforms to VkShaderKey

This commit is contained in:
Ricardo Luís Vaz Silva 2025-01-02 11:30:44 -03:00 committed by Magnus Norddahl
commit e75d8d35eb
8 changed files with 24 additions and 18 deletions

View file

@ -645,7 +645,6 @@ public:
matrices.mGlobVis = 1.f;
matrices.mPalLightLevels = palLightLevels;
matrices.mClipLine.X = -10000000.0f;
matrices.mShadowFilter = gl_light_shadow_filter;
matrices.mProjectionMatrix.ortho(0, (float)width, (float)height, 0, -1.0f, 1.0f);
matrices.CalcDependencies();
return SetViewpoint(matrices);

View file

@ -37,7 +37,6 @@ struct HWViewpointUniforms
int mViewHeight = 0;
float mClipHeight = 0.f;
float mClipHeightDirection = 0.f;
int mShadowFilter = 1;
int mLightTilesWidth = 0;

View file

@ -256,6 +256,11 @@ std::unique_ptr<VulkanShader> VkShaderManager::LoadFragShader(FString shadername
if (key.UseRaytrace) definesBlock << "#define USE_RAYTRACE\n";
if (key.UseRaytracePrecise) definesBlock << "#define USE_RAYTRACE_PRECISE\n";
definesBlock << "#define SHADOWMAP_FILTER ";
definesBlock << std::to_string(key.ShadowmapFilter).c_str();
definesBlock << "\n";
if (key.UseShadowmap) definesBlock << "#define USE_SHADOWMAP\n";
if (key.UseLevelMesh) definesBlock << "#define USE_LEVELMESH\n";

View file

@ -101,7 +101,8 @@ public:
uint64_t LightBlendMode : 2; // LIGHT_BLEND_CLAMPED , LIGHT_BLEND_COLORED_CLAMP , LIGHT_BLEND_UNCLAMPED
uint64_t LightAttenuationMode : 1; // LIGHT_ATTENUATION_LINEAR , LIGHT_ATTENUATION_INVERSE_SQUARE
uint64_t UseRaytracePrecise : 1; // USE_RAYTRACE_PRECISE
uint64_t Unused : 36;
uint64_t ShadowmapFilter : 4; // SHADOWMAP_FILTER
uint64_t Unused : 32;
};
uint64_t AsQWORD = 0;
};

View file

@ -305,6 +305,7 @@ void VkRenderState::ApplyRenderPass(int dt)
pipelineKey.ShaderKey.UseShadowmap = gl_light_shadows == 1;
pipelineKey.ShaderKey.UseRaytrace = gl_light_shadows >= 2;
pipelineKey.ShaderKey.UseRaytracePrecise = gl_light_shadows >= 3;
pipelineKey.ShaderKey.ShadowmapFilter = std::clamp(int(gl_light_shadow_filter), 0, 15);
pipelineKey.ShaderKey.GBufferPass = mRenderTarget.DrawBuffers > 1;
@ -1069,6 +1070,8 @@ void VkRenderState::ApplyLevelMeshPipeline(VulkanCommandBuffer* cmdbuffer, VkPip
pipelineKey.ShaderKey.UseShadowmap = gl_light_shadows == 1;
pipelineKey.ShaderKey.UseRaytrace = gl_light_shadows >= 2;
pipelineKey.ShaderKey.UseRaytracePrecise = gl_light_shadows >= 3;
pipelineKey.ShaderKey.ShadowmapFilter = std::clamp(int(gl_light_shadow_filter), 0, 15);
pipelineKey.ShaderKey.GBufferPass = mRenderTarget.DrawBuffers > 1;
// State overridden by the renderstate drawing the mesh

View file

@ -128,7 +128,6 @@ void HWDrawInfo::StartScene(FRenderViewpoint &parentvp, HWViewpointUniforms *uni
VPUniforms.mPalLightLevels = static_cast<int>(gl_bandedswlight) | (static_cast<int>(gl_fogmode) << 8) | ((int)lightmode << 16);
}
VPUniforms.mClipLine.X = -10000000.0f;
VPUniforms.mShadowFilter = static_cast<int>(gl_light_shadow_filter);
}
mClipper->SetViewpoint(Viewpoint);
vClipper->SetViewpoint(Viewpoint);

View file

@ -16,7 +16,6 @@ layout(set = 1, binding = 0, std140) uniform readonly ViewpointUBO
int uViewHeight; // Software fuzz scaling
float uClipHeight;
float uClipHeightDirection;
int uShadowmapFilter;
int uLightTilesWidth; // Levelmesh light tiles
};

View file

@ -48,7 +48,7 @@ float traceHit(vec3 origin, vec3 direction, float dist)
#endif
}
float traceShadow(vec4 lightpos, int quality, float softShadowRadius)
float traceShadow(vec4 lightpos, float softShadowRadius)
{
vec3 origin = pixelpos.xyz + vWorldNormal.xyz;
vec3 target = lightpos.xyz + 0.01; // nudge light position slightly as Doom maps tend to have their lights perfectly aligned with planes
@ -56,7 +56,10 @@ float traceShadow(vec4 lightpos, int quality, float softShadowRadius)
vec3 direction = normalize(target - origin);
float dist = distance(origin, target);
if (quality == 0 || softShadowRadius == 0)
#if SHADOWMAP_FILTER == 0
return traceHit(origin, direction, dist);
#else
if (softShadowRadius == 0)
{
return traceHit(origin, direction, dist);
}
@ -67,7 +70,7 @@ float traceShadow(vec4 lightpos, int quality, float softShadowRadius)
vec3 ydir = cross(direction, xdir);
float sum = 0.0;
int step_count = quality * 4;
const int step_count = SHADOWMAP_FILTER * 4;
for (int i = 0; i < step_count; i++)
{
vec2 gridoffset = getVogelDiskSample(i, step_count, gl_FragCoord.x + gl_FragCoord.y * 13.37) * softShadowRadius;
@ -76,13 +79,14 @@ float traceShadow(vec4 lightpos, int quality, float softShadowRadius)
}
return (sum / step_count);
}
#endif
}
float shadowAttenuation(vec4 lightpos, float lightcolorA, float softShadowRadius)
{
if (lightpos.w > 1000000.0)
return 1.0; // Sunlight
return traceShadow(lightpos, uShadowmapFilter, softShadowRadius);
return traceShadow(lightpos, softShadowRadius);
}
#elif defined(USE_SHADOWMAP)
@ -172,7 +176,7 @@ float sampleShadowmapPCF(vec3 planePoint, float v)
float texelPos = floor(shadowDirToU(ray.xz) * scale);
float sum = 0.0;
float step_count = uShadowmapFilter;
float step_count = SHADOWMAP_FILTER;
texelPos -= step_count + 0.5;
for (float x = -step_count; x <= step_count; x++)
@ -189,7 +193,7 @@ float sampleShadowmapPCF(vec3 planePoint, float v)
sum += step(dist2, texture(ShadowMap, vec2(u, v)).x);
texelPos++;
}
return sum / (uShadowmapFilter * 2.0 + 1.0);
return sum / (SHADOWMAP_FILTER * 2.0 + 1.0);
}
float shadowmapAttenuation(vec4 lightpos, float shadowIndex)
@ -201,15 +205,12 @@ float shadowmapAttenuation(vec4 lightpos, float shadowIndex)
return 1.0; // Light is too close
float v = (shadowIndex + 0.5) / 1024.0;
if (uShadowmapFilter == 0)
{
#if SHADOWMAP_FILTER == 0
return sampleShadowmap(planePoint, v);
}
else
{
#else
return sampleShadowmapPCF(planePoint, v);
}
#endif
}
float shadowAttenuation(vec4 lightpos, float lightcolorA, float softShadowRadius)