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

@ -13,8 +13,9 @@ class VkContext;
/**
* Skybox renderer
*
* Renders an atmospheric sky dome with gradient colors.
* The sky uses a dome/sphere approach for realistic appearance.
* Renders an atmospheric sky gradient using a fullscreen triangle.
* No vertex buffer: 3 vertices cover the entire screen via gl_VertexIndex.
* World-space ray direction is reconstructed from the inverse view+projection.
*/
class Skybox {
public:
@ -62,9 +63,6 @@ public:
glm::vec3 getHorizonColor(float time) const;
private:
void createSkyDome();
void destroySkyDome();
glm::vec3 getSkyColor(float altitude, float time) const;
glm::vec3 getZenithColor(float time) const;
@ -73,13 +71,6 @@ private:
VkPipeline pipeline = VK_NULL_HANDLE;
VkPipelineLayout pipelineLayout = VK_NULL_HANDLE;
VkBuffer vertexBuffer = VK_NULL_HANDLE;
VmaAllocation vertexAlloc = VK_NULL_HANDLE;
VkBuffer indexBuffer = VK_NULL_HANDLE;
VmaAllocation indexAlloc = VK_NULL_HANDLE;
int indexCount = 0;
float timeOfDay = 12.0f; // Default: noon
float timeSpeed = 1.0f; // 1.0 = 1 hour per real second
bool timeProgressionEnabled = false;