From 7a4a21c8bf4ca4051220fea43c86d5b5a5eece2d Mon Sep 17 00:00:00 2001 From: Kelsi Date: Sat, 21 Feb 2026 03:23:24 -0800 Subject: [PATCH] Align lens flare with sky-locked sun rendering - anchor flare sun position to camera + sun direction to match celestial billboard projection - remove world-space parallax drift that caused flare/sun misalignment while moving --- src/rendering/lens_flare.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/rendering/lens_flare.cpp b/src/rendering/lens_flare.cpp index 7c44f307..8bae2551 100644 --- a/src/rendering/lens_flare.cpp +++ b/src/rendering/lens_flare.cpp @@ -215,14 +215,23 @@ void LensFlare::render(const Camera& camera, const glm::vec3& sunPosition, float return; } + // Sun billboard rendering is sky-locked (view translation removed), so anchor + // flare projection to camera position along sun direction to avoid parallax drift. + glm::vec3 sunDir = sunPosition; + if (glm::length(sunDir) < 0.0001f) { + return; + } + sunDir = glm::normalize(sunDir); + glm::vec3 anchoredSunPos = camera.getPosition() + sunDir * 800.0f; + // Calculate sun visibility - float visibility = calculateSunVisibility(camera, sunPosition); + float visibility = calculateSunVisibility(camera, anchoredSunPos); if (visibility < 0.01f) { return; } // Get sun screen position - glm::vec2 sunScreen = worldToScreen(camera, sunPosition); + glm::vec2 sunScreen = worldToScreen(camera, anchoredSunPos); glm::vec2 screenCenter(0.0f, 0.0f); // Vector from sun to screen center