Align sun placement and shadow direction to active lighting

- drive shadow light direction from live LightingManager directionalDir
- normalize shadow light to downward-facing convention with grazing-angle guard
- make celestial/sky sun placement robust to directionalDir convention mismatches
- keep visible sun above horizon while preserving shadow alignment
This commit is contained in:
Kelsi 2026-02-21 03:21:08 -08:00
parent 566e7138f3
commit 8156942b66
3 changed files with 43 additions and 4 deletions

View file

@ -211,7 +211,13 @@ void Celestial::renderSun(const Camera& camera, float timeOfDay,
celestialShader->use();
glm::vec3 dir = sunDir ? glm::normalize(*sunDir) : glm::vec3(0.0f, 0.0f, 1.0f);
// Prefer opposite of light-ray direction (sun->world), but guard against
// profile/convention mismatches that can place the sun below the horizon.
glm::vec3 lightDir = sunDir ? glm::normalize(*sunDir) : glm::vec3(0.0f, 0.0f, -1.0f);
glm::vec3 dir = -lightDir;
if (dir.z < 0.0f) {
dir = lightDir;
}
// Place sun on sky sphere at fixed distance
const float sunDistance = 800.0f;