feat(rendering): GPU architecture + visual quality fixes
M2 GPU instancing
- M2InstanceGPU SSBO (96 B/entry, double-buffered, 16384 max)
- Group opaque instances by (modelId, LOD); single vkCmdDrawIndexed per group
- boneBase field indexes into mega bone SSBO via gl_InstanceIndex
Indirect terrain drawing
- 24 MB mega index buffer (6M uint32) + 64 MB mega vertex buffer
- CPU builds VkDrawIndexedIndirectCommand per visible chunk
- Single VB/IB bind per frame; shadow pass reuses mega buffers
- Replaced vkCmdDrawIndexedIndirect with direct vkCmdDrawIndexed to fix
host-mapped buffer race condition that caused terrain flickering
GPU frustum culling (compute shader)
- m2_cull.comp.glsl: 64-thread workgroups, sphere-vs-6-planes + distance cull
- CullInstanceGPU SSBO input, uint visibility[] output, double-buffered
- dispatchCullCompute() runs before main pass via render graph node
Consolidated bone matrix SSBOs
- 16 MB double-buffered mega bone SSBO (2048 instances × 128 bones)
- Eliminated per-instance descriptor sets; one megaBoneSet_ per frame
- prepareRender() packs bone matrices consecutively into current frame slot
Render graph / frame graph
- RenderGraph: RGResource handles, RGPass nodes, Kahn topological sort
- Automatic VkImageMemoryBarrier/VkBufferMemoryBarrier between passes
- Passes: minimap_composite, worldmap_composite, preview_composite,
shadow_pass, reflection_pass, compute_cull
- beginFrame() uses buildFrameGraph() + renderGraph_->execute(cmd)
Pipeline derivatives
- PipelineBuilder::setFlags/setBasePipeline for VK_PIPELINE_CREATE_DERIVATIVE_BIT
- M2 opaque = base; alphaTest/alpha/additive are derivatives
- Applied to terrain (wireframe) and WMO (alpha-test) renderers
Rendering bug fixes:
- fix(shadow): compute lightSpaceMatrix before updatePerFrameUBO to eliminate
one-frame lag that caused shadow trails and flicker on moving objects
- fix(shadow): scale depth bias with shadowDistance_ instead of hardcoded 0.8f
to prevent acne at close range and gaps at far range
- fix(visibility): WMO group distance threshold 500u → 1200u to match terrain
view distance; buildings were disappearing on the horizon
- fix(precision): camera near plane 0.05 → 0.5 (ratio 600K:1 → 60K:1),
eliminating Z-fighting and improving frustum plane extraction stability
- fix(streaming): terrain load radius 4 → 6 tiles (~2133u → ~3200u) to exceed
M2 render distance (2800u) and eliminate pop-in when camera turns;
unload radius 7 → 9; spawn radius 3 → 4
- fix(visibility): ground-detail M2 distance multiplier 0.75 → 0.9 to reduce
early pop of grass and debris
2026-04-04 13:43:16 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <vulkan/vulkan.h>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <functional>
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
|
|
|
|
|
namespace wowee {
|
|
|
|
|
namespace rendering {
|
|
|
|
|
|
feat(animation): 452 named constants, 30-phase character animation state machine
Add animation_ids.hpp/cpp with all 452 WoW animation ID constants (anim::STAND,
anim::RUN, anim::FIRE_BOW, ... anim::FLY_BACKWARDS, etc.), nameFromId() O(1)
lookup, and flyVariant() compact 218-element ground→FLY_* resolver.
Expand AnimationController into a full state machine with 20+ named states:
spell cast (directed→omni→cast fallback chain, instant one-shot release),
hit reactions (WOUND/CRIT/DODGE/BLOCK/SHIELD_BLOCK), stun, wounded idle,
stealth animation substitution, loot, fishing channel, sit/sleep/kneel
down→loop→up transitions, sheathe/unsheathe combat enter/exit, ranged weapons
(BOW/GUN/CROSSBOW/THROWN with reload states), game object OPEN/CLOSE/DESTROY,
vehicle enter/exit, mount flight directionals (FLY_LEFT/RIGHT/UP/DOWN/BACKWARDS),
emote state variants, off-hand/pierce/dual-wield alternation, NPC
birth/spawn/drown/rise, sprint aura override, totem idle, NPC greeting/farewell.
Add spell_defines.hpp with SpellEffect (~45 constants) and SpellMissInfo
(12 constants) namespaces; replace all magic numbers in spell_handler.cpp.
Add GAMEOBJECT_BYTES_1 to update field table (all 4 expansion JSONs) and wire
GameObjectStateCallback. Add DBC cross-validation on world entry.
Expand tools/_ANIM_NAMES from ~35 to 452 entries in m2_viewer.py and
asset_pipeline_gui.py. Add tests/test_animation_ids.cpp.
Bug fixes included:
- Stand state 1 was animating READY_2H(27) — fixed to SITTING(97)
- Spell casts ended freeze-frame — add one-shot release animation
- NPC 2H swing probe chain missing ATTACK_2H_LOOSE (polearm/staff)
- Chair sits (states 2/4/5/6) incorrectly played floor-sit transition
- STOP(3) used for all spell casts — replaced with model-aware chain
2026-04-04 23:02:53 +03:00
|
|
|
// Lightweight Render Graph / Frame Graph
|
feat(rendering): GPU architecture + visual quality fixes
M2 GPU instancing
- M2InstanceGPU SSBO (96 B/entry, double-buffered, 16384 max)
- Group opaque instances by (modelId, LOD); single vkCmdDrawIndexed per group
- boneBase field indexes into mega bone SSBO via gl_InstanceIndex
Indirect terrain drawing
- 24 MB mega index buffer (6M uint32) + 64 MB mega vertex buffer
- CPU builds VkDrawIndexedIndirectCommand per visible chunk
- Single VB/IB bind per frame; shadow pass reuses mega buffers
- Replaced vkCmdDrawIndexedIndirect with direct vkCmdDrawIndexed to fix
host-mapped buffer race condition that caused terrain flickering
GPU frustum culling (compute shader)
- m2_cull.comp.glsl: 64-thread workgroups, sphere-vs-6-planes + distance cull
- CullInstanceGPU SSBO input, uint visibility[] output, double-buffered
- dispatchCullCompute() runs before main pass via render graph node
Consolidated bone matrix SSBOs
- 16 MB double-buffered mega bone SSBO (2048 instances × 128 bones)
- Eliminated per-instance descriptor sets; one megaBoneSet_ per frame
- prepareRender() packs bone matrices consecutively into current frame slot
Render graph / frame graph
- RenderGraph: RGResource handles, RGPass nodes, Kahn topological sort
- Automatic VkImageMemoryBarrier/VkBufferMemoryBarrier between passes
- Passes: minimap_composite, worldmap_composite, preview_composite,
shadow_pass, reflection_pass, compute_cull
- beginFrame() uses buildFrameGraph() + renderGraph_->execute(cmd)
Pipeline derivatives
- PipelineBuilder::setFlags/setBasePipeline for VK_PIPELINE_CREATE_DERIVATIVE_BIT
- M2 opaque = base; alphaTest/alpha/additive are derivatives
- Applied to terrain (wireframe) and WMO (alpha-test) renderers
Rendering bug fixes:
- fix(shadow): compute lightSpaceMatrix before updatePerFrameUBO to eliminate
one-frame lag that caused shadow trails and flicker on moving objects
- fix(shadow): scale depth bias with shadowDistance_ instead of hardcoded 0.8f
to prevent acne at close range and gaps at far range
- fix(visibility): WMO group distance threshold 500u → 1200u to match terrain
view distance; buildings were disappearing on the horizon
- fix(precision): camera near plane 0.05 → 0.5 (ratio 600K:1 → 60K:1),
eliminating Z-fighting and improving frustum plane extraction stability
- fix(streaming): terrain load radius 4 → 6 tiles (~2133u → ~3200u) to exceed
M2 render distance (2800u) and eliminate pop-in when camera turns;
unload radius 7 → 9; spawn radius 3 → 4
- fix(visibility): ground-detail M2 distance multiplier 0.75 → 0.9 to reduce
early pop of grass and debris
2026-04-04 13:43:16 +03:00
|
|
|
// Converts hardcoded pass sequence (shadow → reflection → compute cull →
|
|
|
|
|
// main → post-process → ImGui → present) into declarative graph nodes.
|
|
|
|
|
// Graph auto-inserts VkImageMemoryBarrier between passes.
|
|
|
|
|
|
|
|
|
|
// Resource handle — identifies a virtual resource (image or buffer) within the graph.
|
|
|
|
|
struct RGResource {
|
|
|
|
|
uint32_t id = UINT32_MAX;
|
|
|
|
|
bool valid() const { return id != UINT32_MAX; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Image barrier descriptor for automatic synchronization between passes.
|
|
|
|
|
struct RGImageBarrier {
|
|
|
|
|
VkImage image;
|
|
|
|
|
VkImageLayout oldLayout;
|
|
|
|
|
VkImageLayout newLayout;
|
|
|
|
|
VkAccessFlags srcAccess;
|
|
|
|
|
VkAccessFlags dstAccess;
|
|
|
|
|
VkPipelineStageFlags srcStage;
|
|
|
|
|
VkPipelineStageFlags dstStage;
|
|
|
|
|
VkImageAspectFlags aspectMask;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Buffer barrier descriptor for automatic synchronization between passes.
|
|
|
|
|
struct RGBufferBarrier {
|
|
|
|
|
VkBuffer buffer;
|
|
|
|
|
VkDeviceSize offset;
|
|
|
|
|
VkDeviceSize size;
|
|
|
|
|
VkAccessFlags srcAccess;
|
|
|
|
|
VkAccessFlags dstAccess;
|
|
|
|
|
VkPipelineStageFlags srcStage;
|
|
|
|
|
VkPipelineStageFlags dstStage;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Render pass node — wraps an execution callback with declared inputs/outputs.
|
|
|
|
|
struct RGPass {
|
|
|
|
|
std::string name;
|
|
|
|
|
std::vector<RGResource> inputs;
|
|
|
|
|
std::vector<RGResource> outputs;
|
|
|
|
|
std::function<void(VkCommandBuffer cmd)> execute;
|
|
|
|
|
bool enabled = true; // Can be dynamically disabled per-frame
|
|
|
|
|
|
|
|
|
|
// Barriers to insert before this pass executes
|
|
|
|
|
std::vector<RGImageBarrier> imageBarriers;
|
|
|
|
|
std::vector<RGBufferBarrier> bufferBarriers;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class RenderGraph {
|
|
|
|
|
public:
|
|
|
|
|
RenderGraph() = default;
|
|
|
|
|
~RenderGraph() = default;
|
|
|
|
|
|
|
|
|
|
// Reset graph for a new frame (clears passes, keeps resource registry).
|
|
|
|
|
void reset();
|
|
|
|
|
|
|
|
|
|
// Register a virtual resource (returns handle for input/output declarations).
|
|
|
|
|
RGResource registerResource(const std::string& name);
|
|
|
|
|
|
|
|
|
|
// Look up a previously registered resource by name.
|
|
|
|
|
RGResource findResource(const std::string& name) const;
|
|
|
|
|
|
|
|
|
|
// Add a render pass node.
|
|
|
|
|
// inputs: resources this pass reads from
|
|
|
|
|
// outputs: resources this pass writes to
|
|
|
|
|
// execute: callback invoked with the frame's command buffer
|
|
|
|
|
void addPass(const std::string& name,
|
|
|
|
|
const std::vector<RGResource>& inputs,
|
|
|
|
|
const std::vector<RGResource>& outputs,
|
|
|
|
|
std::function<void(VkCommandBuffer cmd)> execute);
|
|
|
|
|
|
|
|
|
|
// Enable/disable a pass by name (for dynamic toggling, e.g. shadows off).
|
|
|
|
|
void setPassEnabled(const std::string& name, bool enabled);
|
|
|
|
|
|
|
|
|
|
// Compile: topological sort by dependency order, insert barriers.
|
|
|
|
|
// Must be called after all addPass() calls and before execute().
|
|
|
|
|
void compile();
|
|
|
|
|
|
|
|
|
|
// Execute all enabled passes in compiled order on the given command buffer.
|
|
|
|
|
void execute(VkCommandBuffer cmd);
|
|
|
|
|
|
|
|
|
|
// Query: get the compiled execution order (pass names, for debug HUD).
|
|
|
|
|
const std::vector<uint32_t>& getExecutionOrder() const { return executionOrder_; }
|
|
|
|
|
const std::vector<RGPass>& getPasses() const { return passes_; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
// Topological sort helper (Kahn's algorithm).
|
|
|
|
|
void topologicalSort();
|
|
|
|
|
|
|
|
|
|
// Resource registry: name → id
|
|
|
|
|
struct ResourceEntry {
|
|
|
|
|
std::string name;
|
|
|
|
|
uint32_t id;
|
|
|
|
|
};
|
|
|
|
|
std::vector<ResourceEntry> resources_;
|
|
|
|
|
uint32_t nextResourceId_ = 0;
|
|
|
|
|
|
|
|
|
|
// Pass storage
|
|
|
|
|
std::vector<RGPass> passes_;
|
|
|
|
|
|
|
|
|
|
// Compiled execution order (indices into passes_)
|
|
|
|
|
std::vector<uint32_t> executionOrder_;
|
|
|
|
|
bool compiled_ = false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace rendering
|
|
|
|
|
} // namespace wowee
|