Add reducing shadows quality for smaller local lights

This commit is contained in:
Wojtek Figat
2024-04-04 13:29:38 +02:00
parent 61323f8526
commit 3d0d41ebff
2 changed files with 12 additions and 6 deletions

View File

@@ -568,7 +568,7 @@ void ShadowsPass::Dispose()
void ShadowsPass::SetupShadows(RenderContext& renderContext, RenderContextBatch& renderContextBatch)
{
PROFILE_CPU();
maxShadowsQuality = Math::Clamp(Math::Min<int32>((int32)Graphics::ShadowsQuality, (int32)renderContext.View.MaxShadowsQuality), 0, (int32)Quality::MAX - 1);
_maxShadowsQuality = Math::Clamp(Math::Min<int32>((int32)Graphics::ShadowsQuality, (int32)renderContext.View.MaxShadowsQuality), 0, (int32)Quality::MAX - 1);
// Early out and skip shadows setup if no lights is actively casting shadows
// RenderBuffers will automatically free any old ShadowsCustomBuffer after a few frames if we don't update LastFrameUsed
@@ -902,14 +902,20 @@ void ShadowsPass::RenderShadowMask(RenderContextBatch& renderContextBatch, Rende
RenderContext& renderContext = renderContextBatch.GetMainContext();
const ShadowsCustomBuffer& shadows = *renderContext.Buffers->FindCustomBuffer<ShadowsCustomBuffer>(TEXT("Shadows"));
ASSERT(shadows.LastFrameUsed == Engine::FrameCount);
const ShadowAtlasLight& atlasLight = shadows.Lights.At(light.ID);
const float sphereModelScale = 3.0f;
auto& view = renderContext.View;
auto shader = _shader->GetShader();
const bool isLocalLight = light.IsPointLight || light.IsSpotLight;
// TODO: here we can use lower shadows quality based on light distance to view (LOD switching) and per light setting for max quality
int32 shadowQuality = maxShadowsQuality;
int32 shadowQuality = _maxShadowsQuality;
if (isLocalLight)
{
// Reduce shadows quality for smaller lights
if (light.ScreenSize < 0.25f)
shadowQuality--;
if (light.ScreenSize < 0.1f)
shadowQuality--;
shadowQuality = Math::Max(shadowQuality, 0);
}
// Setup shader data
Data sperLight;

View File

@@ -22,7 +22,7 @@ private:
GPUPipelineStatePermutationsPs<static_cast<int32>(Quality::MAX) * 2> _psShadowPoint;
GPUPipelineStatePermutationsPs<static_cast<int32>(Quality::MAX) * 2> _psShadowSpot;
PixelFormat _shadowMapFormat; // Cached on initialization
int32 maxShadowsQuality = 0; // Cached state for the current frame rendering (setup via Prepare)
int32 _maxShadowsQuality = 0; // Cached state for the current frame rendering (setup via Prepare)
public:
/// <summary>