Fix sky and clouds orientation for Z-up world coordinates

Skybox: replace sphere-mesh approach with a fullscreen triangle that
reconstructs the world-space ray direction analytically via inverse
projection/view matrices. Eliminates clip.w=0 degeneracy at the horizon
and correctly maps altitude to dir.z in the Z-up coordinate system.

Clouds: hemisphere mesh was storing altitude in aPos.y (Y-up convention);
the Z-up view matrix projected this sideways, making clouds appear
vertical. Store altitude in aPos.z and update the fragment shader to
read dir.z as altitude and dir.xy as the horizontal UV plane.
This commit is contained in:
Kelsi 2026-02-21 21:57:16 -08:00
parent 69cf39ba02
commit 4fc3689dcc
9 changed files with 39 additions and 155 deletions

View file

@ -202,17 +202,17 @@ void Clouds::generateMesh() {
vertices_.clear();
indices_.clear();
// Upper hemisphere
// Upper hemisphere — Z-up world: altitude goes into Z, horizontal spread in X/Y
for (int ring = 0; ring <= RINGS; ++ring) {
float phi = (ring / static_cast<float>(RINGS)) * (static_cast<float>(M_PI) * 0.5f);
float y = RADIUS * std::cos(phi);
float altZ = RADIUS * std::cos(phi); // altitude → world Z (up)
float ringRadius = RADIUS * std::sin(phi);
for (int seg = 0; seg <= SEGMENTS; ++seg) {
float theta = (seg / static_cast<float>(SEGMENTS)) * (2.0f * static_cast<float>(M_PI));
float x = ringRadius * std::cos(theta);
float z = ringRadius * std::sin(theta);
vertices_.push_back(glm::vec3(x, y, z));
float y = ringRadius * std::sin(theta);
vertices_.push_back(glm::vec3(x, y, altZ));
}
}