mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-04-17 01:23:51 +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
|
|
@ -4,6 +4,8 @@
|
|||
#include <memory>
|
||||
#include <optional>
|
||||
#include <cstdint>
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <vk_mem_alloc.h>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
namespace wowee {
|
||||
|
|
@ -16,127 +18,77 @@ namespace pipeline {
|
|||
namespace rendering {
|
||||
|
||||
class Camera;
|
||||
class Shader;
|
||||
class VkContext;
|
||||
|
||||
/**
|
||||
* Water surface for a single map chunk
|
||||
*/
|
||||
struct WaterSurface {
|
||||
glm::vec3 position; // World position
|
||||
glm::vec3 origin; // Mesh origin (world)
|
||||
glm::vec3 stepX; // Mesh X step vector in world space
|
||||
glm::vec3 stepY; // Mesh Y step vector in world space
|
||||
float minHeight; // Minimum water height
|
||||
float maxHeight; // Maximum water height
|
||||
uint16_t liquidType; // LiquidType.dbc ID (WotLK)
|
||||
glm::vec3 position;
|
||||
glm::vec3 origin;
|
||||
glm::vec3 stepX;
|
||||
glm::vec3 stepY;
|
||||
float minHeight;
|
||||
float maxHeight;
|
||||
uint16_t liquidType;
|
||||
|
||||
// Owning tile coordinates (for per-tile removal)
|
||||
int tileX = -1, tileY = -1;
|
||||
|
||||
// Owning WMO instance ID (for WMO liquid removal, 0 = terrain water)
|
||||
uint32_t wmoId = 0;
|
||||
|
||||
// Water layer dimensions within chunk (0-7 offset, 1-8 size)
|
||||
uint8_t xOffset = 0;
|
||||
uint8_t yOffset = 0;
|
||||
uint8_t width = 8; // Width in tiles (1-8)
|
||||
uint8_t height = 8; // Height in tiles (1-8)
|
||||
uint8_t width = 8;
|
||||
uint8_t height = 8;
|
||||
|
||||
// Height map for water surface ((width+1) x (height+1) vertices)
|
||||
std::vector<float> heights;
|
||||
|
||||
// Render mask (which tiles have water)
|
||||
std::vector<uint8_t> mask;
|
||||
|
||||
// Render data
|
||||
uint32_t vao = 0;
|
||||
uint32_t vbo = 0;
|
||||
uint32_t ebo = 0;
|
||||
// Vulkan render data
|
||||
::VkBuffer vertexBuffer = VK_NULL_HANDLE;
|
||||
VmaAllocation vertexAlloc = VK_NULL_HANDLE;
|
||||
::VkBuffer indexBuffer = VK_NULL_HANDLE;
|
||||
VmaAllocation indexAlloc = VK_NULL_HANDLE;
|
||||
int indexCount = 0;
|
||||
|
||||
// Per-surface material UBO
|
||||
::VkBuffer materialUBO = VK_NULL_HANDLE;
|
||||
VmaAllocation materialAlloc = VK_NULL_HANDLE;
|
||||
|
||||
// Material descriptor set (set 1)
|
||||
VkDescriptorSet materialSet = VK_NULL_HANDLE;
|
||||
|
||||
bool hasHeightData() const { return !heights.empty(); }
|
||||
};
|
||||
|
||||
/**
|
||||
* Water renderer
|
||||
*
|
||||
* Renders water surfaces with transparency and animation.
|
||||
* Supports multiple liquid types (water, ocean, magma, slime).
|
||||
* Water renderer (Vulkan)
|
||||
*/
|
||||
class WaterRenderer {
|
||||
public:
|
||||
WaterRenderer();
|
||||
~WaterRenderer();
|
||||
|
||||
bool initialize();
|
||||
bool initialize(VkContext* ctx, VkDescriptorSetLayout perFrameLayout);
|
||||
void shutdown();
|
||||
|
||||
/**
|
||||
* Load water surfaces from ADT terrain
|
||||
* @param terrain The ADT terrain data
|
||||
* @param append If true, add to existing water instead of replacing
|
||||
* @param tileX Tile X coordinate for tracking ownership (-1 = untracked)
|
||||
* @param tileY Tile Y coordinate for tracking ownership (-1 = untracked)
|
||||
*/
|
||||
void loadFromTerrain(const pipeline::ADTTerrain& terrain, bool append = false,
|
||||
int tileX = -1, int tileY = -1);
|
||||
|
||||
/**
|
||||
* Load water surface from WMO liquid data
|
||||
* @param liquid WMO liquid data from MLIQ chunk
|
||||
* @param modelMatrix WMO instance model matrix for transforming to world space
|
||||
* @param wmoId WMO instance ID for tracking ownership
|
||||
*/
|
||||
void loadFromWMO(const pipeline::WMOLiquid& liquid, const glm::mat4& modelMatrix, uint32_t wmoId);
|
||||
|
||||
/**
|
||||
* Remove all water surfaces belonging to a specific WMO instance
|
||||
* @param wmoId WMO instance ID
|
||||
*/
|
||||
void removeWMO(uint32_t wmoId);
|
||||
|
||||
/**
|
||||
* Remove all water surfaces belonging to a specific tile
|
||||
* @param tileX Tile X coordinate
|
||||
* @param tileY Tile Y coordinate
|
||||
*/
|
||||
void removeTile(int tileX, int tileY);
|
||||
|
||||
/**
|
||||
* Clear all water surfaces
|
||||
*/
|
||||
void clear();
|
||||
|
||||
/**
|
||||
* Render all water surfaces
|
||||
*/
|
||||
void render(const Camera& camera, float time);
|
||||
void render(VkCommandBuffer cmd, VkDescriptorSet perFrameSet, const Camera& camera, float time);
|
||||
|
||||
/**
|
||||
* Enable/disable water rendering
|
||||
*/
|
||||
void setEnabled(bool enabled) { renderingEnabled = enabled; }
|
||||
bool isEnabled() const { return renderingEnabled; }
|
||||
|
||||
/**
|
||||
* Query the water height at a given world position.
|
||||
* Returns the highest water surface height at that XY, or nullopt if no water.
|
||||
*/
|
||||
std::optional<float> getWaterHeightAt(float glX, float glY) const;
|
||||
std::optional<uint16_t> getWaterTypeAt(float glX, float glY) const;
|
||||
|
||||
/**
|
||||
* Get water surface count
|
||||
*/
|
||||
int getSurfaceCount() const { return static_cast<int>(surfaces.size()); }
|
||||
|
||||
/**
|
||||
* Set fog parameters
|
||||
*/
|
||||
void setFog(const glm::vec3& color, float start, float end) {
|
||||
fogColor = color; fogStart = start; fogEnd = end;
|
||||
}
|
||||
|
||||
private:
|
||||
void createWaterMesh(WaterSurface& surface);
|
||||
void destroyWaterMesh(WaterSurface& surface);
|
||||
|
|
@ -144,14 +96,20 @@ private:
|
|||
glm::vec4 getLiquidColor(uint16_t liquidType) const;
|
||||
float getLiquidAlpha(uint16_t liquidType) const;
|
||||
|
||||
std::unique_ptr<Shader> waterShader;
|
||||
void updateMaterialUBO(WaterSurface& surface);
|
||||
VkDescriptorSet allocateMaterialSet();
|
||||
|
||||
VkContext* vkCtx = nullptr;
|
||||
|
||||
// Pipeline
|
||||
VkPipeline waterPipeline = VK_NULL_HANDLE;
|
||||
VkPipelineLayout pipelineLayout = VK_NULL_HANDLE;
|
||||
VkDescriptorSetLayout materialSetLayout = VK_NULL_HANDLE;
|
||||
VkDescriptorPool materialDescPool = VK_NULL_HANDLE;
|
||||
static constexpr uint32_t MAX_WATER_SETS = 2048;
|
||||
|
||||
std::vector<WaterSurface> surfaces;
|
||||
bool renderingEnabled = true;
|
||||
|
||||
// Fog parameters
|
||||
glm::vec3 fogColor = glm::vec3(0.5f, 0.6f, 0.7f);
|
||||
float fogStart = 800.0f; // Match WMO renderer fog settings
|
||||
float fogEnd = 1500.0f;
|
||||
};
|
||||
|
||||
} // namespace rendering
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue