mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-03-23 07:40:14 +00:00
Enhanced sky atmosphere with DBC-driven colors, sun lighting, and zone weather
- Skybox now uses DBC sky colors (skyTop/skyMiddle/skyBand1/skyBand2) instead of hardcoded C++ color curves, with 3-band gradient and Rayleigh/Mie scattering - Clouds receive sun direction for lit edges, self-shadowing, and silver lining - Fixed sun quad box artifact with proper edge fade in celestial shader - Lens flare attenuated by fog, cloud density, and weather intensity - Replaced garish green/purple lens flare ghosts with warm natural palette - Added zone-based weather system for single-player mode with per-zone rain/snow configuration, probability-based activation, and smooth intensity transitions - Server SMSG_WEATHER remains authoritative when connected to a server
This commit is contained in:
parent
085fd09b9d
commit
6563eebb60
18 changed files with 434 additions and 252 deletions
|
|
@ -9,45 +9,37 @@ namespace wowee {
|
|||
namespace rendering {
|
||||
|
||||
class VkContext;
|
||||
struct SkyParams;
|
||||
|
||||
/**
|
||||
* Procedural cloud renderer (Vulkan)
|
||||
*
|
||||
* Renders animated procedural clouds on a sky hemisphere using FBM noise.
|
||||
* Two noise layers at different frequencies produce realistic cloud shapes.
|
||||
* Sun-lit edges, self-shadowing, and DBC-driven cloud colors for realistic appearance.
|
||||
*
|
||||
* 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).
|
||||
* push = CloudPush (3 x vec4 = 48 bytes)
|
||||
*/
|
||||
class Clouds {
|
||||
public:
|
||||
Clouds();
|
||||
~Clouds();
|
||||
|
||||
/**
|
||||
* Initialize the cloud system.
|
||||
* @param ctx Vulkan context
|
||||
* @param perFrameLayout Descriptor set layout for set 0 (camera UBO)
|
||||
*/
|
||||
bool initialize(VkContext* ctx, VkDescriptorSetLayout perFrameLayout);
|
||||
void shutdown();
|
||||
void recreatePipelines();
|
||||
|
||||
/**
|
||||
* Render clouds.
|
||||
* Render clouds using DBC-driven colors and sun lighting.
|
||||
* @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 params Sky parameters with DBC colors and sun direction
|
||||
*/
|
||||
void render(VkCommandBuffer cmd, VkDescriptorSet perFrameSet, float timeOfDay);
|
||||
void render(VkCommandBuffer cmd, VkDescriptorSet perFrameSet, const SkyParams& params);
|
||||
|
||||
/**
|
||||
* Update cloud animation (wind drift).
|
||||
* @param deltaTime Seconds since last frame
|
||||
*/
|
||||
void update(float deltaTime);
|
||||
|
||||
|
|
@ -56,7 +48,6 @@ public:
|
|||
bool isEnabled() const { return enabled_; }
|
||||
|
||||
// --- Cloud parameters ---
|
||||
/** Cloud coverage, 0 = clear, 1 = overcast. */
|
||||
void setDensity(float density);
|
||||
float getDensity() const { return density_; }
|
||||
|
||||
|
|
@ -66,19 +57,16 @@ public:
|
|||
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
|
||||
glm::vec4 cloudColor; // xyz = DBC-derived base cloud color, w = unused
|
||||
glm::vec4 sunDirDensity; // xyz = sun direction, w = density
|
||||
glm::vec4 windAndLight; // x = windOffset, y = sunIntensity, z = ambient, w = unused
|
||||
};
|
||||
static_assert(sizeof(CloudPush) == 24, "CloudPush size mismatch");
|
||||
static_assert(sizeof(CloudPush) == 48, "CloudPush size mismatch");
|
||||
|
||||
void generateMesh();
|
||||
void createBuffers();
|
||||
void destroyBuffers();
|
||||
|
||||
glm::vec3 getCloudColor(float timeOfDay) const;
|
||||
|
||||
// Vulkan objects
|
||||
VkContext* vkCtx_ = nullptr;
|
||||
VkPipeline pipeline_ = VK_NULL_HANDLE;
|
||||
|
|
@ -95,14 +83,14 @@ private:
|
|||
|
||||
// Cloud parameters
|
||||
bool enabled_ = true;
|
||||
float density_ = 0.5f;
|
||||
float density_ = 0.35f;
|
||||
float windSpeed_ = 1.0f;
|
||||
float windOffset_ = 0.0f; // Accumulated wind movement
|
||||
float windOffset_ = 0.0f;
|
||||
|
||||
// Mesh generation parameters
|
||||
static constexpr int SEGMENTS = 32;
|
||||
static constexpr int RINGS = 8;
|
||||
static constexpr float RADIUS = 900.0f; // Slightly smaller than skybox
|
||||
static constexpr float RADIUS = 900.0f;
|
||||
};
|
||||
|
||||
} // namespace rendering
|
||||
|
|
|
|||
|
|
@ -47,8 +47,13 @@ public:
|
|||
* @param camera The camera to render from
|
||||
* @param sunPosition World-space sun position
|
||||
* @param timeOfDay Current time (0-24 hours)
|
||||
* @param fogDensity Fog density 0-1 (attenuates flare)
|
||||
* @param cloudDensity Cloud density 0-1 (attenuates flare)
|
||||
* @param weatherIntensity Weather intensity 0-1 (rain/snow attenuates flare)
|
||||
*/
|
||||
void render(VkCommandBuffer cmd, const Camera& camera, const glm::vec3& sunPosition, float timeOfDay);
|
||||
void render(VkCommandBuffer cmd, const Camera& camera, const glm::vec3& sunPosition,
|
||||
float timeOfDay, float fogDensity = 0.0f, float cloudDensity = 0.0f,
|
||||
float weatherIntensity = 0.0f);
|
||||
|
||||
/**
|
||||
* @brief Enable or disable lens flare rendering
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ struct LightingParams {
|
|||
glm::vec3 skyBand1Color{0.9f, 0.95f, 1.0f}; // Sky band 1
|
||||
glm::vec3 skyBand2Color{1.0f, 0.98f, 0.9f}; // Sky band 2
|
||||
|
||||
float cloudDensity = 1.0f; // Cloud density/opacity
|
||||
float cloudDensity = 0.3f; // Cloud density/opacity
|
||||
float horizonGlow = 0.3f; // Horizon glow intensity
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -31,9 +31,10 @@ struct SkyParams {
|
|||
glm::vec3 skyBand2Color{1.0f, 0.98f, 0.9f};
|
||||
|
||||
// Atmospheric effects
|
||||
float cloudDensity = 0.0f; // 0-1
|
||||
float fogDensity = 0.0f; // 0-1
|
||||
float horizonGlow = 0.3f; // 0-1
|
||||
float cloudDensity = 0.0f; // 0-1
|
||||
float fogDensity = 0.0f; // 0-1
|
||||
float horizonGlow = 0.3f; // 0-1
|
||||
float weatherIntensity = 0.0f; // 0-1 (rain/snow intensity, attenuates lens flare)
|
||||
|
||||
// Time
|
||||
float timeOfDay = 12.0f; // 0-24 hours
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ namespace wowee {
|
|||
namespace rendering {
|
||||
|
||||
class VkContext;
|
||||
struct SkyParams;
|
||||
|
||||
/**
|
||||
* Skybox renderer
|
||||
|
|
@ -16,6 +17,9 @@ class VkContext;
|
|||
* 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.
|
||||
*
|
||||
* Sky colors are driven by DBC data (Light.dbc / LightIntBand.dbc) via SkyParams,
|
||||
* with Rayleigh/Mie atmospheric scattering for realistic appearance.
|
||||
*/
|
||||
class Skybox {
|
||||
public:
|
||||
|
|
@ -27,12 +31,12 @@ public:
|
|||
void recreatePipelines();
|
||||
|
||||
/**
|
||||
* Render the skybox
|
||||
* Render the skybox using DBC-driven sky colors.
|
||||
* @param cmd Command buffer to record into
|
||||
* @param perFrameSet Per-frame descriptor set (set 0, contains camera UBO)
|
||||
* @param timeOfDay Time of day in hours (0-24), affects sky color
|
||||
* @param params Sky parameters with DBC colors and sun direction
|
||||
*/
|
||||
void render(VkCommandBuffer cmd, VkDescriptorSet perFrameSet, float timeOfDay = 12.0f);
|
||||
void render(VkCommandBuffer cmd, VkDescriptorSet perFrameSet, const SkyParams& params);
|
||||
|
||||
/**
|
||||
* Enable/disable skybox rendering
|
||||
|
|
@ -58,15 +62,7 @@ public:
|
|||
*/
|
||||
void update(float deltaTime);
|
||||
|
||||
/**
|
||||
* Get horizon color for fog (public for fog system)
|
||||
*/
|
||||
glm::vec3 getHorizonColor(float time) const;
|
||||
|
||||
private:
|
||||
glm::vec3 getSkyColor(float altitude, float time) const;
|
||||
glm::vec3 getZenithColor(float time) const;
|
||||
|
||||
VkContext* vkCtx = nullptr;
|
||||
|
||||
VkPipeline pipeline = VK_NULL_HANDLE;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include <vk_mem_alloc.h>
|
||||
#include <glm/glm.hpp>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace wowee {
|
||||
namespace rendering {
|
||||
|
|
@ -79,6 +80,35 @@ public:
|
|||
*/
|
||||
int getParticleCount() const;
|
||||
|
||||
/**
|
||||
* @brief Zone weather configuration
|
||||
* Provides default weather per zone for single-player mode.
|
||||
* When connected to a server, SMSG_WEATHER overrides these.
|
||||
*/
|
||||
struct ZoneWeather {
|
||||
Type type = Type::NONE;
|
||||
float minIntensity = 0.0f; // Min intensity (varies over time)
|
||||
float maxIntensity = 0.0f; // Max intensity
|
||||
float probability = 0.0f; // Chance of weather being active (0-1)
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Set weather for a zone (used for zone-based weather configuration)
|
||||
*/
|
||||
void setZoneWeather(uint32_t zoneId, Type type, float minIntensity, float maxIntensity, float probability);
|
||||
|
||||
/**
|
||||
* @brief Update weather based on current zone (single-player mode)
|
||||
* @param zoneId Current zone ID
|
||||
* @param deltaTime Time since last frame
|
||||
*/
|
||||
void updateZoneWeather(uint32_t zoneId, float deltaTime);
|
||||
|
||||
/**
|
||||
* @brief Initialize default zone weather table
|
||||
*/
|
||||
void initializeZoneWeatherDefaults();
|
||||
|
||||
/**
|
||||
* @brief Clean up Vulkan resources
|
||||
*/
|
||||
|
|
@ -120,6 +150,15 @@ private:
|
|||
static constexpr int MAX_PARTICLES = 2000;
|
||||
static constexpr float SPAWN_VOLUME_SIZE = 100.0f; // Size of spawn area around camera
|
||||
static constexpr float SPAWN_HEIGHT = 80.0f; // Height above camera to spawn
|
||||
|
||||
// Zone-based weather
|
||||
std::unordered_map<uint32_t, ZoneWeather> zoneWeatherTable_;
|
||||
uint32_t currentWeatherZone_ = 0;
|
||||
float zoneWeatherTimer_ = 0.0f; // Time accumulator for weather cycling
|
||||
float zoneWeatherCycleDuration_ = 0.0f; // Current cycle length
|
||||
bool zoneWeatherActive_ = false; // Is zone weather currently active?
|
||||
float targetIntensity_ = 0.0f; // Target intensity for smooth transitions
|
||||
bool zoneWeatherInitialized_ = false;
|
||||
};
|
||||
|
||||
} // namespace rendering
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue