Optimize local lights sphere mesh rendering to match the area better

This commit is contained in:
Wojtek Figat
2024-04-05 12:48:09 +02:00
parent 0cc6669cbd
commit 3efd1e4e84
6 changed files with 53 additions and 91 deletions

View File

@@ -158,7 +158,7 @@ bool ShadowsPass::Init()
// Load assets
_shader = Content::LoadAsyncInternal<Shader>(TEXT("Shaders/Shadows"));
_sphereModel = Content::LoadAsyncInternal<Model>(TEXT("Engine/Models/SphereLowPoly"));
_sphereModel = Content::LoadAsyncInternal<Model>(TEXT("Engine/Models/Sphere"));
if (_shader == nullptr || _sphereModel == nullptr)
return true;
@@ -891,7 +891,6 @@ 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 float sphereModelScale = 3.0f;
auto& view = renderContext.View;
auto shader = _shader->GetShader();
const bool isLocalLight = light.IsPointLight || light.IsSpotLight;
@@ -922,14 +921,12 @@ void ShadowsPass::RenderShadowMask(RenderContextBatch& renderContextBatch, Rende
if (isLocalLight)
{
// Calculate world view projection matrix for the light sphere
Matrix world, wvp, matrix;
Matrix::Scaling(((RenderLocalLightData&)light).Radius * sphereModelScale, wvp);
Matrix::Translation(light.Position, matrix);
Matrix::Multiply(wvp, matrix, world);
Matrix world, wvp;
bool isInside;
RenderTools::ComputeSphereModelDrawMatrix(renderContext.View, light.Position, ((RenderLocalLightData&)light).Radius, world, isInside);
Matrix::Multiply(world, view.ViewProjection(), wvp);
Matrix::Transpose(wvp, sperLight.WVP);
}
// TODO: reimplement cascades blending for directional lights (but with dithering)
// Render shadow in screen space
GPUConstantBuffer* cb0 = shader->GetCB(0);
@@ -942,12 +939,12 @@ void ShadowsPass::RenderShadowMask(RenderContextBatch& renderContextBatch, Rende
if (light.IsPointLight)
{
context->SetState(_psShadowPoint.Get(permutationIndex));
_sphereModel->Render(context);
_sphereModel->LODs.Get()[0].Meshes.Get()[0].Render(context);
}
else if (light.IsSpotLight)
{
context->SetState(_psShadowSpot.Get(permutationIndex));
_sphereModel->Render(context);
_sphereModel->LODs.Get()[0].Meshes.Get()[0].Render(context);
}
else //if (light.IsDirectionalLight)
{