diff --git a/Source/Engine/Renderer/ShadowsPass.cpp b/Source/Engine/Renderer/ShadowsPass.cpp index bbd036592..64f043d28 100644 --- a/Source/Engine/Renderer/ShadowsPass.cpp +++ b/Source/Engine/Renderer/ShadowsPass.cpp @@ -568,7 +568,7 @@ void ShadowsPass::Dispose() void ShadowsPass::SetupShadows(RenderContext& renderContext, RenderContextBatch& renderContextBatch) { PROFILE_CPU(); - maxShadowsQuality = Math::Clamp(Math::Min((int32)Graphics::ShadowsQuality, (int32)renderContext.View.MaxShadowsQuality), 0, (int32)Quality::MAX - 1); + _maxShadowsQuality = Math::Clamp(Math::Min((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(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; diff --git a/Source/Engine/Renderer/ShadowsPass.h b/Source/Engine/Renderer/ShadowsPass.h index 17d21b6d6..5f8558abd 100644 --- a/Source/Engine/Renderer/ShadowsPass.h +++ b/Source/Engine/Renderer/ShadowsPass.h @@ -22,7 +22,7 @@ private: GPUPipelineStatePermutationsPs(Quality::MAX) * 2> _psShadowPoint; GPUPipelineStatePermutationsPs(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: ///