mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-03-24 16:10:14 +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,25 +1,27 @@
|
|||
#pragma once
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include <glm/glm.hpp>
|
||||
#include <memory>
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <vk_mem_alloc.h>
|
||||
#include <vector>
|
||||
|
||||
namespace wowee {
|
||||
namespace rendering {
|
||||
|
||||
class Camera;
|
||||
class Shader;
|
||||
class VkContext;
|
||||
|
||||
/**
|
||||
* @brief Renders procedural animated clouds on a sky dome
|
||||
* Procedural cloud renderer (Vulkan)
|
||||
*
|
||||
* Features:
|
||||
* - Procedural cloud generation using multiple noise layers
|
||||
* - Two cloud layers at different altitudes
|
||||
* - Animated wind movement
|
||||
* - Time-of-day color tinting (orange at sunrise/sunset)
|
||||
* - Transparency and soft edges
|
||||
* Renders animated procedural clouds on a sky hemisphere using FBM noise.
|
||||
* Two noise layers at different frequencies produce realistic cloud shapes.
|
||||
*
|
||||
* Pipeline layout:
|
||||
* set 0 = perFrameLayout (camera UBO — view, projection, etc.)
|
||||
* push = CloudPush (vec4 cloudColor + float density + float windOffset = 24 bytes)
|
||||
*
|
||||
* The vertex shader reads view/projection from set 0 directly; no per-object
|
||||
* model matrix is needed (clouds are locked to the sky dome).
|
||||
*/
|
||||
class Clouds {
|
||||
public:
|
||||
|
|
@ -27,68 +29,79 @@ public:
|
|||
~Clouds();
|
||||
|
||||
/**
|
||||
* @brief Initialize cloud system (generate mesh and shaders)
|
||||
* @return true if initialization succeeded
|
||||
* Initialize the cloud system.
|
||||
* @param ctx Vulkan context
|
||||
* @param perFrameLayout Descriptor set layout for set 0 (camera UBO)
|
||||
*/
|
||||
bool initialize();
|
||||
bool initialize(VkContext* ctx, VkDescriptorSetLayout perFrameLayout);
|
||||
void shutdown();
|
||||
|
||||
/**
|
||||
* @brief Render clouds
|
||||
* @param camera The camera to render from
|
||||
* @param timeOfDay Current time (0-24 hours)
|
||||
* Render clouds.
|
||||
* @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)
|
||||
*/
|
||||
void render(const Camera& camera, float timeOfDay);
|
||||
void render(VkCommandBuffer cmd, VkDescriptorSet perFrameSet, float timeOfDay);
|
||||
|
||||
/**
|
||||
* @brief Update cloud animation
|
||||
* @param deltaTime Time since last frame
|
||||
* Update cloud animation (wind drift).
|
||||
* @param deltaTime Seconds since last frame
|
||||
*/
|
||||
void update(float deltaTime);
|
||||
|
||||
/**
|
||||
* @brief Enable or disable cloud rendering
|
||||
*/
|
||||
void setEnabled(bool enabled) { this->enabled = enabled; }
|
||||
bool isEnabled() const { return enabled; }
|
||||
// --- Enable / disable ---
|
||||
void setEnabled(bool enabled) { enabled_ = enabled; }
|
||||
bool isEnabled() const { return enabled_; }
|
||||
|
||||
/**
|
||||
* @brief Set cloud density (0.0 = clear, 1.0 = overcast)
|
||||
*/
|
||||
// --- Cloud parameters ---
|
||||
/** Cloud coverage, 0 = clear, 1 = overcast. */
|
||||
void setDensity(float density);
|
||||
float getDensity() const { return density; }
|
||||
float getDensity() const { return density_; }
|
||||
|
||||
/**
|
||||
* @brief Set wind speed multiplier
|
||||
*/
|
||||
void setWindSpeed(float speed) { windSpeed = speed; }
|
||||
float getWindSpeed() const { return windSpeed; }
|
||||
void setWindSpeed(float speed) { windSpeed_ = speed; }
|
||||
float getWindSpeed() const { return windSpeed_; }
|
||||
|
||||
private:
|
||||
// Push constant block — must match clouds.frag.glsl
|
||||
struct CloudPush {
|
||||
glm::vec4 cloudColor; // 16 bytes (xyz = colour, w unused)
|
||||
float density; // 4 bytes
|
||||
float windOffset; // 4 bytes
|
||||
// total = 24 bytes
|
||||
};
|
||||
static_assert(sizeof(CloudPush) == 24, "CloudPush size mismatch");
|
||||
|
||||
void generateMesh();
|
||||
void cleanup();
|
||||
void createBuffers();
|
||||
void destroyBuffers();
|
||||
|
||||
glm::vec3 getCloudColor(float timeOfDay) const;
|
||||
|
||||
// OpenGL objects
|
||||
GLuint vao = 0;
|
||||
GLuint vbo = 0;
|
||||
GLuint ebo = 0;
|
||||
std::unique_ptr<Shader> shader;
|
||||
// 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;
|
||||
|
||||
// Mesh data
|
||||
std::vector<glm::vec3> vertices;
|
||||
std::vector<unsigned int> indices;
|
||||
int triangleCount = 0;
|
||||
// Mesh data (CPU side, used during initialization only)
|
||||
std::vector<glm::vec3> vertices_;
|
||||
std::vector<uint32_t> indices_;
|
||||
int indexCount_ = 0;
|
||||
|
||||
// Cloud parameters
|
||||
bool enabled = true;
|
||||
float density = 0.5f; // Cloud coverage
|
||||
float windSpeed = 1.0f;
|
||||
float windOffset = 0.0f; // Accumulated wind movement
|
||||
bool enabled_ = true;
|
||||
float density_ = 0.5f;
|
||||
float windSpeed_ = 1.0f;
|
||||
float windOffset_ = 0.0f; // Accumulated wind movement
|
||||
|
||||
// Mesh generation parameters
|
||||
static constexpr int SEGMENTS = 32; // Horizontal segments
|
||||
static constexpr int RINGS = 8; // Vertical rings (only upper hemisphere)
|
||||
static constexpr float RADIUS = 900.0f; // Slightly smaller than skybox
|
||||
static constexpr int SEGMENTS = 32;
|
||||
static constexpr int RINGS = 8;
|
||||
static constexpr float RADIUS = 900.0f; // Slightly smaller than skybox
|
||||
};
|
||||
|
||||
} // namespace rendering
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue