diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-29 10:11:19 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-29 10:11:19 +1000 |
commit | 624c7aaaf192f2e87081a241123a8507a4718ba3 (patch) | |
tree | a54b09902da8d724f3ba740a215fd53d8a861fd9 /source/client | |
parent | 9d67cda97fc327ca3c53e044a897fbfb196104c4 (diff) |
Move lighting calculation to separate thread
Diffstat (limited to 'source/client')
-rw-r--r-- | source/client/StarClientApplication.cpp | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/source/client/StarClientApplication.cpp b/source/client/StarClientApplication.cpp index a76a527..be32e58 100644 --- a/source/client/StarClientApplication.cpp +++ b/source/client/StarClientApplication.cpp @@ -361,18 +361,41 @@ void ClientApplication::render() { m_cinematicOverlay->render(); } else if (m_state > MainAppState::Title) { - if (auto worldClient = m_universeClient->worldClient()) { - if (auto renderer = Application::renderer()) + WorldClientPtr worldClient = m_universeClient->worldClient(); + RendererPtr renderer = Application::renderer(); + if (worldClient) { + if (renderer) renderer->setEffectParameter("lightMapEnabled", true); worldClient->render(m_renderData, TilePainter::BorderTileSize); - m_worldPainter->render(m_renderData); + // Might have to move lightmap adjustment code back into worldPainter->render + // eventually, can't be bothered to remove the passed lambda yet + m_worldPainter->render(m_renderData, [&]() { worldClient->waitForLighting(); }); m_mainInterface->renderInWorldElements(); - if (auto renderer = Application::renderer()) + if (renderer) renderer->setEffectParameter("lightMapEnabled", false); } m_mainInterface->render(); m_cinematicOverlay->render(); + if (worldClient && renderer) { + worldClient->waitForLighting(); + + if (m_renderData.isFullbright) { + renderer->setEffectTexture("lightMap", Image::filled(Vec2U(1, 1), { 255, 255, 255, 255 }, PixelFormat::RGB24)); + renderer->setEffectTexture("tileLightMap", Image::filled(Vec2U(1, 1), { 0, 0, 0, 0 }, PixelFormat::RGBA32)); + renderer->setEffectParameter("lightMapMultiplier", 1.0f); + } + else { + m_worldPainter->adjustLighting(m_renderData); + + WorldCamera const& camera = m_worldPainter->camera(); + renderer->setEffectParameter("lightMapMultiplier", assets->json("/rendering.config:lightMapMultiplier").toFloat()); + renderer->setEffectParameter("lightMapScale", Vec2F::filled(TilePixels * camera.pixelRatio())); + renderer->setEffectParameter("lightMapOffset", camera.worldToScreen(Vec2F(m_renderData.lightMinPosition))); + renderer->setEffectTexture("lightMap", m_renderData.lightMap); + renderer->setEffectTexture("tileLightMap", m_renderData.tileLightMap); + } + } } if (!m_errorScreen->accepted()) |