mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-03-25 00:20:16 +00:00
Vulcan Nightmare
Experimentally bringing up vulcan support
This commit is contained in:
parent
863a786c48
commit
83b576e8d9
189 changed files with 12147 additions and 7820 deletions
|
|
@ -1,142 +1,132 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <glm/glm.hpp>
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <vk_mem_alloc.h>
|
||||
|
||||
namespace wowee {
|
||||
namespace rendering {
|
||||
|
||||
class Shader;
|
||||
class Camera;
|
||||
class VkContext;
|
||||
|
||||
/**
|
||||
* Celestial body renderer
|
||||
* Celestial body renderer (Vulkan)
|
||||
*
|
||||
* Renders sun and moon that move across the sky based on time of day.
|
||||
* Sun rises at dawn, sets at dusk. Moon is visible at night.
|
||||
*
|
||||
* Pipeline layout:
|
||||
* set 0 = perFrameLayout (camera UBO — view, projection, etc.)
|
||||
* push = CelestialPush (mat4 model + vec4 celestialColor + float intensity
|
||||
* + float moonPhase + float animTime = 96 bytes)
|
||||
*/
|
||||
class Celestial {
|
||||
public:
|
||||
Celestial();
|
||||
~Celestial();
|
||||
|
||||
bool initialize();
|
||||
/**
|
||||
* Initialize the renderer.
|
||||
* @param ctx Vulkan context
|
||||
* @param perFrameLayout Descriptor set layout for set 0 (camera UBO)
|
||||
*/
|
||||
bool initialize(VkContext* ctx, VkDescriptorSetLayout perFrameLayout);
|
||||
void shutdown();
|
||||
|
||||
/**
|
||||
* Render celestial bodies (sun and moon)
|
||||
* @param camera Camera for view matrix
|
||||
* @param timeOfDay Time of day in hours (0-24)
|
||||
* @param sunDir Optional sun direction from lighting system (normalized)
|
||||
* @param sunColor Optional sun color from lighting system
|
||||
* @param gameTime Optional server game time in seconds (for deterministic moon phases)
|
||||
* Render celestial bodies (sun and moons).
|
||||
* @param cmd Command buffer to record into
|
||||
* @param perFrameSet Per-frame descriptor set (set 0, camera UBO)
|
||||
* @param timeOfDay Time of day in hours (0-24)
|
||||
* @param sunDir Optional sun direction from lighting system (normalized)
|
||||
* @param sunColor Optional sun colour from lighting system
|
||||
* @param gameTime Optional server game time in seconds (deterministic moon phases)
|
||||
*/
|
||||
void render(const Camera& camera, float timeOfDay,
|
||||
const glm::vec3* sunDir = nullptr,
|
||||
void render(VkCommandBuffer cmd, VkDescriptorSet perFrameSet,
|
||||
float timeOfDay,
|
||||
const glm::vec3* sunDir = nullptr,
|
||||
const glm::vec3* sunColor = nullptr,
|
||||
float gameTime = -1.0f);
|
||||
|
||||
/**
|
||||
* Enable/disable celestial rendering
|
||||
*/
|
||||
void setEnabled(bool enabled) { renderingEnabled = enabled; }
|
||||
bool isEnabled() const { return renderingEnabled; }
|
||||
|
||||
/**
|
||||
* Update celestial bodies (for moon phase cycling)
|
||||
* Update celestial bodies (moon phase cycling, haze timer).
|
||||
*/
|
||||
void update(float deltaTime);
|
||||
|
||||
/**
|
||||
* Set White Lady phase (primary moon, 0.0 = new, 0.5 = full, 1.0 = new)
|
||||
*/
|
||||
// --- Enable / disable ---
|
||||
void setEnabled(bool enabled) { renderingEnabled_ = enabled; }
|
||||
bool isEnabled() const { return renderingEnabled_; }
|
||||
|
||||
// --- Moon phases ---
|
||||
/** Set White Lady phase (primary moon, 0 = new, 0.5 = full, 1 = new). */
|
||||
void setMoonPhase(float phase);
|
||||
float getMoonPhase() const { return whiteLadyPhase_; }
|
||||
|
||||
/**
|
||||
* Set Blue Child phase (secondary moon, 0.0 = new, 0.5 = full, 1.0 = new)
|
||||
*/
|
||||
/** Set Blue Child phase (secondary moon, 0 = new, 0.5 = full, 1 = new). */
|
||||
void setBlueChildPhase(float phase);
|
||||
float getBlueChildPhase() const { return blueChildPhase_; }
|
||||
|
||||
/**
|
||||
* Enable/disable automatic moon phase cycling
|
||||
*/
|
||||
void setMoonPhaseCycling(bool enabled) { moonPhaseCycling = enabled; }
|
||||
bool isMoonPhaseCycling() const { return moonPhaseCycling; }
|
||||
void setMoonPhaseCycling(bool enabled) { moonPhaseCycling_ = enabled; }
|
||||
bool isMoonPhaseCycling() const { return moonPhaseCycling_; }
|
||||
|
||||
/**
|
||||
* Enable/disable two-moon rendering (White Lady + Blue Child)
|
||||
*/
|
||||
/** Enable / disable two-moon rendering (White Lady + Blue Child). */
|
||||
void setDualMoonMode(bool enabled) { dualMoonMode_ = enabled; }
|
||||
bool isDualMoonMode() const { return dualMoonMode_; }
|
||||
|
||||
/**
|
||||
* Get sun position in world space
|
||||
*/
|
||||
// --- Positional / colour queries (unchanged from GL version) ---
|
||||
glm::vec3 getSunPosition(float timeOfDay) const;
|
||||
|
||||
/**
|
||||
* Get moon position in world space
|
||||
*/
|
||||
glm::vec3 getMoonPosition(float timeOfDay) const;
|
||||
|
||||
/**
|
||||
* Get sun color (changes with time of day)
|
||||
*/
|
||||
glm::vec3 getSunColor(float timeOfDay) const;
|
||||
|
||||
/**
|
||||
* Get sun intensity (0-1, fades at dawn/dusk)
|
||||
*/
|
||||
float getSunIntensity(float timeOfDay) const;
|
||||
float getSunIntensity(float timeOfDay) const;
|
||||
|
||||
private:
|
||||
void createCelestialQuad();
|
||||
void destroyCelestialQuad();
|
||||
// Push constant block — MUST match celestial.vert.glsl / celestial.frag.glsl
|
||||
struct CelestialPush {
|
||||
glm::mat4 model; // 64 bytes
|
||||
glm::vec4 celestialColor; // 16 bytes (xyz = colour, w unused)
|
||||
float intensity; // 4 bytes
|
||||
float moonPhase; // 4 bytes
|
||||
float animTime; // 4 bytes
|
||||
float _pad; // 4 bytes (round to 16-byte boundary = 96 bytes total)
|
||||
};
|
||||
static_assert(sizeof(CelestialPush) == 96, "CelestialPush size mismatch");
|
||||
|
||||
void renderSun(const Camera& camera, float timeOfDay,
|
||||
const glm::vec3* sunDir = nullptr,
|
||||
const glm::vec3* sunColor = nullptr);
|
||||
void renderMoon(const Camera& camera, float timeOfDay); // White Lady (primary)
|
||||
void renderBlueChild(const Camera& camera, float timeOfDay); // Blue Child (secondary)
|
||||
void createQuad();
|
||||
void destroyQuad();
|
||||
|
||||
void renderSun(VkCommandBuffer cmd, VkDescriptorSet perFrameSet,
|
||||
float timeOfDay,
|
||||
const glm::vec3* sunDir, const glm::vec3* sunColor);
|
||||
void renderMoon(VkCommandBuffer cmd, VkDescriptorSet perFrameSet, float timeOfDay);
|
||||
void renderBlueChild(VkCommandBuffer cmd, VkDescriptorSet perFrameSet, float timeOfDay);
|
||||
|
||||
float calculateCelestialAngle(float timeOfDay, float riseTime, float setTime) const;
|
||||
|
||||
/**
|
||||
* Compute moon phase from game time (deterministic)
|
||||
* @param gameTime Server game time in seconds
|
||||
* @param cycleDays Lunar cycle length in game days
|
||||
* @return Phase 0.0-1.0 (0=new, 0.5=full, 1.0=new)
|
||||
*/
|
||||
float computePhaseFromGameTime(float gameTime, float cycleDays) const;
|
||||
void updatePhasesFromGameTime(float gameTime);
|
||||
|
||||
/**
|
||||
* Update moon phases from game time (server-driven)
|
||||
*/
|
||||
void updatePhasesFromGameTime(float gameTime);
|
||||
// Vulkan objects
|
||||
VkContext* vkCtx_ = nullptr;
|
||||
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;
|
||||
|
||||
std::unique_ptr<Shader> celestialShader;
|
||||
|
||||
uint32_t vao = 0;
|
||||
uint32_t vbo = 0;
|
||||
uint32_t ebo = 0;
|
||||
|
||||
bool renderingEnabled = true;
|
||||
bool renderingEnabled_ = true;
|
||||
|
||||
// Moon phase system (two moons in Azeroth lore)
|
||||
float whiteLadyPhase_ = 0.5f; // 0.0-1.0 (0=new, 0.5=full) - primary moon
|
||||
float blueChildPhase_ = 0.25f; // 0.0-1.0 (0=new, 0.5=full) - secondary moon
|
||||
bool moonPhaseCycling = true;
|
||||
float moonPhaseTimer = 0.0f; // Fallback for deltaTime mode (development)
|
||||
float sunHazeTimer_ = 0.0f; // Always-running timer for sun haze animation
|
||||
bool dualMoonMode_ = true; // Default: render both moons (Azeroth-specific)
|
||||
float whiteLadyPhase_ = 0.5f; // 0-1, 0=new, 0.5=full
|
||||
float blueChildPhase_ = 0.25f; // 0-1
|
||||
bool moonPhaseCycling_ = true;
|
||||
float moonPhaseTimer_ = 0.0f; // Fallback deltaTime mode
|
||||
float sunHazeTimer_ = 0.0f; // Always-running haze animation timer
|
||||
bool dualMoonMode_ = true;
|
||||
|
||||
// WoW lunar cycle constants (in game days)
|
||||
// WoW day = 24 real minutes, so these are ~realistic game-world cycles
|
||||
static constexpr float WHITE_LADY_CYCLE_DAYS = 30.0f; // ~12 real hours for full cycle
|
||||
static constexpr float BLUE_CHILD_CYCLE_DAYS = 27.0f; // ~10.8 real hours (slightly faster)
|
||||
static constexpr float MOON_CYCLE_DURATION = 240.0f; // Fallback: 4 minutes (deltaTime mode)
|
||||
// WoW lunar cycle constants (game days; 1 game day = 24 real minutes)
|
||||
static constexpr float WHITE_LADY_CYCLE_DAYS = 30.0f;
|
||||
static constexpr float BLUE_CHILD_CYCLE_DAYS = 27.0f;
|
||||
static constexpr float MOON_CYCLE_DURATION = 240.0f; // Fallback: 4 minutes
|
||||
};
|
||||
|
||||
} // namespace rendering
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue